是否可以为 Spring Oauth2 Sso 服务设置默认登录成功网址?
接下来的场景
- 浏览器请求
index.html
- sso 服务:不 protected ==> 返回
index.html
- index.html 包含
manifest
属性 ==> 浏览器请求 list - sso 服务: list protected ==> 返回 401
- 客户端重定向到
${sso.host}/login
- sso 服务重定向到 auth 服务器
- 身份验证 ==> 使用查询字符串中的代码重定向回
${sso.host}/login
- sso 服务:请求 token 并重定向到 list 文件
有没有办法不重定向到上次请求的 protected 资源,而是默认重定向到“index.html”?
即使没有办法实现,也请告诉我
最佳答案
我有(我认为)类似的问题:在我的例子中,一旦 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);
}
});
关于java - Spring-Security-Oauth2:默认登录成功url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30545067/