最新の安定バージョンについては、Spring Security 6.3.1 を使用してください!

Saml 2.0 メタデータ

Spring Security は、アサーティングパーティのメタデータを解析して AssertingPartyDetails インスタンスを生成したり、RelyingPartyRegistration インスタンスから証明書利用者のメタデータを公開したりできます。

<saml2:IDPSSODescriptor> メタデータの解析

RelyingPartyRegistrations を使用して、アサーティングパーティのメタデータを解析できます。

OpenSAML ベンダーサポートを使用する場合、結果の AssertingPartyDetails は型 OpenSamlAssertingPartyDetails になります。これは、以下を実行することで、基礎となる OpenSAML XMLObject を取得できることを意味します。

  • Java

  • Kotlin

OpenSamlAssertingPartyDetails details = (OpenSamlAssertingPartyDetails)
        registration.getAssertingPartyDetails();
EntityDescriptor openSamlEntityDescriptor = details.getEntityDescriptor();
val details: OpenSamlAssertingPartyDetails =
        registration.getAssertingPartyDetails() as OpenSamlAssertingPartyDetails;
val openSamlEntityDescriptor: EntityDescriptor = details.getEntityDescriptor();

<saml2:SPSSODescriptor> メタデータの作成

以下に示すように、Saml2MetadataFilter をフィルターチェーンに追加することにより、メタデータエンドポイントを公開できます。

  • Java

  • Kotlin

DefaultRelyingPartyRegistrationResolver relyingPartyRegistrationResolver =
        new DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository);
Saml2MetadataFilter filter = new Saml2MetadataFilter(
        relyingPartyRegistrationResolver,
        new OpenSamlMetadataResolver());

http
    // ...
    .saml2Login(withDefaults())
    .addFilterBefore(filter, Saml2WebSsoAuthenticationFilter.class);
val relyingPartyRegistrationResolver: Converter<HttpServletRequest, RelyingPartyRegistration> =
    DefaultRelyingPartyRegistrationResolver(this.relyingPartyRegistrationRepository)
val filter = Saml2MetadataFilter(
    relyingPartyRegistrationResolver,
    OpenSamlMetadataResolver()
)

http {
    //...
    saml2Login { }
    addFilterBefore<Saml2WebSsoAuthenticationFilter>(filter)
}

このメタデータエンドポイントを使用して、依存パーティをアサーティングパーティに登録できます。これは、メタデータエンドポイントを提供するための正しいフォームフィールドを見つけるのと同じくらい簡単です。

デフォルトでは、メタデータのエンドポイントは /saml2/service-provider-metadata/{registrationId} です。これを変更するには、フィルターで setRequestMatcher メソッドを呼び出します。

  • Java

  • Kotlin

filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"));
filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata/{registrationId}", "GET"))

または、コンストラクターにカスタムの証明書利用者登録リゾルバーを登録している場合は、次のように registrationId ヒントなしでパスを指定できます。

  • Java

  • Kotlin

filter.setRequestMatcher(new AntPathRequestMatcher("/saml2/metadata", "GET"));
filter.setRequestMatcher(AntPathRequestMatcher("/saml2/metadata", "GET"))

RelyingPartyRegistration のルックアップ方法の変更

カスタム RelyingPartyRegistrationResolver をメタデータエンドポイントに適用するには、次のようにフィルターコンストラクターで直接指定できます。

  • Java

RelyingPartyRegistrationResolver myRegistrationResolver = ...;
Saml2MetadataFilter metadata = new Saml2MetadataFilter(myRegistrationResolver, new OpenSamlMetadataResolver());

// ...

http.addFilterBefore(metadata, BasicAuthenticationFilter.class);
Kotlin
val myRegistrationResolver: RelyingPartyRegistrationResolver = ...;
val metadata = new Saml2MetadataFilter(myRegistrationResolver, OpenSamlMetadataResolver());

// ...

http.addFilterBefore(metadata, BasicAuthenticationFilter::class.java);

RelyingPartyRegistrationResolver を適用して URI から registrationId を削除する場合は、次のようにフィルター内の URI も変更する必要があります。

  • Java

metadata.setRequestMatcher("/saml2/metadata")
Kotlin
metadata.setRequestMatcher("/saml2/metadata")