Skip to content

Commit 054791c

Browse files
committed
Remove deprecations in ServletOAuth2AuthorizedClientExchangeFilterFunction
Closes gh-11588
1 parent 65db5fa commit 054791c

File tree

2 files changed

+2
-114
lines changed

2 files changed

+2
-114
lines changed

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

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -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;
@@ -38,18 +37,14 @@
3837
import org.springframework.security.core.authority.AuthorityUtils;
3938
import org.springframework.security.core.context.SecurityContextHolder;
4039
import org.springframework.security.oauth2.client.ClientAuthorizationException;
41-
import org.springframework.security.oauth2.client.ClientCredentialsOAuth2AuthorizedClientProvider;
4240
import org.springframework.security.oauth2.client.OAuth2AuthorizationFailureHandler;
4341
import org.springframework.security.oauth2.client.OAuth2AuthorizeRequest;
4442
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
4543
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
4644
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
4745
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
48-
import org.springframework.security.oauth2.client.RefreshTokenOAuth2AuthorizedClientProvider;
4946
import org.springframework.security.oauth2.client.RemoveAuthorizedClientOAuth2AuthorizationFailureHandler;
5047
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
51-
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
52-
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest;
5348
import org.springframework.security.oauth2.client.registration.ClientRegistration;
5449
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
5550
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
@@ -150,16 +145,8 @@ public final class ServletOAuth2AuthorizedClientExchangeFilterFunction implement
150145
private static final Authentication ANONYMOUS_AUTHENTICATION = new AnonymousAuthenticationToken("anonymous",
151146
"anonymousUser", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
152147

153-
@Deprecated
154-
private Duration accessTokenExpiresSkew = Duration.ofMinutes(1);
155-
156-
@Deprecated
157-
private OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient;
158-
159148
private OAuth2AuthorizedClientManager authorizedClientManager;
160149

161-
private boolean defaultAuthorizedClientManager;
162-
163150
private boolean defaultOAuth2AuthorizedClient;
164151

165152
private String defaultClientRegistrationId;
@@ -224,7 +211,6 @@ public ServletOAuth2AuthorizedClientExchangeFilterFunction(
224211
clientRegistrationRepository, authorizedClientRepository);
225212
defaultAuthorizedClientManager.setAuthorizationFailureHandler(authorizationFailureHandler);
226213
this.authorizedClientManager = defaultAuthorizedClientManager;
227-
this.defaultAuthorizedClientManager = true;
228214
this.clientResponseHandler = new AuthorizationFailureForwarder(authorizationFailureHandler);
229215
}
230216

@@ -235,52 +221,6 @@ private void removeAuthorizedClient(OAuth2AuthorizedClientRepository authorizedC
235221
authorizedClientRepository.removeAuthorizedClient(clientRegistrationId, principal, request, response);
236222
}
237223

