Spring-Security-Oauth2:默认登录成功url
是否可以为Spring Oauth2 Sso服务设置默认登录成功?
继szenario之后
- 浏览器reqeuests
index.html
- sso服务:不受保护==>返回
index.html
- index.html包含
manifest
属性==>浏览器请求清单 - sso服务:Manifest受保护==>返回401
- 客户端重定向到
${sso.host}/login
- sso服务重定向到auth服务器
- authentication ==>使用query-String中的代码重定向回
${sso.host}/login
- sso服务:请求令牌并重定向到清单文件
有没有办法不重定向到受保护的最后一个请求的资源,但默认情况下重定向到’index.html’?
即使没有办法实现这一点,请告诉我
我(我认为)有一个类似的问题:在我的情况下,一旦SSO请求成功,用户就被重定向到/,这不是我想要的。
有一个内置的解决方案需要一些挖掘才能找到。
AbstractAuthenticationProcessingFilter
有一个方法setAuthenticationSuccessHandler
,允许您控制它,因此如果您有权访问OAuth2ClientAuthenticationProcessingFilter
您可以将其设置为您想要的。
如果您有类似于教程的设置: https : OAuth2ClientAuthenticationProcessingFilter
,那么您只需将以下内容添加到教程中创建的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); } });