diff --git a/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index ba0c1c8c0d..ee63df1130 100644 --- a/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -12,6 +12,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.DefaultRedirectStrategy; import org.springframework.security.web.RedirectStrategy; import org.springframework.security.web.WebAttributes; @@ -46,11 +47,9 @@ public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSu * Builds the target URL according to the logic defined in the main class Javadoc. */ protected String determineTargetUrl(final HttpServletRequest requestRaw, final HttpServletResponse response) { - // Check for the parameter and use that if available - boolean isUser = false; boolean isAdmin = false; - final Authentication authentication = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication(); + final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); final Collection authorities = authentication.getAuthorities(); for (final GrantedAuthority grantedAuthority : authorities) { if (grantedAuthority.getAuthority().equals("ROLE_USER")) { diff --git a/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml b/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml index edf0776151..de7bd9b981 100644 --- a/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml +++ b/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml @@ -1,42 +1,31 @@ - - - + + - - - - - + - + - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp b/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp index 93f9dc2fbd..8f73dbfd03 100644 --- a/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp +++ b/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/console.jsp @@ -4,7 +4,7 @@ -

This is the body of the sample view

+

This is the landing page for the admin

This text is only visible to a user diff --git a/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp index 93f9dc2fbd..43f86bb059 100644 --- a/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp +++ b/spring-security-mvc-custom/src/main/webapp/WEB-INF/view/homepage.jsp @@ -1,22 +1,22 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> +<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%> -

This is the body of the sample view

+

This is the homepage for the user

This text is only visible to a user -
+
- + This text is only visible to an admin -
+
">Logout - + \ No newline at end of file