このバージョンはまだ開発中であり、まだ安定しているとは見なされていません。最新の安定バージョンについては、Spring Security 6.5.4 を使用してください!

SAML 2.0 移行

<saml2:LogoutRequest> 検証が失敗した場合は <saml2:LogoutResponse> を期待する

SAML アイデンティティプロバイダーは、<saml2:LogoutRequest> の処理に失敗した場合、サービスプロバイダーがエラー <saml2:LogoutResponse> を返すことを期待します。

過去のバージョンの Spring Security では、場合によっては 401 が返され、各依存パーティからのログアウトリクエストとレスポンスの チェーンが壊れていました。

Spring Security 7 ではこの動作は修正されており、何もする必要はありません。

ただし、これで問題が発生する場合は、エラー <saml2:LogoutRequest> が必要なときに null を返す Saml2LogoutRequestResolver を発行することで、以前の動作に戻すことができます。次のようなデリゲートを作成できます。

  • Java

  • Kotlin

@Bean
Saml2LogoutResponseResolver logoutResponseResolver(RelyingPartyRegistrationRepository registrations) {
    OpenSaml5LogoutResponseResolver delegate = new OpenSaml5LogoutResponseResolver(registrations);
    return new Saml2LogoutResponseResolver() {
        @Override
        public void resolve(HttpServletRequest request, Authentication authentication) {
            delegate.resolve(request, authentication);
        }

        @Override
        public void resolve(HttpServletRequest request, Authentication authentication, Saml2AuthenticationException error) {
            return null;
        }
    };
}
@Bean
fun logoutResponseResolver(registrations: RelyingPartyRegistrationRepository?): Saml2LogoutResponseResolver {
    val delegate = OpenSaml5LogoutResponseResolver(registrations)
    return object : Saml2LogoutResponseResolver() {
        override fun resolve(request: HttpServletRequest?, authentication: Authentication?) {
            delegate.resolve(request, authentication)
        }

        override fun resolve(request: HttpServletRequest?, authentication: Authentication?, error: Saml2AuthenticationException?) {
            return null
        }
    }
}

Saml2AuthenticatedPrincipal よりも Saml2ResponseAuthenticationAccessor を優先します

Spring Security 7 は <saml2:Assertion> の詳細をプリンシパルから分離します。これにより、Spring Security はシングルログアウトを実行するために必要なアサーションの詳細を取得できます。

これにより、Saml2AuthenticatedPrincipal は非推奨となります。Saml2Authentication を使用するためにこれを実装する必要はなくなりました。

代わりに、資格情報は Saml2ResponseAssertionAccessor を実装します。これは、認証に基づいて適切なアクションを決定するときに Spring Security 7 が優先します。

This change is made automatically for you when using the defaults.

If this causes you trouble when upgrading, you can publish a custom ResponseAuhenticationConverter to return a Saml2Authentication instead of returning a Saml2AssertionAuthentication like so:

  • Java

  • Kotlin

@Bean
OpenSaml5AuthenticationProvider authenticationProvider() {
	OpenSaml5AuthenticationProvider authenticationProvider =
		new OpenSaml5AuthenticationProvider();
	ResponseAuthenticationConverter defaults = new ResponseAuthenticationConverter();
	authenticationProvider.setResponseAuthenticationConverter(
		defaults.andThen((authentication) -> new Saml2Authentication(
			authentication.getPrincipal(),
			authentication.getSaml2Response(),
			authentication.getAuthorities())));
	return authenticationProvider;
}
@Bean
fun authenticationProvider(): OpenSaml5AuthenticationProvider {
	val authenticationProvider = OpenSaml5AuthenticationProvider()
	val defaults = ResponseAuthenticationConverter()
	authenticationProvider.setResponseAuthenticationConverter(
		defaults.andThen { authentication ->
			Saml2Authentication(authentication.getPrincipal(),
				authentication.getSaml2Response(),
				authentication.getAuthorities())
		})
	return authenticationProvider
}

If you are constructing a Saml2Authentication instance yourself, consider changing to Saml2AssertionAuthentication to get the same benefit as the current default.

<saml2:Response> GET リクエストを Saml2AuthenticationTokenConverter で処理しない

Spring Security は、SAML 2.0 仕様でサポートされていないため、GET 経由の <saml2:Response> ペイロードの処理をサポートしていません。

To better comply with this, Saml2AuthenticationTokenConverter and OpenSaml5AuthenticationTokenConverter will not process GET requests by default as of Spring Security 8. To prepare for this, the property shouldConvertGetRequests is available. To use it, publish your own converter like so:

  • Java

  • Kotlin

@Bean
OpenSaml5AuthenticationTokenConverter authenticationConverter(RelyingPartyRegistrationRepository registrations) {
	OpenSaml5AuthenticationTokenConverter authenticationConverter = new OpenSaml5AuthenticationTokenConverter(registrations);
	authenticationConverter.setShouldConvertGetRequests(false);
	return authenticationConverter;
}
@Bean
fun authenticationConverter(val registrations: RelyingPartyRegistrationRepository): Saml2AuthenticationTokenConverter {
	val authenticationConverter = Saml2AuthenticationTokenConverter(registrations)
	authenticationConverter.setShouldConvertGetRequests(false)
	return authenticationConverter
}

If you must continue using Saml2AuthenticationTokenConverter or OpenSaml5AuthenticationTokenConverter to process GET requests, you can call setShouldConvertGetRequests to true.