![](/img/trans.png)
[英]No Bean for ResourceServerTokenServices found - Spring-Security-Oauth2
[英]Spring-Security-Oauth2: Default login success url
是否可以为 Spring Oauth2 Sso 服务设置默认登录成功网址?
以下场景
index.html
index.html
manifest
属性 ==> 浏览器请求清单${sso.host}/login
${sso.host}/login
有没有办法不重定向到上次请求的受保护资源,而是默认重定向到“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);
}
});
有没有办法不重定向到上次请求的受保护资源,而是默认重定向到“index.html”?
是的,在 WebSecurityConfigurerAdapter 中:
public class MyWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
[...]
@Override
protected void configure(HttpSecurity http) throws Exception {
http
[...]
.oauth2Login()
.defaultSuccessUrl("index.html", true)
[...]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.