Skip to content

Commit 0859da5

Browse files
committed
Remove deprecations in OAuth2AuthorizedClientArgumentResolver
Closes gh-11584
1 parent 743b6a5 commit 0859da5

File tree

2 files changed

+2
-72
lines changed

2 files changed

+2
-72
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolver.java

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -27,16 +27,11 @@
2727
import org.springframework.security.core.Authentication;
2828
import org.springframework.security.core.authority.AuthorityUtils;
2929
import org.springframework.security.core.context.SecurityContextHolder;
30-
import org.springframework.security.oauth2.client.ClientCredentialsOAuth2AuthorizedClientProvider;
3130
import org.springframework.security.oauth2.client.OAuth2AuthorizeRequest;
3231
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
3332
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager;
34-
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProvider;
35-
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientProviderBuilder;
3633
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
3734
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
38-
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
39-
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest;
4035
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
4136
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
4237
import org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository;
@@ -74,8 +69,6 @@ public final class OAuth2AuthorizedClientArgumentResolver implements HandlerMeth
7469

7570
private OAuth2AuthorizedClientManager authorizedClientManager;
7671

77-
private boolean defaultAuthorizedClientManager;
78-
7972
/**
8073
* Constructs an {@code OAuth2AuthorizedClientArgumentResolver} using the provided
8174
* parameters.
@@ -100,7 +93,6 @@ public OAuth2AuthorizedClientArgumentResolver(ClientRegistrationRepository clien
10093
Assert.notNull(authorizedClientRepository, "authorizedClientRepository cannot be null");
10194
this.authorizedClientManager = new DefaultOAuth2AuthorizedClientManager(clientRegistrationRepository,
10295
authorizedClientRepository);
103-
this.defaultAuthorizedClientManager = true;
10496
}
10597

10698
@Override
@@ -153,46 +145,4 @@ private String resolveClientRegistrationId(MethodParameter parameter) {
153145
return null;
154146
}
155147

156-
/**
157-
* Sets the client used when requesting an access token credential at the Token
158-
* Endpoint for the {@code client_credentials} grant.
159-
* @param clientCredentialsTokenResponseClient the client used when requesting an
160-
* access token credential at the Token Endpoint for the {@code client_credentials}
161-
* grant
162-
* @deprecated Use
163-
* {@link #OAuth2AuthorizedClientArgumentResolver(OAuth2AuthorizedClientManager)}
164-
* instead. Create an instance of
165-
* {@link ClientCredentialsOAuth2AuthorizedClientProvider} configured with a
166-
* {@link ClientCredentialsOAuth2AuthorizedClientProvider#setAccessTokenResponseClient(OAuth2AccessTokenResponseClient)
167-
* DefaultClientCredentialsTokenResponseClient} (or a custom one) and than supply it
168-
* to
169-
* {@link DefaultOAuth2AuthorizedClientManager#setAuthorizedClientProvider(OAuth2AuthorizedClientProvider)
170-
* DefaultOAuth2AuthorizedClientManager}.
171-
*/
172-
@Deprecated
173-
public void setClientCredentialsTokenResponseClient(
174-
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) {
175-
Assert.notNull(clientCredentialsTokenResponseClient, "clientCredentialsTokenResponseClient cannot be null");
176-
Assert.state(this.defaultAuthorizedClientManager,
177-
"The client cannot be set when the constructor used is \"OAuth2AuthorizedClientArgumentResolver(OAuth2AuthorizedClientManager)\". "
178-
+ "Instead, use the constructor \"OAuth2AuthorizedClientArgumentResolver(ClientRegistrationRepository, OAuth2AuthorizedClientRepository)\".");
179-
updateDefaultAuthorizedClientManager(clientCredentialsTokenResponseClient);
180-
}
181-
182-
private void updateDefaultAuthorizedClientManager(
183-
OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient) {
184-
// @formatter:off
185-
OAuth2AuthorizedClientProvider authorizedClientProvider = OAuth2AuthorizedClientProviderBuilder.builder()
186-
.authorizationCode()
187-
.refreshToken()
188-
.clientCredentials((configurer) ->
189-
configurer.accessTokenResponseClient(clientCredentialsTokenResponseClient)
190-
)
191-
.password()
192-
.build();
193-
// @formatter:on
194-
((DefaultOAuth2AuthorizedClientManager) this.authorizedClientManager)
195-
.setAuthorizedClientProvider(authorizedClientProvider);
196-
}
197-
198148
}

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/web/method/annotation/OAuth2AuthorizedClientArgumentResolverTests.java

Lines changed: 1 addition & 21 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.
@@ -42,7 +42,6 @@
4242
import org.springframework.security.oauth2.client.PasswordOAuth2AuthorizedClientProvider;
4343
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient;
4444
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
45-
import org.springframework.security.oauth2.client.endpoint.DefaultClientCredentialsTokenResponseClient;
4645
import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient;
4746
import org.springframework.security.oauth2.client.endpoint.OAuth2ClientCredentialsGrantRequest;
4847
import org.springframework.security.oauth2.client.endpoint.OAuth2PasswordGrantRequest;
@@ -64,7 +63,6 @@
6463
import static org.assertj.core.api.Assertions.assertThat;
6564
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
6665
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
67-
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
6866
import static org.mockito.ArgumentMatchers.any;
6967
import static org.mockito.ArgumentMatchers.anyString;
7068
import static org.mockito.ArgumentMatchers.eq;
@@ -178,24 +176,6 @@ public void constructorWhenAuthorizedClientManagerIsNullThenThrowIllegalArgument
178176
assertThatIllegalArgumentException().isThrownBy(() -> new OAuth2AuthorizedClientArgumentResolver(null));
179177
}
180178

181-
@Test
182-
public void setClientCredentialsTokenResponseClientWhenClientIsNullThenThrowIllegalArgumentException() {
183-
assertThatIllegalArgumentException()
184-
.isThrownBy(() -> this.argumentResolver.setClientCredentialsTokenResponseClient(null))
185-
.withMessage("clientCredentialsTokenResponseClient cannot be null");
186-
}
187-
188-
@Test
189-
public void setClientCredentialsTokenResponseClientWhenNotDefaultAuthorizedClientManagerThenThrowIllegalStateException() {
190-
assertThatIllegalStateException()
191-
.isThrownBy(() -> this.argumentResolver
192-
.setClientCredentialsTokenResponseClient(new DefaultClientCredentialsTokenResponseClient()))
193-
.withMessage("The client cannot be set when the constructor used is "
194-
+ "\"OAuth2AuthorizedClientArgumentResolver(OAuth2AuthorizedClientManager)\". "
195-
+ "Instead, use the constructor \"OAuth2AuthorizedClientArgumentResolver(ClientRegistrationRepository, "
196-
+ "OAuth2AuthorizedClientRepository)\".");
197-
}
198-
199179
@Test
200180
public void supportsParameterWhenParameterTypeOAuth2AuthorizedClientThenTrue() {
201181
MethodParameter methodParameter = this.getMethodParameter("paramTypeAuthorizedClient",

0 commit comments

Comments
 (0)