tldr;註冊一個自定義的AuthenticationSuccessHandler或配置SAMLRelayStateSuccessHandler以在成功驗證後設置重定向URL Spring Security的SAML擴展的適當方式是什麼?如何在Spring Security的SAML擴展中註冊AuthenticationSuccessHandler或SAMLRelayStateSuccessHandler?
我是Spring和Spring Security的新手,但是我已經獲得了一些成功,讓SAML擴展可以用於單點登錄應用程序。但是,我遇到了一個問題,Okta(IDP)和我的應用程序將在成功驗證後不斷循環,而不是轉到原始URL。我的懷疑是,這是由於我使用Vaadin以及Spring並且一旦Vaadin servlet加載,它完全是做了一些有趣的事情,或者完全忽略了Spring過濾器。在建議的解決方案是註冊AuthenticationSuccessHandler的博客文章combining filter-based Spring Security with Vaadin中提出了一個可能的問題和解決方案。
然而,Spring Security SAML擴展與簡單的表單登錄或OpenID相比並不那麼簡單。例如,使用表單登錄註冊成功處理程序非常簡單
http.formLogin().successHandler(handler);
沒有這樣的選項可用於SAML擴展。然而,在另一篇文章VladimírSchäfer中(參見「Spring saml-如何在SP上啓動登錄時記住請求參數,並在IdP響應後處理它們)建議將AuthenticationSuccessHandler更改爲SAMLRelayStateSuccessHandler。文檔表明這將是完美的方式它可是,我寧願不繼承SAMLEntryPoint
我現在SecurityConfiguration是完全基於Java的,並遵循使用Spring和1563一起馬特Raible的文章SecurityConfiguration如下:。
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable() // Disable Spring's CSRF protection and use Vaadin's.
.authorizeRequests() // Everything else: Do SAML SSO
// Allow everyone to attempt to login
.antMatchers("/root/saml*").permitAll()
// But make sure all other requests are authenticated
.anyRequest().authenticated()
.and()
// Create a completely new session
.sessionManagement().sessionFixation().newSession()
.and()
// Configure the saml properties
.apply(saml())
.serviceProvider()
.keyStore()
.storeFilePath("saml/keystore.jks")
.password(this.password)
.keyname(this.keyAlias)
.keyPassword(this.password)
.and()
.protocol("https")
// Do I need to adjust this localhost piece?
.hostname(String.format("%s:%s", "localhost", this.port))
.basePath("/")
.and()
// Load the metadata from the stored properties
.identityProvider().metadataFilePath(this.metadataUrl);
}
` `
註冊AuthenticationSuccessHandler或配置SAMLRelayStateSuccessHandler的最佳方法是什麼?任何其他想法也將不勝感激!
我希望我能接受兩個答案。我接受了我自己的,因爲它包含了更多關於如何做的細節以及進一步的反思,我認爲通過Java代碼使用XML文件是非常有價值的。基本上,我認爲HTTPSecurity上的Java API有點不足。 –