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

プロトコルエンドポイント

OAuth2 認証エンドポイント

OAuth2AuthorizationEndpointConfigurer は、OAuth2 認証エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 認可リクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2AuthorizationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.authorizationEndpoint(authorizationEndpoint ->
			authorizationEndpoint
				.authorizationRequestConverter(authorizationRequestConverter)   (1)
				.authorizationRequestConverters(authorizationRequestConvertersConsumer) (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer)   (4)
				.authorizationResponseHandler(authorizationResponseHandler) (5)
				.errorResponseHandler(errorResponseHandler) (6)
				.consentPage("/oauth2/v1/authorize")    (7)
		);

	return http.build();
}
1authorizationRequestConverter()HttpServletRequest から OAuth2 認可リクエスト [IETF] (英語) (または同意) を OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2authorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5authorizationResponseHandler(): 「認証された」 OAuth2AuthorizationCodeRequestAuthenticationToken を処理し、OAuth2AuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthorizationCodeRequestAuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7consentPage(): 認可リクエストフロー中に同意が必要な場合にリソース所有者をリダイレクトするカスタム同意ページの URI

OAuth2AuthorizationEndpointConfigurer は OAuth2AuthorizationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2AuthorizationEndpointFilter は、OAuth2 認証リクエスト (および同意) を処理する Filter です。

OAuth2AuthorizationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2AuthorizationCodeRequestAuthenticationConverter と OAuth2AuthorizationConsentAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2AuthorizationCodeRequestAuthenticationProvider と OAuth2AuthorizationConsentAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2AuthorizationCodeRequestAuthenticationToken を処理し、OAuth2AuthorizationResponse を返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthorizationCodeRequestAuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

認可リクエスト検証のカスタマイズ

OAuth2AuthorizationCodeRequestAuthenticationValidator は、Authorization Code Grant で使用される特定の OAuth2 認可リクエストパラメーターを検証するために使用されるデフォルトのバリデータです。デフォルトの実装では、redirect_uri および scope パラメーターが検証されます。検証に失敗すると、OAuth2AuthorizationCodeRequestAuthenticationException がスローされます。

OAuth2AuthorizationCodeRequestAuthenticationProvider は、型 Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> のカスタム認証バリデーターを setAuthenticationValidator() に提供することにより、デフォルトの認可リクエストの検証をオーバーライドする機能を提供します。

OAuth2AuthorizationCodeRequestAuthenticationContext は、OAuth2 認証リクエストパラメーターを含む OAuth2AuthorizationCodeRequestAuthenticationToken を保持します。
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthorizationCodeRequestAuthenticationException をスローします。

開発ライフサイクルフェーズでの一般的な使用例は、redirect_uri パラメーターで localhost を許可することです。

次の例は、redirect_uri パラメーターで localhost を許可するカスタム認証バリデータを使用して OAuth2AuthorizationCodeRequestAuthenticationProvider を構成する方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.authorizationEndpoint(authorizationEndpoint ->
			authorizationEndpoint
				.authenticationProviders(configureAuthenticationValidator())
		);

	return http.build();
}

private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
	return (authenticationProviders) ->
		authenticationProviders.forEach((authenticationProvider) -> {
			if (authenticationProvider instanceof OAuth2AuthorizationCodeRequestAuthenticationProvider) {
				Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> authenticationValidator =
					// Override default redirect_uri validator
					new CustomRedirectUriValidator()
						// Reuse default scope validator
						.andThen(OAuth2AuthorizationCodeRequestAuthenticationValidator.DEFAULT_SCOPE_VALIDATOR);

				((OAuth2AuthorizationCodeRequestAuthenticationProvider) authenticationProvider)
					.setAuthenticationValidator(authenticationValidator);
			}
		});
}

static class CustomRedirectUriValidator implements Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> {

