Spring-Security-Oauth2:默认登录成功网址

Yan*_*lem 5 java spring spring-security spring-security-oauth2

是否可以为Spring Oauth2 Sso服务设置默认登录成功?

继szenario之后

  1. 浏览器请求 index.html
  2. sso服务:不受保护==>返回 index.html
  3. index.html包含manifest属性==>浏览器请求清单
  4. sso服务:Manifest受保护==>返回401
  5. 客户端重定向到 ${sso.host}/login
  6. sso服务重定向到auth服务器
  7. authentication ==>重定向回${sso.host}/login查询字符串中的代码
  8. sso服务:请求令牌并重定向到清单文件

有没有办法不重定向到受保护的上次请求的资源,但默认情况下重定向到'index.html'?

即使没有办法实现这一点,请告诉我

Pat*_*era 11

我(我认为)有类似的问题:在我的情况下,一旦SSO请求成功,用户就被重定向到/,这不是我想要的.

有一个内置的解决方案需要一些挖掘才能找到.

AbstractAuthenticationProcessingFilter有一个方法setAuthenticationSuccessHandler,可以让你控制这一点,所以如果你有访问OAuth2ClientAuthenticationProcessingFilter,你可以将其设置为你想要的.

如果您有类似于教程的设置:https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_manual,那么您只需将以下内容添加到OAuth2ClientAuthenticationProcessingFilter教程中创建的内容中:

OAuth2ClientAuthenticationProcessingFilter oauth2Filter = new OAuth2ClientAuthenticationProcessingFilter("/XXXProvider/login");
oauth2Filter.setAuthenticationSuccessHandler(new SimpleUrlAuthenticationSuccessHandler() {
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        this.setDefaultTargetUrl("/my_preferred_location");
        super.onAuthenticationSuccess(request, response, authentication);
    }
});
Run Code Online (Sandbox Code Playgroud)