|
8 | 8 |
|
9 | 9 | `OAuth2AuthorizationServerConfiguration` uses xref:configuration-model.adoc#customizing-the-configuration[`OAuth2AuthorizationServerConfigurer`] to apply the default configuration and registers a `SecurityFilterChain` `@Bean` composed of all the infrastructure components supporting an OAuth2 authorization server. |
10 | 10 |
|
11 | | -[TIP] |
12 | | -`OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(HttpSecurity)` is a convenience (`static`) utility method that applies the default OAuth2 security configuration to `HttpSecurity`. |
13 | | - |
14 | 11 | The OAuth2 authorization server `SecurityFilterChain` `@Bean` is configured with the following default protocol endpoints: |
15 | 12 |
|
16 | 13 | * xref:protocol-endpoints.adoc#oauth2-authorization-endpoint[OAuth2 Authorization endpoint] |
@@ -58,11 +55,14 @@ https://openid.net/specs/openid-connect-core-1_0.html[OpenID Connect 1.0] is dis |
58 | 55 | ---- |
59 | 56 | @Bean |
60 | 57 | public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
61 | | - OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http); |
62 | | -
|
63 | | - http.getConfigurer(OAuth2AuthorizationServerConfigurer.class) |
64 | | - .oidc(Customizer.withDefaults()); // Initialize `OidcConfigurer` |
65 | | -
|
| 58 | + OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
| 59 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
| 60 | + http |
| 61 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 62 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 63 | + authorizationServer |
| 64 | + .oidc(Customizer.withDefaults()) // Initialize `OidcConfigurer` |
| 65 | + ); |
66 | 66 | return http.build(); |
67 | 67 | } |
68 | 68 | ---- |
@@ -105,28 +105,31 @@ Furthermore, it lets you customize the request processing logic for the protocol |
105 | 105 | @Bean |
106 | 106 | public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
107 | 107 | OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
108 | | - new OAuth2AuthorizationServerConfigurer(); |
109 | | - http.apply(authorizationServerConfigurer); |
110 | | -
|
111 | | - authorizationServerConfigurer |
112 | | - .registeredClientRepository(registeredClientRepository) <1> |
113 | | - .authorizationService(authorizationService) <2> |
114 | | - .authorizationConsentService(authorizationConsentService) <3> |
115 | | - .authorizationServerSettings(authorizationServerSettings) <4> |
116 | | - .tokenGenerator(tokenGenerator) <5> |
117 | | - .clientAuthentication(clientAuthentication -> { }) <6> |
118 | | - .authorizationEndpoint(authorizationEndpoint -> { }) <7> |
119 | | - .deviceAuthorizationEndpoint(deviceAuthorizationEndpoint -> { }) <8> |
120 | | - .deviceVerificationEndpoint(deviceVerificationEndpoint -> { }) <9> |
121 | | - .tokenEndpoint(tokenEndpoint -> { }) <10> |
122 | | - .tokenIntrospectionEndpoint(tokenIntrospectionEndpoint -> { }) <11> |
123 | | - .tokenRevocationEndpoint(tokenRevocationEndpoint -> { }) <12> |
124 | | - .authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint -> { }) <13> |
125 | | - .oidc(oidc -> oidc |
126 | | - .providerConfigurationEndpoint(providerConfigurationEndpoint -> { }) <14> |
127 | | - .logoutEndpoint(logoutEndpoint -> { }) <15> |
128 | | - .userInfoEndpoint(userInfoEndpoint -> { }) <16> |
129 | | - .clientRegistrationEndpoint(clientRegistrationEndpoint -> { }) <17> |
| 108 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
| 109 | +
|
| 110 | + http |
| 111 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 112 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 113 | + authorizationServer |
| 114 | + .registeredClientRepository(registeredClientRepository) <1> |
| 115 | + .authorizationService(authorizationService) <2> |
| 116 | + .authorizationConsentService(authorizationConsentService) <3> |
| 117 | + .authorizationServerSettings(authorizationServerSettings) <4> |
| 118 | + .tokenGenerator(tokenGenerator) <5> |
| 119 | + .clientAuthentication(clientAuthentication -> { }) <6> |
| 120 | + .authorizationEndpoint(authorizationEndpoint -> { }) <7> |
| 121 | + .deviceAuthorizationEndpoint(deviceAuthorizationEndpoint -> { }) <8> |
| 122 | + .deviceVerificationEndpoint(deviceVerificationEndpoint -> { }) <9> |
| 123 | + .tokenEndpoint(tokenEndpoint -> { }) <10> |
| 124 | + .tokenIntrospectionEndpoint(tokenIntrospectionEndpoint -> { }) <11> |
| 125 | + .tokenRevocationEndpoint(tokenRevocationEndpoint -> { }) <12> |
| 126 | + .authorizationServerMetadataEndpoint(authorizationServerMetadataEndpoint -> { }) <13> |
| 127 | + .oidc(oidc -> oidc |
| 128 | + .providerConfigurationEndpoint(providerConfigurationEndpoint -> { }) <14> |
| 129 | + .logoutEndpoint(logoutEndpoint -> { }) <15> |
| 130 | + .userInfoEndpoint(userInfoEndpoint -> { }) <16> |
| 131 | + .clientRegistrationEndpoint(clientRegistrationEndpoint -> { }) <17> |
| 132 | + ) |
130 | 133 | ); |
131 | 134 |
|
132 | 135 | return http.build(); |
@@ -232,18 +235,21 @@ It defines extension points that let you customize the pre-processing, main proc |
232 | 235 | @Bean |
233 | 236 | public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
234 | 237 | OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
235 | | - new OAuth2AuthorizationServerConfigurer(); |
236 | | - http.apply(authorizationServerConfigurer); |
237 | | -
|
238 | | - authorizationServerConfigurer |
239 | | - .clientAuthentication(clientAuthentication -> |
240 | | - clientAuthentication |
241 | | - .authenticationConverter(authenticationConverter) <1> |
242 | | - .authenticationConverters(authenticationConvertersConsumer) <2> |
243 | | - .authenticationProvider(authenticationProvider) <3> |
244 | | - .authenticationProviders(authenticationProvidersConsumer) <4> |
245 | | - .authenticationSuccessHandler(authenticationSuccessHandler) <5> |
246 | | - .errorResponseHandler(errorResponseHandler) <6> |
| 238 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
| 239 | +
|
| 240 | + http |
| 241 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 242 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 243 | + authorizationServer |
| 244 | + .clientAuthentication(clientAuthentication -> |
| 245 | + clientAuthentication |
| 246 | + .authenticationConverter(authenticationConverter) <1> |
| 247 | + .authenticationConverters(authenticationConvertersConsumer) <2> |
| 248 | + .authenticationProvider(authenticationProvider) <3> |
| 249 | + .authenticationProviders(authenticationProvidersConsumer) <4> |
| 250 | + .authenticationSuccessHandler(authenticationSuccessHandler) <5> |
| 251 | + .errorResponseHandler(errorResponseHandler) <6> |
| 252 | + ) |
247 | 253 | ); |
248 | 254 |
|
249 | 255 | return http.build(); |
@@ -288,13 +294,16 @@ The following example shows how to configure `JwtClientAssertionAuthenticationPr |
288 | 294 | @Bean |
289 | 295 | public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
290 | 296 | OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
291 | | - new OAuth2AuthorizationServerConfigurer(); |
292 | | - http.apply(authorizationServerConfigurer); |
| 297 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
293 | 298 |
|
294 | | - authorizationServerConfigurer |
295 | | - .clientAuthentication(clientAuthentication -> |
296 | | - clientAuthentication |
297 | | - .authenticationProviders(configureJwtClientAssertionValidator()) |
| 299 | + http |
| 300 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 301 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 302 | + authorizationServer |
| 303 | + .clientAuthentication(clientAuthentication -> |
| 304 | + clientAuthentication |
| 305 | + .authenticationProviders(configureJwtClientAssertionValidator()) |
| 306 | + ) |
298 | 307 | ); |
299 | 308 |
|
300 | 309 | return http.build(); |
@@ -339,14 +348,17 @@ If you need to verify another attribute of the client `X509Certificate`, for exa |
339 | 348 | @Bean |
340 | 349 | public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { |
341 | 350 | OAuth2AuthorizationServerConfigurer authorizationServerConfigurer = |
342 | | - new OAuth2AuthorizationServerConfigurer(); |
343 | | - http.apply(authorizationServerConfigurer); |
| 351 | + OAuth2AuthorizationServerConfigurer.authorizationServer(); |
344 | 352 |
|
345 | | - authorizationServerConfigurer |
346 | | - .clientAuthentication(clientAuthentication -> |
| 353 | + http |
| 354 | + .securityMatcher(authorizationServerConfigurer.getEndpointsMatcher()) |
| 355 | + .with(authorizationServerConfigurer, (authorizationServer) -> |
| 356 | + authorizationServer |
| 357 | + .clientAuthentication(clientAuthentication -> |
347 | 358 | clientAuthentication |
348 | | - .authenticationProviders(configureX509ClientCertificateVerifier()) |
349 | | - ); |
| 359 | + .authenticationProviders(configureX509ClientCertificateVerifier()) |
| 360 | + ) |
| 361 | + ); |
350 | 362 |
|
351 | 363 | return http.build(); |
352 | 364 | } |
|
0 commit comments