AuthenticationSuccessHandler example for Spring Security 3

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

I am a newbie to Spring Security 3 . I am using roles for users to login.

I want to redirect a user to a different page based on the role of that user, I understand is that I would have to implement the AuthenticationSuccessHandler for the same, but some examples in that direction would help.

Thanks in advance, Vivek

回答1:

You can do something like this:

public class Test implements AuthenticationSuccessHandler {     public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {         Set roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());         if (roles.contains("ROLE_USER") {             response.sendRedirect("/userpage");         }     } } 

In the XML config add this:



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!