I have a made a user login interface which gets authenticated using Spring Security.
I made an authenticationsuccesshandler which redirects user to other page. Here is the Java Code that handles it.
protected String determineTargetUrl(final Authentication authentication) {
boolean isUser = false;
boolean isAdmin = false;
final Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
for (final GrantedAuthority grantedAuthority : authorities) {
if (grantedAuthority.getAuthority().equals("ROLE_USER")) {
isUser = true;
break;
} else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) {
isAdmin = true;
break;
}
}
if (isUser) {
return "/static_htm.html";
} else if (isAdmin) {
return "/console.html";
} else {
throw new IllegalStateException();
}
}
I can't seem to understand if I wanted to add a Controller for displaying username for example or displaying error message on wrong login, how should I achieve it with or without a controller.
I also tried adding a new Java Package having Controller class but it didn't work. Any Ideas ?
Also, what is the difference between authenticationsuccesshandler and a controller ?
Aucun commentaire:
Enregistrer un commentaire