Spring Security 3的AuthenticationSuccessHandler示例

我是Spring Security 3的新手。 我正在使用角色供用户登录。

我想基于该用户的角色将用户重定向到不同的页面,我理解的是我必须实现相同的AuthenticationSuccessHandler ,但是在这方面的一些示例会有所帮助。

提前谢谢,Vivek

你可以这样做:

 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"); } } } 

在XML配置中添加: