diff --git a/pom.xml b/pom.xml index 60be53522..38e0cd40b 100644 --- a/pom.xml +++ b/pom.xml @@ -135,7 +135,10 @@ spring-boot-devtools true + + + diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 3ade1b2f7..fd5e0a966 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -20,9 +20,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; * and open the template in the editor. */ -/** - * @author japarejo - */ + @Configuration @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @@ -36,18 +34,24 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() + .antMatchers("/users/new").permitAll() + .antMatchers("/login/**").anonymous() + .antMatchers("/logout").permitAll() + .antMatchers("/usuarios/new").permitAll() + .antMatchers("/admin/**").hasAnyAuthority("admin") + .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") .antMatchers("/clients/new").permitAll() .antMatchers("/offers/**").hasAnyAuthority("admin") - .antMatchers("/vets/**").authenticated().anyRequest().denyAll() .and().formLogin() - /* .loginPage("/login") */ - .failureUrl("/login-error").and().logout().logoutSuccessUrl("/"); + .loginPage("/login").permitAll() + .failureUrl("/login?error") + .and().logout().logoutSuccessUrl("/login"); // Configuración para que funcione la consola de administración // de la BD H2 (deshabilitar las cabeceras de protección contra // ataques de tipo csrf y habilitar los framesets si su contenido // se sirve desde esta misma página. - http.csrf().ignoringAntMatchers("/h2-console/**"); + //http.csrf().ignoringAntMatchers("/h2-console/**"); http.headers().frameOptions().sameOrigin(); } diff --git a/src/main/java/org/springframework/cheapy/system/LoginController.java b/src/main/java/org/springframework/cheapy/system/LoginController.java new file mode 100644 index 000000000..e26025570 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/system/LoginController.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cheapy.system; + +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +class LoginController { + + @GetMapping("/login") + public String login() { + Authentication authentication= SecurityContextHolder.getContext().getAuthentication(); + if(authentication==null || authentication instanceof AnonymousAuthenticationToken) { + return "login"; + } + return "redirect:/"; + } + + + +} diff --git a/src/main/java/org/springframework/cheapy/system/WelcomeController.java b/src/main/java/org/springframework/cheapy/system/WelcomeController.java index 85782e967..1f3b04637 100644 --- a/src/main/java/org/springframework/cheapy/system/WelcomeController.java +++ b/src/main/java/org/springframework/cheapy/system/WelcomeController.java @@ -27,4 +27,6 @@ class WelcomeController { return "welcome"; } + + } diff --git a/src/main/webapp/WEB-INF/jsp/login.jsp b/src/main/webapp/WEB-INF/jsp/login.jsp new file mode 100644 index 000000000..796cdceeb --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/login.jsp @@ -0,0 +1,302 @@ +<%@ page session="false" trimDirectiveWhitespaces="true" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> +<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> + + + + + + + + + + +
+
+ + + +
+ +
+
+

Invalid username or password

+
+ +
+
+ +
diff --git a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp index c88a4c589..970f56781 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/createOrUpdateOwnerForm.jsp @@ -2,10 +2,9 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

New Owner diff --git a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp index fd57e3541..c68c500ab 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/findOwners.jsp @@ -2,12 +2,11 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%> - +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Find Owners

diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp index 98011c4d2..26c556611 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownerDetails.jsp @@ -1,9 +1,8 @@ <%@ page session="false" trimDirectiveWhitespaces="true" %> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Owner Information

diff --git a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp index f4ef33da5..78817241e 100644 --- a/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp @@ -2,9 +2,8 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

Owners

diff --git a/src/main/webapp/WEB-INF/jsp/users/createOwnerForm.jsp b/src/main/webapp/WEB-INF/jsp/users/createOwnerForm.jsp index f811bda81..e01e1c527 100644 --- a/src/main/webapp/WEB-INF/jsp/users/createOwnerForm.jsp +++ b/src/main/webapp/WEB-INF/jsp/users/createOwnerForm.jsp @@ -2,10 +2,9 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> - +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

New Owner diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag index 6963454f7..d402d3729 100644 --- a/src/main/webapp/WEB-INF/tags/menu.tag +++ b/src/main/webapp/WEB-INF/tags/menu.tag @@ -41,11 +41,6 @@ - - - Login - @@ -74,10 +69,10 @@

-

- " - class="btn btn-primary btn-block btn-sm">Logout -

+
+ + +
diff --git a/src/main/webapp/WEB-INF/tags/menuItem.tag b/src/main/webapp/WEB-INF/tags/menuItem.tag index 8c14dbbc5..8b60498f5 100644 --- a/src/main/webapp/WEB-INF/tags/menuItem.tag +++ b/src/main/webapp/WEB-INF/tags/menuItem.tag @@ -1,9 +1,8 @@ <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> -<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> - <%@ attribute name="active" required="true" rtexprvalue="true" %> <%@ attribute name="url" required="true" rtexprvalue="true" %> <%@ attribute name="title" required="false" rtexprvalue="true" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
  • "