Spring Security 3的AuthenticationSuccessHandler示例

Spring Security 3的AuthenticationSuccessHandler示例,第1张

Spring Security 3的AuthenticationSuccessHandler示例

您可以执行以下 *** 作:

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

在XML配置中添加以下内容

<bean id="authenticationFilter" >    <!-- There might be more properties here, depending on your auth filter!! -->    <property name="authenticationSuccessHandler" ref="successHandler" /></bean><bean id="successHandler" />


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5615717.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存