Spring Security中的AuthenticationSuccessHandler

Spring Security中的AuthenticationSuccessHandler,第1张

Spring Security中的AuthenticationSuccessHandler
import java.io.IOException;import java.util.Set;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.security.core.Authentication;import org.springframework.security.core.authority.AuthorityUtils;import org.springframework.security.web.authentication.AuthenticationSuccessHandler;import org.springframework.stereotype.Component;@Componentpublic class Securityhandler implements AuthenticationSuccessHandler {     public void onAuthenticationSuccess(HttpServletRequest request,   HttpServletResponse response, Authentication authentication) throws IOException  {        Set<String> roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities());        if (roles.contains("ROLE_ADMIN")) { response.sendRedirect("admin/home.html");        }    }}

您已经错过

@Component
成功处理程序类中的注释



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

原文地址: http://outofmemory.cn/zaji/5441698.html

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

发表评论

登录后才能评论

评论列表(0条)

保存