![](/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.