238-
/**
239-
* Sets the {@link OAuth2AccessTokenResponseClient} used for getting an
240-
* {@link OAuth2AuthorizedClient} for the client_credentials grant.
241-
* @param clientCredentialsTokenResponseClient the client to use
242-
* @deprecated Use
243-
* {@link #ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager)}
244-
* instead. Create an instance of
245-
* {@link ClientCredentialsOAuth2AuthorizedClientProvider} configured with a
246-
* {@link ClientCredentialsOAuth2AuthorizedClientProvider#setAccessTokenResponseClient(OAuth2AccessTokenResponseClient)
247-
* DefaultClientCredentialsTokenResponseClient} (or a custom one) and than supply it
248-
* to
249-
* {@link DefaultOAuth2AuthorizedClientManager#setAuthorizedClientProvider(OAuth2AuthorizedClientProvider)
250-
* DefaultOAuth2AuthorizedClientManager}.
251-
*/
252-
@Deprecated
253-
public void setClientCredentialsTokenResponseClient(
254-
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) {
255-
Assert.notNull(clientCredentialsTokenResponseClient, "clientCredentialsTokenResponseClient cannot be null");
256-
Assert.state(this.defaultAuthorizedClientManager,
257-
"The client cannot be set when the constructor used is \"ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager)\". "
258-
+ "Instead, use the constructor \"ServletOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\".");
259-
this.clientCredentialsTokenResponseClient = clientCredentialsTokenResponseClient;
260-
updateDefaultAuthorizedClientManager();
261-
}
262-
263-
private void updateDefaultAuthorizedClientManager() {
264-
// @formatter:off
265-
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
266-
.authorizationCode()
267-
.refreshToken((configurer) -> configurer.clockSkew(this.accessTokenExpiresSkew))
268-
.clientCredentials(this::updateClientCredentialsProvider)
269-
.password((configurer) -> configurer.clockSkew(this.accessTokenExpiresSkew))
270-
.build();
271-
// @formatter:on
272-
((DefaultOAuth2AuthorizedClientManager) this.authorizedClientManager)
273-
.setAuthorizedClientProvider(authorizedClientProvider);
274-
}
275-
276-
private void updateClientCredentialsProvider(
277-
OAuth2AuthorizedClientProviderBuilder.ClientCredentialsGrantBuilder builder) {
278-
if (this.clientCredentialsTokenResponseClient != null) {
279-
builder.accessTokenResponseClient(this.clientCredentialsTokenResponseClient);
280-
}
281-
builder.clockSkew(this.accessTokenExpiresSkew);
282-
}
283-
284224
/**
285225
* If true, a default {@link OAuth2AuthorizedClient} can be discovered from the
286226
* current Authentication. It is recommended to be cautious with this feature since
@@ -393,27 +333,6 @@ public static Consumer<Map<String, Object>> httpServletResponse(HttpServletRespo
393333
return (attributes) -> attributes.put(HTTP_SERVLET_RESPONSE_ATTR_NAME, response);
394334
}
395335

396-
/**
397-
* An access token will be considered expired by comparing its expiration to now +
398-
* this skewed Duration. The default is 1 minute.
399-
* @param accessTokenExpiresSkew the Duration to use.
400-
* @deprecated The {@code accessTokenExpiresSkew} should be configured with the
401-
* specific {@link OAuth2AuthorizedClientProvider} implementation, e.g.
402-
* {@link ClientCredentialsOAuth2AuthorizedClientProvider#setClockSkew(Duration)
403-
* ClientCredentialsOAuth2AuthorizedClientProvider} or
404-
* {@link RefreshTokenOAuth2AuthorizedClientProvider#setClockSkew(Duration)
405-
* RefreshTokenOAuth2AuthorizedClientProvider}.
406-
*/
407-
@Deprecated
408-
public void setAccessTokenExpiresSkew(Duration accessTokenExpiresSkew) {
409-
Assert.notNull(accessTokenExpiresSkew, "accessTokenExpiresSkew cannot be null");
410-
Assert.state(this.defaultAuthorizedClientManager,
411-
"The accessTokenExpiresSkew cannot be set when the constructor used is \"ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager)\". "
412-
+ "Instead, use the constructor \"ServletOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\".");
413-
this.accessTokenExpiresSkew = accessTokenExpiresSkew;
414-
updateDefaultAuthorizedClientManager();
415-
}
416-
417336
/**
418337
* Sets the {@link OAuth2AuthorizationFailureHandler} that handles authentication and
419338
* authorization failures when communicating to the OAuth 2.0 Resource Server.

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,7 +73,6 @@
7373
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
7474
import org.springframework.security.oauth2.client.RefreshTokenOAuth2AuthorizedClientProvider;
7575
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
76-
import org.springframework.security.oauth2.client.endpoint.DefaultClientCredentialsTokenResponseClient;
7776
import org.springframework.security.oauth2.client.endpoint.DefaultRefreshTokenTokenResponseClient;
7877
import org.springframework.security.oauth2.client.endpoint.JwtBearerGrantRequest;
7978
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
@@ -112,7 +111,6 @@
112111
import static org.assertj.core.api.Assertions.assertThat;
113112
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
114113
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
115-
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
116114
import static org.assertj.core.api.Assertions.entry;
117115
import static org.mockito.ArgumentMatchers.any;
118116
import static org.mockito.ArgumentMatchers.eq;
@@ -220,35 +218,6 @@ public void constructorWhenAuthorizedClientManagerIsNullThenThrowIllegalArgument
220218
.isThrownBy(() -> new ServletOAuth2AuthorizedClientExchangeFilterFunction(null));
221219
}
222220

223-
@Test
224-
public void setClientCredentialsTokenResponseClientWhenClientIsNullThenThrowIllegalArgumentException() {
225-
assertThatIllegalArgumentException()
226-
.isThrownBy(() -> this.function.setClientCredentialsTokenResponseClient(null))
227-
.withMessage("clientCredentialsTokenResponseClient cannot be null");
228-
}
229-
230-
@Test
231-
public void setClientCredentialsTokenResponseClientWhenNotDefaultAuthorizedClientManagerThenThrowIllegalStateException() {
232-
assertThatIllegalStateException()
233-
.isThrownBy(() -> this.function
234-
.setClientCredentialsTokenResponseClient(new DefaultClientCredentialsTokenResponseClient()))
235-
.withMessage("The client cannot be set when the constructor used is "
236-
+ "\"ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager)\". "
237-
+ "Instead, use the constructor \"ServletOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, "
238-
+ "OAuth2AuthorizedClientRepository)\".");
239-
}
240-
241-
@Test
242-
public void setAccessTokenExpiresSkewWhenNotDefaultAuthorizedClientManagerThenThrowIllegalStateException() {
243-
assertThatIllegalStateException()
244-
.isThrownBy(() -> this.function.setAccessTokenExpiresSkew(Duration.ofSeconds(30)))
245-
.isInstanceOf(IllegalStateException.class)
246-
.withMessage("The accessTokenExpiresSkew cannot be set when the constructor used is "
247-
+ "\"ServletOAuth2AuthorizedClientExchangeFilterFunction(OAuth2AuthorizedClientManager)\". "
248-
+ "Instead, use the constructor \"ServletOAuth2AuthorizedClientExchangeFilterFunction(ClientRegistrationRepository, "
249-
+ "OAuth2AuthorizedClientRepository)\".");
250-
}
251-
252221
@Test
253222
public void defaultRequestRequestResponseWhenNullRequestContextThenRequestAndResponseNull() {
254223
Map<String, Object> attrs = getDefaultRequestAttributes();

0 commit comments

Comments
 (0)