gpt4 book ai didi

java - Spring-Security-Oauth2:默认登录成功url

转载 作者:搜寻专家 更新时间:2023-10-31 08:25:48 26 4
gpt4 key购买 nike

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

接下来的场景

  1. 浏览器请求 index.html
  2. sso 服务:不 protected ==> 返回 index.html
  3. index.html 包含 manifest 属性 ==> 浏览器请求 list
  4. sso 服务: list protected ==> 返回 401
  5. 客户端重定向到 ${sso.host}/login
  6. sso 服务重定向到 auth 服务器
  7. 身份验证 ==> 使用查询字符串中的代码重定向回 ${sso.host}/login
  8. 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com