	@Override
	public void accept(OAuth2AuthorizationCodeRequestAuthenticationContext authenticationContext) {
		OAuth2AuthorizationCodeRequestAuthenticationToken authorizationCodeRequestAuthentication =
			authenticationContext.getAuthentication();
		RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
		String requestedRedirectUri = authorizationCodeRequestAuthentication.getRedirectUri();

		// Use exact string matching when comparing client redirect URIs against pre-registered URIs
		if (!registeredClient.getRedirectUris().contains(requestedRedirectUri)) {
			OAuth2Error error = new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST);
			throw new OAuth2AuthorizationCodeRequestAuthenticationException(error, null);
		}
	}
}

OAuth2 デバイス認証エンドポイント

OAuth2DeviceAuthorizationEndpointConfigurer は、OAuth2 デバイス認証エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 デバイス認証リクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2DeviceAuthorizationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.deviceAuthorizationEndpoint(deviceAuthorizationEndpoint ->
			deviceAuthorizationEndpoint
				.deviceAuthorizationRequestConverter(deviceAuthorizationRequestConverter) (1)
				.deviceAuthorizationRequestConverters(deviceAuthorizationRequestConvertersConsumer) (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer) (4)
				.deviceAuthorizationResponseHandler(deviceAuthorizationResponseHandler) (5)
				.errorResponseHandler(errorResponseHandler) (6)
				.verificationUri("/oauth2/v1/device_verification") (7)
		);

	return http.build();
}
1deviceAuthorizationRequestConverter()HttpServletRequest から OAuth2 デバイス認可リクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2DeviceAuthorizationRequestAuthenticationToken のインスタンスに追加します。
2deviceAuthorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2DeviceAuthorizationRequestAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5deviceAuthorizationResponseHandler(): 「認証された」 OAuth2DeviceAuthorizationRequestAuthenticationToken を処理し、OAuth2DeviceAuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7verificationUri(): リソース所有者をセカンダリデバイスに誘導するためのカスタムエンドユーザー検証ページの URI

OAuth2DeviceAuthorizationEndpointConfigurer は OAuth2DeviceAuthorizationEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2DeviceAuthorizationEndpointFilter は、OAuth2 デバイス認証リクエストを処理する Filter です。

OAuth2DeviceAuthorizationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2DeviceAuthorizationRequestAuthenticationConverter

  • AuthenticationManager —  OAuth2DeviceAuthorizationRequestAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2DeviceAuthorizationRequestAuthenticationToken を処理し、OAuth2DeviceAuthorizationResponse を返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 デバイス検証エンドポイント

OAuth2DeviceVerificationEndpointConfigurer は、OAuth2 デバイス検証エンドポイント [IETF] (英語) (または「ユーザーインタラクション」) をカスタマイズする機能を提供します。OAuth2 デバイス検証リクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2DeviceVerificationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.deviceVerificationEndpoint(deviceVerificationEndpoint ->
			deviceVerificationEndpoint
				.deviceVerificationRequestConverter(deviceVerificationRequestConverter) (1)
				.deviceVerificationRequestConverters(deviceVerificationRequestConvertersConsumer) (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer) (4)
				.deviceVerificationResponseHandler(deviceVerificationResponseHandler) (5)
				.errorResponseHandler(errorResponseHandler) (6)
				.consentPage("/oauth2/v1/consent") (7)
		);

	return http.build();
}
1deviceVerificationRequestConverter()HttpServletRequest から OAuth2 デバイス検証リクエスト [IETF] (英語) (または同意) を OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2deviceVerificationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5deviceVerificationResponseHandler()AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OAuth2DeviceVerificationAuthenticationToken を処理し、リソース所有者にデバイスに戻るよう指示するために使用されます。
6errorResponseHandler()AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。
7consentPage(): デバイス検証リクエストフロー中に同意が必要な場合に、リソース所有者をリダイレクトするためのカスタム同意ページの URI

OAuth2DeviceVerificationEndpointConfigurer は OAuth2DeviceVerificationEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2DeviceVerificationEndpointFilter は、OAuth2 デバイス検証リクエスト (および同意) を処理する Filter です。

OAuth2DeviceVerificationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2DeviceVerificationAuthenticationConverter と OAuth2DeviceAuthorizationConsentAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2DeviceVerificationAuthenticationProvider と OAuth2DeviceAuthorizationConsentAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OAuth2DeviceVerificationAuthenticationToken を処理し、ユーザーを成功ページ (/?success) にリダイレクトする SimpleUrlAuthenticationSuccessHandler

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OAuth2 トークンエンドポイント

