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

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 が優先します。

デフォルトを使用すると、この変更は自動的に行われます。

アップグレード時に問題が発生する場合は、次のように、Saml2AssertionAuthentication を返す代わりに、Saml2Authentication を返すカスタム ResponseAuhenticationConverter を公開することができます。

  • 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
}

自分で Saml2Authentication インスタンスを構築する場合は、現在のデフォルトと同じ利点を得るために、Saml2AssertionAuthentication に変更することを検討してください。

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

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

これに対応するため、Saml2AuthenticationTokenConverter と OpenSaml5AuthenticationTokenConverter は Spring Security 8 以降、デフォルトでは GET リクエストを処理しなくなります。これに対応するため、shouldConvertGetRequests プロパティが利用可能です。これを使用するには、以下のように独自のコンバーターを公開してください。

  • 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
}

GET リクエストを処理するために Saml2AuthenticationTokenConverter または OpenSaml5AuthenticationTokenConverter を引き続き使用する必要がある場合は、setShouldConvertGetRequests から true. を呼び出すことができます。