Spring-Security-Oauth2:默认登录成功网址 [英] Spring-Security-Oauth2: Default login success url

查看:2528
本文介绍了Spring-Security-Oauth2:默认登录成功网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to set a default login successurl for a Spring Oauth2 Sso service?

关注szenario

Following szenario


  1. 浏览器请求 index.html

  2. sso服务:不受保护==>返回 index.html

  3. index.html包含清单属性==>浏览器请求清单

  4. sso服务:Manifest受保护==>返回401

  5. 客户端重定向到 $ {sso.host} / login

  6. sso服务重定向到auth服务器

  7. 身份验证==>重定向回 $ { sso.host} / login 使用query-String中的代码

  8. sso服务:请求令牌并重定向到清单文件

  1. browser reqeuests index.html
  2. sso service: Not protected ==> return the index.html
  3. index.html contains manifest attribute ==> browser requests the manifest
  4. sso service: Manifest is protected ==> returns 401
  5. client redirects to ${sso.host}/login
  6. sso service redirects to auth server
  7. authentication ==> redirects back to ${sso.host}/login with the code in the query-String
  8. sso service: requests token and redirects to the manifest file

有没有办法不重定向到最后一个受保护的资源,但默认情况下重定向到'index.html'?

Is there a way to NOT redirect to the last requested resource which was protected, but redirect to 'index.html' by default?

即使没有办法实现这个,也请告诉我

Please let me know even if there isn't a way to achieve this

推荐答案

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

I have (I think) a similar issue: in my case, once the SSO request succeeds the user is redirected to /, which is not what I want.

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

There is a built-in solution that took a bit of digging to find.

AbstractAuthenticationProcessingFilter 有一个允许你的方法 setAuthenticationSuccessHandler 要控制它,所以如果你有权访问 OAuth2ClientAuthenticationProcessingFilter ,你可以将它设置为你想要的。

The AbstractAuthenticationProcessingFilter has a method setAuthenticationSuccessHandler that allows you to control this, so if you have access to the OAuth2ClientAuthenticationProcessingFilter you can set it to what you want.

如果您有类似于教程的设置: https://spring.io/guides / tutorials / spring-boot-oauth2 /#_ social_login_manual 然后你可以简单地将以下内容添加到教程中创建的 OAuth2ClientAuthenticationProcessingFilter 中:

If you have a setup similar to the tutorial: https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_manual then you can simply add the following to the OAuth2ClientAuthenticationProcessingFilter that is created in the tutorial:

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

这篇关于Spring-Security-Oauth2:默认登录成功网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