OAuth2TokenEndpointConfigurer は、OAuth2 トークンエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 アクセストークンリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.tokenEndpoint(tokenEndpoint ->
			tokenEndpoint
				.accessTokenRequestConverter(accessTokenRequestConverter)   (1)
				.accessTokenRequestConverters(accessTokenRequestConvertersConsumer) (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer)   (4)
				.accessTokenResponseHandler(accessTokenResponseHandler) (5)
				.errorResponseHandler(errorResponseHandler) (6)
		);

	return http.build();
}
1accessTokenRequestConverter()HttpServletRequest から OAuth2 アクセストークンリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2AuthorizationGrantAuthenticationToken のインスタンスに追加します。
2accessTokenRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2AuthorizationGrantAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5accessTokenResponseHandler()OAuth2AccessTokenAuthenticationToken を処理して OAuth2AccessTokenResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenEndpointConfigurer は OAuth2TokenEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2TokenEndpointFilter は、OAuth2 アクセストークンリクエストを処理する Filter です。

サポートされている認可付与型 [IETF] (英語) は authorization_coderefresh_tokenclient_credentialsurn:ietf:params:oauth:grant-type:device_code です。

OAuth2TokenEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2AuthorizationCodeAuthenticationConverterOAuth2RefreshTokenAuthenticationConverterOAuth2ClientCredentialsAuthenticationConverterOAuth2DeviceCodeAuthenticationConverter で構成される DelegatingAuthenticationConverter

  • AuthenticationManager —  OAuth2AuthorizationCodeAuthenticationProviderOAuth2RefreshTokenAuthenticationProviderOAuth2ClientCredentialsAuthenticationProviderOAuth2DeviceCodeAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler —  OAuth2AccessTokenAuthenticationToken を処理して OAuth2AccessTokenResponse を返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 トークンイントロスペクションエンドポイント

OAuth2TokenIntrospectionEndpointConfigurer は、OAuth2 トークンイントロスペクションエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 イントロスペクションリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenIntrospectionEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.tokenIntrospectionEndpoint(tokenIntrospectionEndpoint ->
			tokenIntrospectionEndpoint
				.introspectionRequestConverter(introspectionRequestConverter)   (1)
				.introspectionRequestConverters(introspectionRequestConvertersConsumer) (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer)   (4)
				.introspectionResponseHandler(introspectionResponseHandler) (5)
				.errorResponseHandler(errorResponseHandler) (6)
		);

	return http.build();
}
1introspectionRequestConverter()HttpServletRequest から OAuth2 イントロスペクションリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenIntrospectionAuthenticationToken のインスタンスに追加します。
2introspectionRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2TokenIntrospectionAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5introspectionResponseHandler(): 「認証された」 OAuth2TokenIntrospectionAuthenticationToken を処理し、OAuth2TokenIntrospection レスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenIntrospectionEndpointConfigurer は OAuth2TokenIntrospectionEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2TokenIntrospectionEndpointFilter は、OAuth2 イントロスペクションリクエストを処理する Filter です。

OAuth2TokenIntrospectionEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2TokenIntrospectionAuthenticationConverter

  • AuthenticationManager —  OAuth2TokenIntrospectionAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OAuth2TokenIntrospectionAuthenticationToken を処理し、OAuth2TokenIntrospection レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 トークン失効エンドポイント

OAuth2TokenRevocationEndpointConfigurer は、OAuth2 トークン失効エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 取り消しリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OAuth2TokenRevocationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.tokenRevocationEndpoint(tokenRevocationEndpoint ->
			tokenRevocationEndpoint
				.revocationRequestConverter(revocationRequestConverter) (1)
				.revocationRequestConverters(revocationRequestConvertersConsumer)   (2)
				.authenticationProvider(authenticationProvider) (3)
				.authenticationProviders(authenticationProvidersConsumer)   (4)
				.revocationResponseHandler(revocationResponseHandler)   (5)
				.errorResponseHandler(errorResponseHandler) (6)
		);

	return http.build();
}
1revocationRequestConverter()HttpServletRequest から OAuth2 取り消しリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenRevocationAuthenticationToken のインスタンスに追加します。
2revocationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OAuth2TokenRevocationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5revocationResponseHandler(): 「認証された」 OAuth2TokenRevocationAuthenticationToken を処理し、OAuth2 取り消しレスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。

