Spring-Security-Oauth2:默认登录成功网址 [英] Spring-Security-Oauth2: Default login success url
问题描述
是否可以为Spring Oauth2 Sso服务设置默认登录成功?
Is it possible to set a default login successurl for a Spring Oauth2 Sso service?
关注szenario
Following szenario
- 浏览器请求
index.html
- sso服务:不受保护==>返回
index.html
- index.html包含
清单
属性==>浏览器请求清单 - sso服务:Manifest受保护==>返回401
- 客户端重定向到
$ {sso.host} / login
- sso服务重定向到auth服务器
- 身份验证==>重定向回
$ { sso.host} / login
使用query-String中的代码 - sso服务:请求令牌并重定向到清单文件
- browser reqeuests
index.html
- sso service: Not protected ==> return the
index.html
- index.html contains
manifest
attribute ==> browser requests the manifest - sso service: Manifest is protected ==> returns 401
- client redirects to
${sso.host}/login
- sso service redirects to auth server
- authentication ==> redirects back to
${sso.host}/login
with the code in the query-String - 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屋!