If you want to control the navigation flow after a successful authentication, you can do so by adding your own AuthenticationSuccessHandler.
Add the following attribute to your <form-login> element which refers to the customAuthenticationHandler bean,
<form-login login-page="/login.xhtml" authentication-success-handler-ref="customAuthenticationHandler"/>
...
</http>
<beans:bean id="customAuthenticationHandler" class="com.examples.CustomAuthenticationHandler" />
The CustomAuthenticationHandler class looks like this:
public class CustomAuthenticationHandler extends SimpleUrlAuthenticationSuccessHandler{
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws ServletException, IOException {
String userTargetUrl = "/welcome.xhtml";
String adminTargetUrl = "/admin/welcome.xhtml";
Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());
if (roles.contains("ROLE_ADMIN")) {
getRedirectStrategy().sendRedirect(request, response, adminTargetUrl);
}
else if(roles.contains("ROLE_USER")) {
getRedirectStrategy().sendRedirect(request, response, userTargetUrl);
}
else {
super.onAuthenticationSuccess(request, response, authentication);
return;
}
}
}