Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基于Spring Security的用户角色登录后重定向到不同页面_Java_Spring Boot_Hibernate_Spring Security - Fatal编程技术网

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())
    );