|
16 | 16 |
|
17 | 17 | package org.springframework.security.oauth2.client.web.reactive.function.client; |
18 | 18 |
|
19 | | -import java.time.Duration; |
20 | 19 | import java.util.Collections; |
21 | 20 | import java.util.HashMap; |
22 | 21 | import java.util.Map; |
|
35 | 34 | import org.springframework.security.core.context.ReactiveSecurityContextHolder; |
36 | 35 | import org.springframework.security.core.context.SecurityContext; |
37 | 36 | import org.springframework.security.oauth2.client.ClientAuthorizationException; |
38 | | -import org.springframework.security.oauth2.client.ClientCredentialsReactiveOAuth2AuthorizedClientProvider; |
39 | 37 | import org.springframework.security.oauth2.client.OAuth2AuthorizeRequest; |
40 | 38 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; |
41 | 39 | import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizationFailureHandler; |
42 | 40 | import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientManager; |
43 | | -import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientProvider; |
44 | | -import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizedClientProviderBuilder; |
45 | | -import org.springframework.security.oauth2.client.RefreshTokenReactiveOAuth2AuthorizedClientProvider; |
46 | 41 | import org.springframework.security.oauth2.client.RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler; |
47 | 42 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; |
48 | | -import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest; |
49 | | -import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient; |
50 | 43 | import org.springframework.security.oauth2.client.registration.ClientRegistration; |
51 | 44 | import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository; |
52 | 45 | import org.springframework.security.oauth2.client.web.DefaultReactiveOAuth2AuthorizedClientManager; |
@@ -143,18 +136,10 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements |
143 | 136 |
|
144 | 137 | private final ReactiveOAuth2AuthorizedClientManager authorizedClientManager; |
145 | 138 |
|
146 | | - private boolean defaultAuthorizedClientManager; |
147 | | - |
148 | 139 | private boolean defaultOAuth2AuthorizedClient; |
149 | 140 |
|
150 | 141 | private String defaultClientRegistrationId; |
151 | 142 |
|
152 | | - @Deprecated |
153 | | - private Duration accessTokenExpiresSkew = Duration.ofMinutes(1); |
154 | | - |
155 | | - @Deprecated |
156 | | - private ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient; |
157 | | - |
158 | 143 | private ClientResponseHandler clientResponseHandler; |
159 | 144 |
|
160 | 145 | /** |
@@ -216,7 +201,6 @@ public ServerOAuth2AuthorizedClientExchangeFilterFunction( |
216 | 201 | this.authorizedClientManager = createDefaultAuthorizedClientManager(clientRegistrationRepository, |
217 | 202 | authorizedClientRepository, authorizationFailureHandler); |
218 | 203 | this.clientResponseHandler = new AuthorizationFailureForwarder(authorizationFailureHandler); |
219 | | - this.defaultAuthorizedClientManager = true; |
220 | 204 | } |
221 | 205 |
|
222 | 206 | private static ReactiveOAuth2AuthorizedClientManager createDefaultAuthorizedClientManager( |
@@ -253,8 +237,7 @@ private static ReactiveOAuth2AuthorizedClientManager createDefaultAuthorizedClie |
253 | 237 | * |
254 | 238 | * <ul> |
255 | 239 | * <li>A refresh token is present on the OAuth2AuthorizedClient</li> |
256 | | - * <li>The access token will be expired in |
257 | | - * {@link #setAccessTokenExpiresSkew(Duration)}</li> |
| 240 | + * <li>The access token will be expired in 1 minute (the default)</li> |
258 | 241 | * <li>The {@link ReactiveSecurityContextHolder} will be used to attempt to save the |
259 | 242 | * token. If it is empty, then the principal name on the OAuth2AuthorizedClient will |
260 | 243 | * be used to create an Authentication for saving.</li> |
@@ -339,73 +322,6 @@ public void setDefaultClientRegistrationId(String clientRegistrationId) { |
339 | 322 | this.defaultClientRegistrationId = clientRegistrationId; |
340 | 323 | } |
341 | 324 |
|
342 | | - /** |
343 | | - * Sets the {@link ReactiveOAuth2AccessTokenResponseClient} used for getting an |
344 | | - * {@link OAuth2AuthorizedClient} for the client_credentials grant. |
345 | | - * @param clientCredentialsTokenResponseClient the client to use |
346 | | - * @deprecated Use |
347 | | - * {@link #ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientManager)} |
348 | | - * instead. Create an instance of |
349 | | - * {@link ClientCredentialsReactiveOAuth2AuthorizedClientProvider} configured with a |
350 | | - * {@link ClientCredentialsReactiveOAuth2AuthorizedClientProvider#setAccessTokenResponseClient(ReactiveOAuth2AccessTokenResponseClient) |
351 | | - * WebClientReactiveClientCredentialsTokenResponseClient} (or a custom one) and than |
352 | | - * supply it to |
353 | | - * {@link DefaultReactiveOAuth2AuthorizedClientManager#setAuthorizedClientProvider(ReactiveOAuth2AuthorizedClientProvider) |
354 | | - * DefaultReactiveOAuth2AuthorizedClientManager}. |
355 | | - */ |
356 | | - @Deprecated |
357 | | - public void setClientCredentialsTokenResponseClient( |
358 | | - ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) { |
359 | | - Assert.notNull(clientCredentialsTokenResponseClient, "clientCredentialsTokenResponseClient cannot be null"); |
360 | | - Assert.state(this.defaultAuthorizedClientManager, |
361 | | - "The client cannot be set when the constructor used is \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientManager)\". " |
362 | | - + "Instead, use the constructor \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\"."); |
363 | | - this.clientCredentialsTokenResponseClient = clientCredentialsTokenResponseClient; |
364 | | - updateDefaultAuthorizedClientManager(); |
365 | | - } |
366 | | - |
367 | | - private void updateDefaultAuthorizedClientManager() { |
368 | | - // @formatter:off |
369 | | - ReactiveOAuth2AuthorizedClientProvider authorizedClientProvider = ReactiveOAuth2AuthorizedClientProviderBuilder.builder() |
370 | | - .authorizationCode() |
371 | | - .refreshToken((configurer) -> configurer.clockSkew(this.accessTokenExpiresSkew)) |
372 | | - .clientCredentials(this::updateClientCredentialsProvider) |
373 | | - .password((configurer) -> configurer.clockSkew(this.accessTokenExpiresSkew)) |
374 | | - .build(); |
375 | | - // @formatter:on |
376 | | - ((DefaultReactiveOAuth2AuthorizedClientManager) this.authorizedClientManager) |
377 | | - .setAuthorizedClientProvider(authorizedClientProvider); |
378 | | - } |
379 | | - |
380 | | - private void updateClientCredentialsProvider( |
381 | | - ReactiveOAuth2AuthorizedClientProviderBuilder.ClientCredentialsGrantBuilder builder) { |
382 | | - if (this.clientCredentialsTokenResponseClient != null) { |
383 | | - builder.accessTokenResponseClient(this.clientCredentialsTokenResponseClient); |
384 | | - } |
385 | | - builder.clockSkew(this.accessTokenExpiresSkew); |
386 | | - } |
387 | | - |
388 | | - /** |
389 | | - * An access token will be considered expired by comparing its expiration to now + |
390 | | - * this skewed Duration. The default is 1 minute. |
391 | | - * @param accessTokenExpiresSkew the Duration to use. |
392 | | - * @deprecated The {@code accessTokenExpiresSkew} should be configured with the |
393 | | - * specific {@link ReactiveOAuth2AuthorizedClientProvider} implementation, e.g. |
394 | | - * {@link ClientCredentialsReactiveOAuth2AuthorizedClientProvider#setClockSkew(Duration) |
395 | | - * ClientCredentialsReactiveOAuth2AuthorizedClientProvider} or |
396 | | - * {@link RefreshTokenReactiveOAuth2AuthorizedClientProvider#setClockSkew(Duration) |
397 | | - * RefreshTokenReactiveOAuth2AuthorizedClientProvider}. |
398 | | - */ |
399 | | - @Deprecated |
400 | | - public void setAccessTokenExpiresSkew(Duration accessTokenExpiresSkew) { |
401 | | - Assert.notNull(accessTokenExpiresSkew, "accessTokenExpiresSkew cannot be null"); |
402 | | - Assert.state(this.defaultAuthorizedClientManager, |
403 | | - "The accessTokenExpiresSkew cannot be set when the constructor used is \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientManager)\". " |
404 | | - + "Instead, use the constructor \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\"."); |
405 | | - this.accessTokenExpiresSkew = accessTokenExpiresSkew; |
406 | | - updateDefaultAuthorizedClientManager(); |
407 | | - } |
408 | | - |
409 | 325 | @Override |
410 | 326 | public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) { |
411 | 327 | // @formatter:off |
|
0 commit comments