Java 基于Spring Security的用户角色登录后重定向到不同页面
Java 基于Spring Security的用户角色登录后重定向到不同页面,java,spring-boot,hibernate,spring-security,Java,Spring Boot,Hibernate,Spring Security,欢迎来到阿卡什之家 欢迎来到门户网站 您可以提供自定义的AuthenticationSuccessHandler AuthenticationSuccessHandler告诉Spring Security在成功的用户身份验证之后应该做什么。 默认实现通常使用SimpleRulthenticationSuccessHandler,一旦用户成功进行身份验证,它会将用户重定向到提供的URL 在自定义实现中,您可以根据用户的角色委托给不同的SimpleRuThenticationSuccessHan
欢迎来到阿卡什之家
欢迎来到门户网站
您可以提供自定义的AuthenticationSuccessHandler
AuthenticationSuccessHandler
告诉Spring Security在成功的用户身份验证之后应该做什么。默认实现通常使用
SimpleRulthenticationSuccessHandler
,一旦用户成功进行身份验证,它会将用户重定向到提供的URL
在自定义实现中,您可以根据用户的角色委托给不同的SimpleRuThenticationSuccessHandler
公共类CustomAuthenticationSuccessHandler实现AuthenticationSuccessHandler{
SimpleRuThenticationSuccessHandler用户SuccessHandler=
新的SimpleRuthenticationSuccessHandler(“/user page”);
SimpleRuthenticationSuccessHandler管理员SuccessHandler=
新的SimpleRuthenticationSuccessHandler(“/admin页”);
@凌驾
AuthenticationSuccess(HttpServletRequest请求、HttpServletResponse响应、,
身份验证)引发IOException、ServletException{
CollectionHi在这里。到目前为止,我尝试了什么来实现您的解决方案?尝试添加源代码或更多特定于您的情况的代码示例。感谢您指出这一点,我已经成功实现了此功能,下次我将确保添加更多的代码示例
http
.formLogin(formLogin -> formLogin
.successHandler(new CustomAuthenticationSuccessHandler())
);