Skip to content

Commit 6ee1643

Browse files
committed
Remove deprecations in ServerOAuth2AuthorizedClientExchangeFilterFunction
Closes gh-11589
1 parent 054791c commit 6ee1643

File tree

2 files changed

+1
-112
lines changed

2 files changed

+1
-112
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.java

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.security.oauth2.client.web.reactive.function.client;
1818

19-
import java.time.Duration;
2019
import java.util.Collections;
2120
import java.util.HashMap;
2221
import java.util.Map;
@@ -35,18 +34,12 @@
3534
import org.springframework.security.core.context.ReactiveSecurityContextHolder;
3635
import org.springframework.security.core.context.SecurityContext;
3736
import org.springframework.security.oauth2.client.ClientAuthorizationException;
38-
import org.springframework.security.oauth2.client.ClientCredentialsReactiveOAuth2AuthorizedClientProvider;
3937
import org.springframework.security.oauth2.client.OAuth2AuthorizeRequest;
4038
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
4139
import org.springframework.security.oauth2.client.ReactiveOAuth2AuthorizationFailureHandler;
4240
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;
4641
import org.springframework.security.oauth2.client.RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler;
4742
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;
5043
import org.springframework.security.oauth2.client.registration.ClientRegistration;
5144
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
5245
import org.springframework.security.oauth2.client.web.DefaultReactiveOAuth2AuthorizedClientManager;
@@ -143,18 +136,10 @@ public final class ServerOAuth2AuthorizedClientExchangeFilterFunction implements
143136

144137
private final ReactiveOAuth2AuthorizedClientManager authorizedClientManager;
145138

146-
private boolean defaultAuthorizedClientManager;
147-
148139
private boolean defaultOAuth2AuthorizedClient;
149140

150141
private String defaultClientRegistrationId;
151142

152-
@Deprecated
153-
private Duration accessTokenExpiresSkew = Duration.ofMinutes(1);
154-
155-
@Deprecated
156-
private ReactiveOAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient;
157-
158143
private ClientResponseHandler clientResponseHandler;
159144

160145
/**
@@ -216,7 +201,6 @@ public ServerOAuth2AuthorizedClientExchangeFilterFunction(
216201
this.authorizedClientManager = createDefaultAuthorizedClientManager(clientRegistrationRepository,
217202
authorizedClientRepository, authorizationFailureHandler);
218203
this.clientResponseHandler = new AuthorizationFailureForwarder(authorizationFailureHandler);
219-
this.defaultAuthorizedClientManager = true;
220204
}
221205

222206
private static ReactiveOAuth2AuthorizedClientManager createDefaultAuthorizedClientManager(
@@ -253,8 +237,7 @@ private static ReactiveOAuth2AuthorizedClientManager createDefaultAuthorizedClie
253237
*
254238
* <ul>
255239
* <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>
258241
* <li>The {@link ReactiveSecurityContextHolder} will be used to attempt to save the
259242
* token. If it is empty, then the principal name on the OAuth2AuthorizedClient will
260243
* be used to create an Authentication for saving.</li>
@@ -339,73 +322,6 @@ public void setDefaultClientRegistrationId(String clientRegistrationId) {
339322
this.defaultClientRegistrationId = clientRegistrationId;
340323
}
341324

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-
409325
@Override
410326
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
411327
// @formatter:off

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunctionTests.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
import org.springframework.security.oauth2.client.endpoint.OAuth2PasswordGrantRequest;
7878
import org.springframework.security.oauth2.client.endpoint.OAuth2RefreshTokenGrantRequest;
7979
import org.springframework.security.oauth2.client.endpoint.ReactiveOAuth2AccessTokenResponseClient;
80-
import org.springframework.security.oauth2.client.endpoint.WebClientReactiveClientCredentialsTokenResponseClient;
8180
import org.springframework.security.oauth2.client.registration.ClientRegistration;
8281
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
8382
import org.springframework.security.oauth2.client.registration.TestClientRegistrations;
@@ -107,7 +106,6 @@
107106
import static org.assertj.core.api.Assertions.assertThat;
108107
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
109108
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
110-
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
111109
import static org.assertj.core.api.Assertions.entry;
112110
import static org.mockito.ArgumentMatchers.any;
113111
import static org.mockito.ArgumentMatchers.eq;
@@ -212,31 +210,6 @@ public void constructorWhenAuthorizedClientManagerIsNullThenThrowIllegalArgument
212210
.isThrownBy(() -> new ServerOAuth2AuthorizedClientExchangeFilterFunction(null));
213211
}
214212

215-
@Test
216-
public void setClientCredentialsTokenResponseClientWhenClientIsNullThenThrowIllegalArgumentException() {
217-
assertThatIllegalArgumentException()
218-
.isThrownBy(() -> this.function.setClientCredentialsTokenResponseClient(null))
219-
.withMessage("clientCredentialsTokenResponseClient cannot be null");
220-
}
221-
222-
@Test
223-
public void setClientCredentialsTokenResponseClientWhenNotDefaultAuthorizedClientManagerThenThrowIllegalStateException() {
224-
assertThatIllegalStateException()
225-
.isThrownBy(() -> this.function.setClientCredentialsTokenResponseClient(
226-
new WebClientReactiveClientCredentialsTokenResponseClient()))
227-
.withMessage(
228-
"The client cannot be set when the constructor used is \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientManager)\". "
229-
+ "Instead, use the constructor \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\".");
230-
}
231-
232-
@Test
233-
public void setAccessTokenExpiresSkewWhenNotDefaultAuthorizedClientManagerThenThrowIllegalStateException() {
234-
assertThatIllegalStateException()
235-
.isThrownBy(() -> this.function.setAccessTokenExpiresSkew(Duration.ofSeconds(30))).withMessage(
236-
"The accessTokenExpiresSkew cannot be set when the constructor used is \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ReactiveOAuth2AuthorizedClientManager)\". "
237-
+ "Instead, use the constructor \"ServerOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\".");
238-
}
239-
240213
@Test
241214
public void filterWhenAuthorizedClientNullThenAuthorizationHeaderNull() {
242215
ClientRequest request = ClientRequest.create(HttpMethod.GET, URI.create("https://example.com")).build();

0 commit comments

Comments
 (0)