OAuth2TokenRevocationEndpointConfigurer は OAuth2TokenRevocationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2TokenRevocationEndpointFilter は、OAuth2 取り消しリクエストを処理する Filter です。

OAuth2TokenRevocationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OAuth2TokenRevocationAuthenticationConverter

  • AuthenticationManager —  OAuth2TokenRevocationAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OAuth2TokenRevocationAuthenticationToken を処理し、OAuth2 失効レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2ErrorAuthenticationFailureHandler

OAuth2 認証サーバーメタデータエンドポイント

OAuth2AuthorizationServerMetadataEndpointConfigurer は、OAuth2 認証サーバーメタデータエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 認可サーバーメタデータレスポンス [IETF] (英語) をカスタマイズできる拡張ポイントを定義します。

OAuth2AuthorizationServerMetadataEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint ->
			authorizationServerMetadataEndpoint
				.authorizationServerMetadataCustomizer(authorizationServerMetadataCustomizer));   (1)

	return http.build();
}
1authorizationServerMetadataCustomizer()OAuth2AuthorizationServerMetadata.Builder へのアクセスを提供する Consumer は、認可サーバーの構成のクレームをカスタマイズする機能を認可します。

OAuth2AuthorizationServerMetadataEndpointConfigurer は OAuth2AuthorizationServerMetadataEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OAuth2AuthorizationServerMetadataEndpointFilter は、OAuth2AuthorizationServerMetadata レスポンス [IETF] (英語) を返す Filter です。

JWK セットエンドポイント

OAuth2AuthorizationServerConfigurer は JWK セットエンドポイント [IETF] (英語) のサポートを提供します。

OAuth2AuthorizationServerConfigurer は NimbusJwkSetEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。NimbusJwkSetEndpointFilter は、JWK セット [IETF] (英語) を返す Filter です。

JWK Set エンドポイントは、JWKSource<SecurityContext>@Bean が登録されている場合にのみ構成されます。

OpenID Connect 1.0 プロバイダー構成エンドポイント

OidcProviderConfigurationEndpointConfigurer は、OpenID Connect 1.0 プロバイダー構成エンドポイント (英語) をカスタマイズする機能を提供します。OpenID プロバイダー構成のレスポンス (英語) をカスタマイズできる拡張ポイントを定義します。

OidcProviderConfigurationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.oidc(oidc ->
			oidc
				.providerConfigurationEndpoint(providerConfigurationEndpoint ->
					providerConfigurationEndpoint
						.providerConfigurationCustomizer(providerConfigurationCustomizer)   (1)
				)
		);

	return http.build();
}
1providerConfigurationCustomizer()OidcProviderConfiguration.Builder へのアクセスを提供する Consumer により、OpenID プロバイダーの構成のクレームをカスタマイズできます。

OidcProviderConfigurationEndpointConfigurer は OidcProviderConfigurationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OidcProviderConfigurationEndpointFilter は、OidcProviderConfiguration レスポンス (英語) を返す Filter です。

OpenID Connect 1.0 ログアウトエンドポイント

