プロトコルエンドポイント
OAuth2 認証エンドポイント
OAuth2AuthorizationEndpointConfigurer は、OAuth2 認証エンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 認可リクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。
OAuth2AuthorizationEndpointConfigurer は、次の構成オプションを提供します。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | authorizationRequestConverter(): HttpServletRequest から OAuth2 認可リクエスト [IETF] (英語) (または同意) を OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。 |
| 2 | authorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2AuthorizationCodeRequestAuthenticationToken または OAuth2AuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | authorizationResponseHandler(): 「認証された」 OAuth2AuthorizationCodeRequestAuthenticationToken を処理し、OAuth2AuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): OAuth2AuthorizationCodeRequestAuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。 |
| 7 | consentPage(): 認可リクエストフロー中に同意が必要な場合にリソース所有者をリダイレクトするカスタム同意ページの 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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 プッシュ認証リクエストエンドポイント
OAuth2PushedAuthorizationRequestEndpointConfigurer は、OAuth2 プッシュ認証リクエストエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 プッシュ認証リクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。
OAuth2PushedAuthorizationRequestEndpointConfigurer は、次の構成オプションを提供します。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
pushedAuthorizationRequestEndpoint
.pushedAuthorizationRequestConverter(pushedAuthorizationRequestConverter) (1)
.pushedAuthorizationRequestConverters(pushedAuthorizationRequestConvertersConsumer) (2)
.authenticationProvider(authenticationProvider) (3)
.authenticationProviders(authenticationProvidersConsumer) (4)
.pushedAuthorizationResponseHandler(pushedAuthorizationResponseHandler) (5)
.errorResponseHandler(errorResponseHandler) (6)
)
);
return http.build();
}| 1 | pushedAuthorizationRequestConverter(): HttpServletRequest から OAuth2 プッシュ認証リクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2PushedAuthorizationRequestAuthenticationToken のインスタンスに追加します。 |
| 2 | pushedAuthorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2PushedAuthorizationRequestAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | pushedAuthorizationResponseHandler(): 「認証された」 OAuth2PushedAuthorizationRequestAuthenticationToken を処理し、OAuth2 プッシュ認証レスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。 |
OAuth2PushedAuthorizationRequestEndpointConfigurer は OAuth2PushedAuthorizationRequestEndpointFilter を構成し、それを OAuth2 認可サーバー SecurityFilterChain @Bean に登録します。OAuth2PushedAuthorizationRequestEndpointFilter は、OAuth2 プッシュ認可リクエストを処理する Filter です。
OAuth2PushedAuthorizationRequestEndpointFilter は、次のデフォルトで構成されています。
AuthenticationConverter—OAuth2AuthorizationCodeRequestAuthenticationConverterから構成されるDelegatingAuthenticationConverter。AuthenticationManager—OAuth2PushedAuthorizationRequestAuthenticationProviderで構成されたAuthenticationManager。AuthenticationSuccessHandler— 「認証済み」OAuth2PushedAuthorizationRequestAuthenticationTokenを処理し、OAuth2 プッシュ認証レスポンスを返す内部実装。AuthenticationFailureHandler—OAuth2ErrorAuthenticationFailureHandler。
プッシュされた認可リクエストの検証のカスタマイズ
OAuth2AuthorizationCodeRequestAuthenticationValidator は、認可コードグラントで使用される特定の OAuth2 プッシュ認可リクエストパラメーターを検証するために使用されるデフォルトのバリデータです。デフォルトの実装では、redirect_uri および scope パラメーターが検証されます。検証に失敗した場合は、OAuth2AuthorizationCodeRequestAuthenticationException がスローされます。
OAuth2PushedAuthorizationRequestAuthenticationProvider は、型 Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> のカスタム認証バリデータを setAuthenticationValidator() に提供することで、デフォルトのプッシュされた認可リクエストの検証をオーバーライドする機能を提供します。
OAuth2AuthorizationCodeRequestAuthenticationContext は、OAuth2 プッシュ認証リクエストパラメーターを含む OAuth2AuthorizationCodeRequestAuthenticationToken を保持します。 |
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthorizationCodeRequestAuthenticationException をスローします。 |
開発ライフサイクルフェーズでの一般的な使用例は、redirect_uri パラメーターで localhost を許可することです。
次の例は、redirect_uri パラメーターで localhost を許可するカスタム認証バリデータを使用して OAuth2PushedAuthorizationRequestAuthenticationProvider を構成する方法を示しています。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.pushedAuthorizationRequestEndpoint(pushedAuthorizationRequestEndpoint ->
pushedAuthorizationRequestEndpoint
.authenticationProviders(configureAuthenticationValidator())
)
);
return http.build();
}
private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
return (authenticationProviders) ->
authenticationProviders.forEach((authenticationProvider) -> {
if (authenticationProvider instanceof OAuth2PushedAuthorizationRequestAuthenticationProvider) {
Consumer<OAuth2AuthorizationCodeRequestAuthenticationContext> authenticationValidator =
// Override default redirect_uri validator
new CustomRedirectUriValidator()
// Reuse default scope validator
.andThen(OAuth2AuthorizationCodeRequestAuthenticationValidator.DEFAULT_SCOPE_VALIDATOR);
((OAuth2PushedAuthorizationRequestAuthenticationProvider) 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | deviceAuthorizationRequestConverter(): HttpServletRequest から OAuth2 デバイス認可リクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2DeviceAuthorizationRequestAuthenticationToken のインスタンスに追加します。 |
| 2 | deviceAuthorizationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2DeviceAuthorizationRequestAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | deviceAuthorizationResponseHandler(): 「認証された」 OAuth2DeviceAuthorizationRequestAuthenticationToken を処理し、OAuth2DeviceAuthorizationResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。 |
| 7 | verificationUri(): リソース所有者をセカンダリデバイスに誘導するためのカスタムエンドユーザー検証ページの 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | deviceVerificationRequestConverter(): HttpServletRequest から OAuth2 デバイス検証リクエスト [IETF] (英語) (または同意) を OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。 |
| 2 | deviceVerificationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2DeviceVerificationAuthenticationToken または OAuth2DeviceAuthorizationConsentAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | deviceVerificationResponseHandler(): AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OAuth2DeviceVerificationAuthenticationToken を処理し、リソース所有者にデバイスに戻るよう指示するために使用されます。 |
| 6 | errorResponseHandler(): AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。 |
| 7 | consentPage(): デバイス検証リクエストフロー中に同意が必要な場合に、リソース所有者をリダイレクトするためのカスタム同意ページの 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.tokenEndpoint(tokenEndpoint ->
tokenEndpoint
.accessTokenRequestConverter(accessTokenRequestConverter) (1)
.accessTokenRequestConverters(accessTokenRequestConvertersConsumer) (2)
.authenticationProvider(authenticationProvider) (3)
.authenticationProviders(authenticationProvidersConsumer) (4)
.accessTokenResponseHandler(accessTokenResponseHandler) (5)
.errorResponseHandler(errorResponseHandler) (6)
)
);
return http.build();
}| 1 | accessTokenRequestConverter(): HttpServletRequest から OAuth2 アクセストークンリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2AuthorizationGrantAuthenticationToken のインスタンスに追加します。 |
| 2 | accessTokenRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2AuthorizationGrantAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | accessTokenResponseHandler(): OAuth2AccessTokenAuthenticationToken を処理して OAuth2AccessTokenResponse [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): OAuth2AuthenticationException を処理して OAuth2Error レスポンス [IETF] (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。 |
OAuth2TokenEndpointConfigurer は OAuth2TokenEndpointFilter を構成し、それを OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OAuth2TokenEndpointFilter は、OAuth2 アクセストークンリクエストを処理する Filter です。
サポートされている認可付与型 [IETF] (英語) は authorization_code、refresh_token、client_credentials、urn:ietf:params:oauth:grant-type:device_code、urn:ietf:params:oauth:grant-type:token-exchange です。
OAuth2TokenEndpointFilter は、次のデフォルトで構成されています。
AuthenticationConverter—OAuth2AuthorizationCodeAuthenticationConverter、OAuth2RefreshTokenAuthenticationConverter、OAuth2ClientCredentialsAuthenticationConverter、OAuth2DeviceCodeAuthenticationConverter、OAuth2TokenExchangeAuthenticationConverterで構成されるDelegatingAuthenticationConverter。AuthenticationManager—OAuth2AuthorizationCodeAuthenticationProvider、OAuth2RefreshTokenAuthenticationProvider、OAuth2ClientCredentialsAuthenticationProvider、OAuth2DeviceCodeAuthenticationProvider、OAuth2TokenExchangeAuthenticationProviderで構成されるAuthenticationManager。AuthenticationSuccessHandler—OAuth2AccessTokenResponseAuthenticationSuccessHandler。AuthenticationFailureHandler—OAuth2ErrorAuthenticationFailureHandler。
クライアント認証情報の付与リクエストの検証のカスタマイズ
OAuth2ClientCredentialsAuthenticationValidator は、特定の OAuth2 クライアント資格情報付与リクエストパラメーターを検証するために使用されるデフォルトのバリデーターです。デフォルトの実装では、scope パラメーターが検証されます。検証が失敗した場合は、OAuth2AuthenticationException がスローされます。
OAuth2ClientCredentialsAuthenticationProvider は、Consumer<OAuth2ClientCredentialsAuthenticationContext> 型のカスタム認証バリデーターを setAuthenticationValidator() に提供することで、デフォルトのリクエスト検証をオーバーライドする機能を提供します。
OAuth2ClientCredentialsAuthenticationContext は、OAuth2 クライアント資格情報付与リクエストパラメーターを含む OAuth2ClientCredentialsAuthenticationToken を保持します。 |
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthenticationException をスローします。 |
次の例は、デフォルトの scope 検証をオーバーライドするカスタム認証バリデータを使用して OAuth2ClientCredentialsAuthenticationProvider を設定する方法を示しています。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.tokenEndpoint(tokenEndpoint ->
tokenEndpoint
.authenticationProviders(configureAuthenticationValidator())
)
);
return http.build();
}
private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
return (authenticationProviders) ->
authenticationProviders.forEach((authenticationProvider) -> {
if (authenticationProvider instanceof OAuth2ClientCredentialsAuthenticationProvider) {
Consumer<OAuth2ClientCredentialsAuthenticationContext> authenticationValidator =
new CustomScopeValidator();
// Override default scope validation
((OAuth2ClientCredentialsAuthenticationProvider) authenticationProvider)
.setAuthenticationValidator(authenticationValidator);
}
});
}
static class CustomScopeValidator implements Consumer<OAuth2ClientCredentialsAuthenticationContext> {
@Override
public void accept(OAuth2ClientCredentialsAuthenticationContext authenticationContext) {
OAuth2ClientCredentialsAuthenticationToken clientCredentialsAuthentication =
authenticationContext.getAuthentication();
Set<String> requestedScopes = clientCredentialsAuthentication.getScopes();
RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
Set<String> allowedScopes = registeredClient.getScopes();
// TODO Implement scope validation
}
}DPoP バインドアクセストークン
RFC 9449 OAuth 2.0 所有証明の実証 (DPPoP とは) [IETF] (英語) は、アクセストークンの送信者制約のためのアプリケーションレベルのメカニズムです。
DPoP の主な目的は、認可サーバーによるアクセストークンの発行時に公開鍵にアクセストークンをバインドし、リソースサーバーでアクセストークンを使用する際にクライアントが対応する秘密鍵を所有していることを証明することを要求することにより、権限のないクライアントや不正なクライアントが漏洩または盗難されたアクセストークンを使用することを防ぐことです。
DPoP を介して送信者によって制約されるアクセストークンは、アクセストークンを所有するすべてのクライアントが使用できる一般的なベアラートークンとは対照的です。
DPoP は DPoP 証明 [IETF] (英語) の概念を導入します。これはクライアントによって作成され、HTTP リクエストのヘッダーとして送信される JWT です。クライアントは DPoP 証明を用いて、特定の公開鍵に対応する秘密鍵を所有していることを証明します。
クライアントがアクセストークンリクエストを開始すると、HTTP ヘッダーに DPoP 証明を添付します。認可サーバーは、アクセストークンを DPoP 証明に関連付けられた公開鍵にバインド(送信者制約)します。
クライアントが保護されたリソースリクエストを開始すると、HTTP ヘッダー内のリクエストに DPoP 証明が再度添付されます。
リソースサーバーは、アクセストークンにバインドされた公開鍵に関する情報を、アクセストークン(JWT)内から直接、OAuth2 トークンイントロスペクションエンドポイント経由で取得します。次に、リソースサーバーは、アクセストークンにバインドされた公開鍵が DPoP 証明内の公開鍵と一致することを検証します。また、DPoP 証明内のアクセストークンハッシュがリクエスト内のアクセストークンと一致することも検証します。
DPoP アクセストークンリクエスト
DPoP を用いて公開鍵に紐付けられたアクセストークンをリクエストするには、クライアントは OAuth2 トークンエンドポイントへのアクセストークンリクエスト時に、DPoP ヘッダーに有効な DPoP 証明を含める必要があります。これは、認可付与型(例: authorization_code、refresh_token、client_credentials など)に関係なく、すべてのアクセストークンリクエストに適用されます。
次の HTTP リクエストは、DPoP ヘッダーに DPoP 証明が含まれる authorization_code アクセストークンリクエストを示しています。
POST /oauth2/token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
DPoP: eyJraWQiOiJyc2EtandrLWtpZCIsInR5cCI6ImRwb3Arand0IiwiYWxnIjoiUlMyNTYiLCJqd2siOnsia3R5IjoiUlNBIiwiZSI6IkFRQUIiLCJraWQiOiJyc2EtandrLWtpZCIsIm4iOiIzRmxxSnI1VFJza0lRSWdkRTNEZDdEOWxib1dkY1RVVDhhLWZKUjdNQXZRbTdYWE5vWWttM3Y3TVFMMU5ZdER2TDJsOENBbmMwV2RTVElOVTZJUnZjNUtxbzJRNGNzTlg5U0hPbUVmem9ST2pRcWFoRWN2ZTFqQlhsdW9DWGRZdVlweDRfMXRmUmdHNmlpNFVoeGg2aUk4cU5NSlFYLWZMZnFoYmZZZnhCUVZSUHl3QmtBYklQNHgxRUFzYkM2RlNObWtoQ3hpTU5xRWd4YUlwWThDMmtKZEpfWklWLVdXNG5vRGR6cEtxSGN3bUI4RnNydW1sVllfRE5WdlVTRElpcGlxOVBiUDRIOTlUWE4xbzc0Nm9SYU5hMDdycTFob0NnTVNTeS04NVNhZ0NveGxteUUtRC1vZjlTc01ZOE9sOXQwcmR6cG9iQnVoeUpfbzVkZnZqS3cifX0.eyJodG0iOiJQT1NUIiwiaHR1IjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20vb2F1dGgyL3Rva2VuIiwiaWF0IjoxNzQ2ODA2MzA1LCJqdGkiOiI0YjIzNDBkMi1hOTFmLTQwYTUtYmFhOS1kZDRlNWRlYWM4NjcifQ.wq8gJ_G6vpiEinfaY3WhereqCCLoeJOG8tnWBBAzRWx9F1KU5yAAWq-ZVCk_k07-h6DIqz2wgv6y9dVbNpRYwNwDUeik9qLRsC60M8YW7EFVyI3n_NpujLwzZeub_nDYMVnyn4ii0NaZrYHtoGXOlswQfS_-ET-jpC0XWm5nBZsCdUEXjOYtwaACC6Js-pyNwKmSLp5SKIk11jZUR5xIIopaQy521y9qJHhGRwzj8DQGsP7wMZ98UFL0E--1c-hh4rTy8PMeWCqRHdwjj_ry_eTe0DJFcxxYQdeL7-0_0CIO4Ayx5WHEpcUOIzBRoN32RsNpDZc-5slDNj9ku004DA
grant_type=authorization_code\
&client_id=s6BhdRkqt\
&code=SplxlOBeZQQYbYS6WxSbIA\
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb\
&code_verifier=bEaL42izcC-o-xBk0K2vuJ6U-y1p9r_wW2dFWIWgjz-以下は、DPoP Proof JWT ヘッダーとクレームの表現を示しています。
{
"typ": "dpop+jwt",
"alg": "RS256",
"jwk": {
"kty": "RSA",
"e": "AQAB",
"n": "3FlqJr5TRskIQIgdE3Dd7D9lboWdcTUT8a-fJR7MAvQm7XXNoYkm3v7MQL1NYtDvL2l8CAnc0WdSTINU6IRvc5Kqo2Q4csNX9SHOmEfzoROjQqahEcve1jBXluoCXdYuYpx4_1tfRgG6ii4Uhxh6iI8qNMJQX-fLfqhbfYfxBQVRPywBkAbIP4x1EAsbC6FSNmkhCxiMNqEgxaIpY8C2kJdJ_ZIV-WW4noDdzpKqHcwmB8FsrumlVY_DNVvUSDIipiq9PbP4H99TXN1o746oRaNa07rq1hoCgMSSy-85SagCoxlmyE-D-of9SsMY8Ol9t0rdzpobBuhyJ_o5dfvjKw"
}
}{
"htm": "POST",
"htu": "https://server.example.com/oauth2/token",
"iat": 1746806305,
"jti": "4b2340d2-a91f-40a5-baa9-dd4e5deac867"
}次のコードは、DPoP Proof JWT を生成する方法の例を示しています。
RSAKey rsaKey = ...
JWKSource<SecurityContext> jwkSource = (jwkSelector, securityContext) -> jwkSelector
.select(new JWKSet(rsaKey));
NimbusJwtEncoder jwtEncoder = new NimbusJwtEncoder(jwkSource);
JwsHeader jwsHeader = JwsHeader.with(SignatureAlgorithm.RS256)
.type("dpop+jwt")
.jwk(rsaKey.toPublicJWK().toJSONObject())
.build();
JwtClaimsSet claims = JwtClaimsSet.builder()
.issuedAt(Instant.now())
.claim("htm", "POST")
.claim("htu", "https://server.example.com/oauth2/token")
.id(UUID.randomUUID().toString())
.build();
Jwt dPoPProof = jwtEncoder.encode(JwtEncoderParameters.from(jwsHeader, claims));認可サーバーが DPoP 証明を正常に検証すると、DPoP 証明からの公開鍵は発行されたアクセストークンにバインドされます (送信者によって制約されます)。
次のアクセストークンレスポンスでは、アクセストークンが DPoP 証明公開鍵にバインドされていることをクライアントに通知するために、token_type パラメーターが DPoP として表示されています。
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
{
"access_token": "Kz~8mXK1EalYznwH-LC-1fBAo.4Ljp~zsPE_NeO.gxU",
"token_type": "DPoP",
"expires_in": 2677
}公開鍵の確認
リソースサーバーは、アクセストークンが DPoP にバインドされているかどうかを識別し、DPoP 証明の公開鍵との紐付けを検証できなければなりません。紐付けは、リソースサーバーがアクセスできる方法で、公開鍵とアクセストークンを関連付けることによって実現されます。たとえば、公開鍵ハッシュをアクセストークンに直接埋め込む(JWT)、またはトークンイントロスペクションを利用するなどです。
アクセストークンが JWT として表現される場合、公開鍵 ハッシュは確認方法 (cnf) クレームの jkt クレームに含まれます。
次の例は、DPoP 証明公開鍵の JWK SHA-256 サムプリントである jkt クレームを含む cnf クレームを含む JWT アクセストークンのクレームを示しています。
{
"sub":"[email protected] (英語) ",
"iss":"https://server.example.com",
"nbf":1562262611,
"exp":1562266216,
"cnf":
{
"jkt":"CQMknzRoZ5YUi7vS58jck1q8TmZT8wiIiXrCN1Ny4VU"
}
}OAuth2 トークンイントロスペクションエンドポイント
OAuth2TokenIntrospectionEndpointConfigurer は、OAuth2 トークンイントロスペクションエンドポイント [IETF] (英語) をカスタマイズする機能を提供します。OAuth2 イントロスペクションリクエスト [IETF] (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。
OAuth2TokenIntrospectionEndpointConfigurer は、次の構成オプションを提供します。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.tokenIntrospectionEndpoint(tokenIntrospectionEndpoint ->
tokenIntrospectionEndpoint
.introspectionRequestConverter(introspectionRequestConverter) (1)
.introspectionRequestConverters(introspectionRequestConvertersConsumer) (2)
.authenticationProvider(authenticationProvider) (3)
.authenticationProviders(authenticationProvidersConsumer) (4)
.introspectionResponseHandler(introspectionResponseHandler) (5)
.errorResponseHandler(errorResponseHandler) (6)
)
);
return http.build();
}| 1 | introspectionRequestConverter(): HttpServletRequest から OAuth2 イントロスペクションリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenIntrospectionAuthenticationToken のインスタンスに追加します。 |
| 2 | introspectionRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2TokenIntrospectionAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | introspectionResponseHandler(): 「認証された」 OAuth2TokenIntrospectionAuthenticationToken を処理し、OAuth2TokenIntrospection レスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.tokenRevocationEndpoint(tokenRevocationEndpoint ->
tokenRevocationEndpoint
.revocationRequestConverter(revocationRequestConverter) (1)
.revocationRequestConverters(revocationRequestConvertersConsumer) (2)
.authenticationProvider(authenticationProvider) (3)
.authenticationProviders(authenticationProvidersConsumer) (4)
.revocationResponseHandler(revocationResponseHandler) (5)
.errorResponseHandler(errorResponseHandler) (6)
)
);
return http.build();
}| 1 | revocationRequestConverter(): HttpServletRequest から OAuth2 取り消しリクエスト [IETF] (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OAuth2TokenRevocationAuthenticationToken のインスタンスに追加します。 |
| 2 | revocationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OAuth2TokenRevocationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | revocationResponseHandler(): 「認証された」 OAuth2TokenRevocationAuthenticationToken を処理し、OAuth2 取り消しレスポンス [IETF] (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint ->
authorizationServerMetadataEndpoint
.authorizationServerMetadataCustomizer(authorizationServerMetadataCustomizer) (1)
)
);
return http.build();
}| 1 | authorizationServerMetadataCustomizer(): 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.oidc(oidc ->
oidc
.providerConfigurationEndpoint(providerConfigurationEndpoint ->
providerConfigurationEndpoint
.providerConfigurationCustomizer(providerConfigurationCustomizer) (1)
)
)
);
return http.build();
}| 1 | providerConfigurationCustomizer(): 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | logoutRequestConverter(): HttpServletRequest からログアウトリクエスト (英語) を OidcLogoutAuthenticationToken のインスタンスに抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を追加します。 |
| 2 | logoutRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OidcLogoutAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | logoutResponseHandler(): AuthenticationSuccessHandler ( ポストプロセッサー ) は、「認証された」 OidcLogoutAuthenticationToken を処理し、ログアウトを実行するために使用されます。 |
| 6 | errorResponseHandler(): AuthenticationFailureHandler ( ポストプロセッサー ) は、OAuth2AuthenticationException を処理し、エラーレスポンスを返すために使用されます。 |
OidcLogoutEndpointConfigurer は OidcLogoutEndpointFilter を構成し、OAuth2 認証サーバー SecurityFilterChain @Bean に登録します。OidcLogoutEndpointFilter は、RP によって開始されたログアウトリクエスト (英語) を処理し、エンドユーザーのログアウトを実行する Filter です。
OidcLogoutEndpointFilter は、次のデフォルトで構成されています。
AuthenticationConverter—OidcLogoutAuthenticationConverter。AuthenticationManager—OidcLogoutAuthenticationProviderで構成されたAuthenticationManager。AuthenticationSuccessHandler—OidcLogoutAuthenticationSuccessHandler。AuthenticationFailureHandler—OAuth2AuthenticationExceptionに関連付けられたOAuth2Errorを使用し、OAuth2Errorレスポンスを返す内部実装。
OidcLogoutAuthenticationProvider は、SessionRegistry を使用して、ログアウトをリクエストしているエンドユーザーに関連付けられた SessionInformation インスタンスを検索します。 |
OidcClientInitiatedLogoutSuccessHandler は、OpenID Connect 1.0 RP によって開始されるログアウトを構成するための Spring Security の OAuth2 クライアントサポートの対応する構成です。 |
ログアウトリクエストの検証のカスタマイズ
OidcLogoutAuthenticationValidator は、特定の OpenID Connect RP 開始ログアウトリクエストパラメーターを検証するために使用されるデフォルトのバリデータです。デフォルトの実装では、post_logout_redirect_uri パラメーターが検証されます。検証が失敗すると、OAuth2AuthenticationException がスローされます。
OidcLogoutAuthenticationProvider は、型 Consumer<OidcLogoutAuthenticationContext> のカスタム認証検証を setAuthenticationValidator() に提供することにより、デフォルトのログアウトリクエスト検証をオーバーライドする機能を提供します。
OidcLogoutAuthenticationContext は、ログアウトリクエストパラメーターを含む OidcLogoutAuthenticationToken を保持します。 |
検証が失敗した場合、認証バリデータ MUST は OAuth2AuthenticationException をスローします。 |
次の例は、カスタム認証バリデータを使用して OidcLogoutAuthenticationProvider を構成する方法を示しています。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.oidc(oidc ->
oidc
.logoutEndpoint(logoutEndpoint ->
logoutEndpoint
.authenticationProviders(configureAuthenticationValidator())
)
)
);
return http.build();
}
private Consumer<List<AuthenticationProvider>> configureAuthenticationValidator() {
return (authenticationProviders) ->
authenticationProviders.forEach((authenticationProvider) -> {
if (authenticationProvider instanceof OidcLogoutAuthenticationProvider oidcLogoutAuthenticationProvider) {
Consumer<OidcLogoutAuthenticationContext> authenticationValidator = new CustomPostLogoutRedirectUriValidator();
oidcLogoutAuthenticationProvider.setAuthenticationValidator(authenticationValidator);
}
});
}
static class CustomPostLogoutRedirectUriValidator implements Consumer<OidcLogoutAuthenticationContext> {
@Override
public void accept(OidcLogoutAuthenticationContext authenticationContext) {
OidcLogoutAuthenticationToken oidcLogoutAuthentication =
authenticationContext.getAuthentication();
RegisteredClient registeredClient = authenticationContext.getRegisteredClient();
// TODO
}
}OpenID Connect 1.0 UserInfo エンドポイント
OidcUserInfoEndpointConfigurer は、OpenID Connect 1.0 UserInfo エンドポイント (英語) をカスタマイズする機能を提供します。UserInfo リクエスト (英語) の前処理、メイン処理、後処理ロジックをカスタマイズできる拡張ポイントを定義します。
OidcUserInfoEndpointConfigurer は、次の構成オプションを提供します。
@Bean
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfigurer authorizationServerConfigurer =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | userInfoRequestConverter(): HttpServletRequest から UserInfo リクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcUserInfoAuthenticationToken のインスタンスに追加します。 |
| 2 | userInfoRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OidcUserInfoAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | userInfoResponseHandler(): 「認証された」 OidcUserInfoAuthenticationToken を処理し、UserInfo レスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): OAuth2AuthenticationException を処理して UserInfo エラーレスポンス (英語) を返すために使用される AuthenticationFailureHandler ( ポストプロセッサー )。 |
| 7 | userInfoMapper(): 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 で保護されたリソースであり、UserInfo リクエスト (英語) でベアラートークンとして送信されるアクセストークンを REQUIRES します。
OAuth2 リソースサーバーのサポートは自動構成されますが、OpenID Connect 1.0 UserInfo エンドポイントの場合、JwtDecoder @Bean は 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 =
OAuth2AuthorizationServerConfigurer.authorizationServer();
http
.securityMatcher(authorizationServerConfigurer.getEndpointsMatcher())
.with(authorizationServerConfigurer, (authorizationServer) ->
authorizationServer
.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();
}| 1 | clientRegistrationRequestConverter(): HttpServletRequest からクライアント登録リクエスト (英語) またはクライアント読み取りリクエスト (英語) を抽出しようとするときに使用される AuthenticationConverter ( プリプロセッサー ) を OidcClientRegistrationAuthenticationToken のインスタンスに追加します。 |
| 2 | clientRegistrationRequestConverters(): デフォルトの List および (オプションで) 追加された AuthenticationConverter へのアクセスを提供する Consumer を設定して、特定の AuthenticationConverter を追加、削除、カスタマイズする機能を許可します。 |
| 3 | authenticationProvider(): OidcClientRegistrationAuthenticationToken の認証に使用される AuthenticationProvider ( メインプロセッサー ) を追加します。 |
| 4 | authenticationProviders(): デフォルトの List および (オプションで) 追加された AuthenticationProvider へのアクセスを提供する Consumer を設定して、特定の AuthenticationProvider を追加、削除、カスタマイズする機能を許可します。 |
| 5 | clientRegistrationResponseHandler(): 「認証された」 OidcClientRegistrationAuthenticationToken を処理し、クライアント登録レスポンス (英語) またはクライアント読み取りレスポンス (英語) を返すために使用される AuthenticationSuccessHandler ( ポストプロセッサー )。 |
| 6 | errorResponseHandler(): 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 はクライアント登録 (またはクライアント読み取り) リクエストでベアラートークンとして送信されるアクセストークンです。
OAuth2 リソースサーバーのサポートは自動構成されますが、OpenID Connect 1.0 クライアント登録エンドポイントでは JwtDecoder @Bean は REQUIRED になります。 |
クライアント登録リクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.create。 |
クライアント読み取りリクエスト REQUIRES のアクセストークン、OAuth2 スコープ client.read。 |