OidcLogoutEndpointConfigurer は、OpenID Connect 1.0 ログアウトエンドポイント (英語) をカスタマイズする機能を提供します。これは、RP によって開始されたログアウトリクエストの前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcLogoutEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.oidc(oidc ->
			oidc
				.logoutEndpoint(logoutEndpoint ->
					logoutEndpoint
						.logoutRequestConverter(logoutRequestConverter) (1)
						.logoutRequestConverters(logoutRequestConvertersConsumer)   (2)
						.authenticationProvider(authenticationProvider) (3)
						.authenticationProviders(authenticationProvidersConsumer)   (4)
						.logoutResponseHandler(logoutResponseHandler)   (5)
						.errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1logoutRequestConverter()HttpServletRequest からログアウトリクエスト (英語) を OidcLogoutAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。
2logoutRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcLogoutAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5logoutResponseHandler()AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OidcLogoutAuthenticationToken を処理し、ログアウトを実行するために使用されます。
6errorResponseHandler()AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。

OidcLogoutEndpointConfigurer は OidcLogoutEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OidcLogoutEndpointFilter は、RP によって開始されたログアウトリクエスト (英語) を処理し、エンドユーザーのログアウトを実行する Filter です。

OidcLogoutEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OidcLogoutAuthenticationConverter

  • AuthenticationManager —  OidcLogoutAuthenticationProvider で構成された AuthenticationManager

  • AuthenticationSuccessHandler — 「認証された」 OidcLogoutAuthenticationToken を処理し、ログアウトを実行する内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OidcLogoutAuthenticationProvider は、SessionRegistry を使用して、ログアウトをリクエストしているエンドユーザーに関連付けられた SessionInformation インスタンスを検索します。
OidcClientInitiatedLogoutSuccessHandler は、OpenID Connect 1.0 RP によって開始されるログアウトを構成するための Spring Security の OAuth2 クライアントサポートの対応する構成です。

OpenID Connect 1.0 UserInfo エンドポイント

OidcUserInfoEndpointConfigurer は、OpenID Connect 1.0 UserInfo エンドポイント (英語) をカスタマイズする機能を提供します。UserInfo リクエスト (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcUserInfoEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.oidc(oidc ->
			oidc
				.userInfoEndpoint(userInfoEndpoint ->
					userInfoEndpoint
						.userInfoRequestConverter(userInfoRequestConverter) (1)
						.userInfoRequestConverters(userInfoRequestConvertersConsumer) (2)
						.authenticationProvider(authenticationProvider) (3)
						.authenticationProviders(authenticationProvidersConsumer) (4)
						.userInfoResponseHandler(userInfoResponseHandler) (5)
						.errorResponseHandler(errorResponseHandler) (6)
						.userInfoMapper(userInfoMapper) (7)
				)
		);

	return http.build();
}
1userInfoRequestConverter()HttpServletRequest から UserInfo リクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcUserInfoAuthenticationToken のインスタンスに追加します。
2userInfoRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcUserInfoAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5userInfoResponseHandler(): 「認証された」 OidcUserInfoAuthenticationToken を処理し、UserInfo レスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理して UserInfo エラーレスポンス (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
7userInfoMapper()OidcUserInfoAuthenticationContext から OidcUserInfo のインスタンスへのクレームを抽出するために使用される Function

OidcUserInfoEndpointConfigurer は OidcUserInfoEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OidcUserInfoEndpointFilter は、UserInfo リクエスト (英語) を処理して OidcUserInfo レスポンス (英語) を返す Filter です。

OidcUserInfoEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  SecurityContext から Authentication を取得し、プリンシパルで OidcUserInfoAuthenticationToken を作成する内部実装。

  • AuthenticationManager —  OidcUserInfoAuthenticationProvider で構成される AuthenticationManager。認可時にリクエストされたスコープ (英語) に基づいて ID トークン (英語) から標準クレーム (英語) を抽出する userInfoMapper の内部実装に関連付けられています。

  • AuthenticationSuccessHandler — 「認証済み」 OidcUserInfoAuthenticationToken を処理し、OidcUserInfo レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OAuth2TokenCustomizer<JwtEncodingContext> @Bean を提供することで、ID トークンをカスタマイズできます。

OpenID Connect 1.0 UserInfo エンドポイントは OAuth2 で保護されたリソースであり、この REQUIRESUserInfo リクエスト (英語) でベアラートークンとして送信されるアクセストークンです。次の例は、OAuth2 リソースサーバー構成を有効にする方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	...

	http.oauth2ResourceServer(resourceServer -> resourceServer.jwt(Customizer.withDefaults()));

	return http.build();
}

@Bean
public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
	return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
}
JwtDecoder@Bean は、OpenID Connect 1.0 UserInfo エンドポイントの REQUIRED です。
ガイド使い方: OpenID Connect 1.0 UserInfo レスポンスをカスタマイズするには、UserInfo エンドポイントをカスタマイズする例が含まれています。

OpenID Connect 1.0 クライアント登録エンドポイント

OidcClientRegistrationEndpointConfigurer は、OpenID Connect 1.0 クライアント登録エンドポイント (英語) をカスタマイズする機能を提供します。クライアント登録リクエスト (英語) またはクライアント読み取りリクエスト (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。

OidcClientRegistrationEndpointConfigurer は、次の構成オプションを提供します。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	authorizationServerConfigurer
		.oidc(oidc ->
			oidc
				.clientRegistrationEndpoint(clientRegistrationEndpoint ->
					clientRegistrationEndpoint
						.clientRegistrationRequestConverter(clientRegistrationRequestConverter) (1)
						.clientRegistrationRequestConverters(clientRegistrationRequestConvertersConsumers) (2)
						.authenticationProvider(authenticationProvider) (3)
						.authenticationProviders(authenticationProvidersConsumer) (4)
						.clientRegistrationResponseHandler(clientRegistrationResponseHandler) (5)
						.errorResponseHandler(errorResponseHandler) (6)
				)
		);

	return http.build();
}
1clientRegistrationRequestConverter()HttpServletRequest からクライアント登録リクエスト (英語) またはクライアント読み取りリクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcClientRegistrationAuthenticationToken のインスタンスに追加します。
2clientRegistrationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。
3authenticationProvider()OidcClientRegistrationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。
4authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。
5clientRegistrationResponseHandler(): 「認証された」 OidcClientRegistrationAuthenticationToken を処理し、クライアント登録レスポンス (英語) またはクライアント読み取りレスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。
6errorResponseHandler()OAuth2AuthenticationException を処理し、クライアント登録エラーレスポンス (英語) またはクライアント読み取りエラーレスポンス (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。
多くの デプロイ は動的クライアント登録を必要としないため、OpenID Connect 1.0 クライアント登録エンドポイントはデフォルトで無効になっています。

OidcClientRegistrationEndpointConfigurer は OidcClientRegistrationEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain@Bean に登録します。OidcClientRegistrationEndpointFilter は、クライアント登録リクエスト (英語) を処理して OidcClientRegistration レスポンス (英語) を返す Filter です。

OidcClientRegistrationEndpointFilter もクライアント読み取りリクエスト (英語) を処理し、OidcClientRegistration レスポンス (英語) を返します。

OidcClientRegistrationEndpointFilter は、次のデフォルトで構成されています。

  • AuthenticationConverter —  OidcClientRegistrationAuthenticationConverter

  • AuthenticationManager —  OidcClientRegistrationAuthenticationProvider と OidcClientConfigurationAuthenticationProvider で構成される AuthenticationManager

  • AuthenticationSuccessHandler — 「認証済み」 OidcClientRegistrationAuthenticationToken を処理し、OidcClientRegistration レスポンスを返す内部実装。

  • AuthenticationFailureHandler —  OAuth2AuthenticationException に関連付けられた OAuth2Error を使用し、OAuth2Error レスポンスを返す内部実装。

OpenID Connect 1.0 クライアント登録エンドポイントは OAuth2 で保護されたリソース (英語) であり、REQUIRES はクライアント登録 (またはクライアント読み取り) リクエストでベアラートークンとして送信されるアクセストークンです。

クライアント登録リクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.create
クライアント読み取りリクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.read

次の例は、OAuth2 リソースサーバー構成を有効にする方法を示しています。

@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
	OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
		new OAuth2AuthorizationServerConfigurer();
	http.apply(authorizationServerConfigurer);

	...

	http.oauth2ResourceServer(resourceServer -> resourceServer.jwt(Customizer.withDefaults()));

	return http.build();
}

@Bean
public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
	return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
}
JwtDecoder@Bean は、OpenID Connect 1.0 クライアント登録エンドポイントの REQUIRED です。