Skip to content

Commit c8cc971

Browse files
committed
Fix package tangles
Issue #7699 #7840
1 parent f2da2c5 commit c8cc971

File tree

28 files changed

+233
-466
lines changed

28 files changed

+233
-466
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/AuthorizedClientServiceOAuth2AuthorizedClientManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2121
import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository;
2222
import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizedClientManager;
23-
import org.springframework.security.oauth2.client.web.RemoveAuthorizedClientOAuth2AuthorizationFailureHandler;
24-
import org.springframework.security.oauth2.client.web.SaveAuthorizedClientOAuth2AuthorizationSuccessHandler;
2523
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2624
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
2725
import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames;
@@ -94,8 +92,11 @@ public AuthorizedClientServiceOAuth2AuthorizedClientManager(ClientRegistrationRe
9492
this.clientRegistrationRepository = clientRegistrationRepository;
9593
this.authorizedClientService = authorizedClientService;
9694
this.contextAttributesMapper = new DefaultContextAttributesMapper();
97-
this.authorizationSuccessHandler = new SaveAuthorizedClientOAuth2AuthorizationSuccessHandler(authorizedClientService);
98-
this.authorizationFailureHandler = new RemoveAuthorizedClientOAuth2AuthorizationFailureHandler(authorizedClientService);
95+
this.authorizationSuccessHandler = (authorizedClient, principal, attributes) ->
96+
authorizedClientService.saveAuthorizedClient(authorizedClient, principal);
97+
this.authorizationFailureHandler = new RemoveAuthorizedClientOAuth2AuthorizationFailureHandler(
98+
(clientRegistrationId, principal, attributes) ->
99+
authorizedClientService.removeAuthorizedClient(clientRegistrationId, principal.getName()));
99100
}
100101

101102
@Nullable
@@ -177,10 +178,9 @@ public void setContextAttributesMapper(Function<OAuth2AuthorizeRequest, Map<Stri
177178
* Sets the {@link OAuth2AuthorizationSuccessHandler} that handles successful authorizations.
178179
*
179180
* <p>
180-
* A {@link SaveAuthorizedClientOAuth2AuthorizationSuccessHandler} is used by default.
181+
* The default saves {@link OAuth2AuthorizedClient}s in the {@link OAuth2AuthorizedClientService}.
181182
*
182183
* @param authorizationSuccessHandler the {@link OAuth2AuthorizationSuccessHandler} that handles successful authorizations
183-
* @see SaveAuthorizedClientOAuth2AuthorizationSuccessHandler
184184
* @since 5.3
185185
*/
186186
public void setAuthorizationSuccessHandler(OAuth2AuthorizationSuccessHandler authorizationSuccessHandler) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import org.springframework.security.core.Authentication;
1919
import org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository;
2020
import org.springframework.security.oauth2.client.web.DefaultReactiveOAuth2AuthorizedClientManager;
21-
import org.springframework.security.oauth2.client.web.RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler;
22-
import org.springframework.security.oauth2.client.web.SaveAuthorizedClientReactiveOAuth2AuthorizationSuccessHandler;
2321
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2422
import org.springframework.util.Assert;
2523
import org.springframework.web.server.ServerWebExchange;
@@ -91,8 +89,11 @@ public AuthorizedClientServiceReactiveOAuth2AuthorizedClientManager(
9189
Assert.notNull(authorizedClientService, "authorizedClientService cannot be null");
9290
this.clientRegistrationRepository = clientRegistrationRepository;
9391
this.authorizedClientService = authorizedClientService;
94-
this.authorizationSuccessHandler = new SaveAuthorizedClientReactiveOAuth2AuthorizationSuccessHandler(authorizedClientService);
95-
this.authorizationFailureHandler = new RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler(authorizedClientService);
92+
this.authorizationSuccessHandler = (authorizedClient, principal, attributes) ->
93+
authorizedClientService.saveAuthorizedClient(authorizedClient, principal);
94+
this.authorizationFailureHandler = new RemoveAuthorizedClientReactiveOAuth2AuthorizationFailureHandler(
95+
(clientRegistrationId, principal, attributes) ->
96+
this.authorizedClientService.removeAuthorizedClient(clientRegistrationId, principal.getName()));
9697
}
9798

9899
@Override
@@ -179,11 +180,9 @@ public void setContextAttributesMapper(Function<OAuth2AuthorizeRequest, Mono<Map
179180
/**
180181
* Sets the handler that handles successful authorizations.
181182
*
182-
* <p>A {@link SaveAuthorizedClientReactiveOAuth2AuthorizationSuccessHandler}
183-
* is used by default.</p>
183+
* The default saves {@link OAuth2AuthorizedClient}s in the {@link ReactiveOAuth2AuthorizedClientService}.
184184
*
185185
* @param authorizationSuccessHandler the handler that handles successful authorizations.
186-
* @see SaveAuthorizedClientReactiveOAuth2AuthorizationSuccessHandler
187186
* @since 5.3
188187
*/
189188
public void setAuthorizationSuccessHandler(ReactiveOAuth2AuthorizationSuccessHandler authorizationSuccessHandler) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/ClientCredentialsOAuth2AuthorizedClientProvider.java

Lines changed: 9 additions & 3 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-2020 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.
@@ -22,6 +22,7 @@
2222
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2323
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2424
import org.springframework.security.oauth2.core.AuthorizationGrantType;
25+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2526
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
2627
import org.springframework.util.Assert;
2728

@@ -79,8 +80,13 @@ public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
7980

8081
OAuth2ClientCredentialsGrantRequest clientCredentialsGrantRequest =
8182
new OAuth2ClientCredentialsGrantRequest(clientRegistration);
82-
OAuth2AccessTokenResponse tokenResponse =
83-
this.accessTokenResponseClient.getTokenResponse(clientCredentialsGrantRequest);
83+
84+
OAuth2AccessTokenResponse tokenResponse;
85+
try {
86+
tokenResponse = this.accessTokenResponseClient.getTokenResponse(clientCredentialsGrantRequest);
87+
} catch (OAuth2AuthorizationException ex) {
88+
throw new ClientAuthorizationException(ex.getError(), clientRegistration.getRegistrationId(), ex);
89+
}
8490

8591
return new OAuth2AuthorizedClient(clientRegistration, context.getPrincipal().getName(), tokenResponse.getAccessToken());
8692
}

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/ClientCredentialsReactiveOAuth2AuthorizedClientProvider.java

Lines changed: 4 additions & 1 deletion
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-2020 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2222
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2323
import org.springframework.security.oauth2.core.AuthorizationGrantType;
24+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2425
import org.springframework.util.Assert;
2526
import reactor.core.publisher.Mono;
2627

@@ -77,6 +78,8 @@ public Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizationContext context
7778

7879
return Mono.just(new OAuth2ClientCredentialsGrantRequest(clientRegistration))
7980
.flatMap(this.accessTokenResponseClient::getTokenResponse)
81+
.onErrorMap(OAuth2AuthorizationException.class,
82+
e -> new ClientAuthorizationException(e.getError(), clientRegistration.getRegistrationId(), e))
8083
.map(tokenResponse -> new OAuth2AuthorizedClient(
8184
clientRegistration, context.getPrincipal().getName(), tokenResponse.getAccessToken()));
8285
}

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/PasswordOAuth2AuthorizedClientProvider.java

Lines changed: 9 additions & 3 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-2020 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.
@@ -22,6 +22,7 @@
2222
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2323
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2424
import org.springframework.security.oauth2.core.AuthorizationGrantType;
25+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2526
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
2627
import org.springframework.util.Assert;
2728
import org.springframework.util.StringUtils;
@@ -96,8 +97,13 @@ public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
9697

9798
OAuth2PasswordGrantRequest passwordGrantRequest =
9899
new OAuth2PasswordGrantRequest(clientRegistration, username, password);
99-
OAuth2AccessTokenResponse tokenResponse =
100-
this.accessTokenResponseClient.getTokenResponse(passwordGrantRequest);
100+
101+
OAuth2AccessTokenResponse tokenResponse;
102+
try {
103+
tokenResponse = this.accessTokenResponseClient.getTokenResponse(passwordGrantRequest);
104+
} catch (OAuth2AuthorizationException ex) {
105+
throw new ClientAuthorizationException(ex.getError(), clientRegistration.getRegistrationId(), ex);
106+
}
101107

102108
return new OAuth2AuthorizedClient(clientRegistration, context.getPrincipal().getName(),
103109
tokenResponse.getAccessToken(), tokenResponse.getRefreshToken());

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/PasswordReactiveOAuth2AuthorizedClientProvider.java

Lines changed: 4 additions & 1 deletion
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-2020 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2222
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2323
import org.springframework.security.oauth2.core.AuthorizationGrantType;
24+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2425
import org.springframework.util.Assert;
2526
import org.springframework.util.StringUtils;
2627
import reactor.core.publisher.Mono;
@@ -97,6 +98,8 @@ public Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizationContext context
9798

9899
return Mono.just(passwordGrantRequest)
99100
.flatMap(this.accessTokenResponseClient::getTokenResponse)
101+
.onErrorMap(OAuth2AuthorizationException.class,
102+
e -> new ClientAuthorizationException(e.getError(), clientRegistration.getRegistrationId(), e))
100103
.map(tokenResponse -> new OAuth2AuthorizedClient(clientRegistration, context.getPrincipal().getName(),
101104
tokenResponse.getAccessToken(), tokenResponse.getRefreshToken()));
102105
}

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/RefreshTokenOAuth2AuthorizedClientProvider.java

Lines changed: 9 additions & 3 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-2020 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.security.oauth2.client.endpoint.OAuth2RefreshTokenGrantRequest;
2222
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2323
import org.springframework.security.oauth2.core.AuthorizationGrantType;
24+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2425
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
2526
import org.springframework.util.Assert;
2627

@@ -86,8 +87,13 @@ public OAuth2AuthorizedClient authorize(OAuth2AuthorizationContext context) {
8687
OAuth2RefreshTokenGrantRequest refreshTokenGrantRequest = new OAuth2RefreshTokenGrantRequest(
8788
authorizedClient.getClientRegistration(), authorizedClient.getAccessToken(),
8889
authorizedClient.getRefreshToken(), scopes);
89-
OAuth2AccessTokenResponse tokenResponse =
90-
this.accessTokenResponseClient.getTokenResponse(refreshTokenGrantRequest);
90+
91+
OAuth2AccessTokenResponse tokenResponse;
92+
try {
93+
tokenResponse = this.accessTokenResponseClient.getTokenResponse(refreshTokenGrantRequest);
94+
} catch (OAuth2AuthorizationException ex) {
95+
throw new ClientAuthorizationException(ex.getError(), authorizedClient.getClientRegistration().getRegistrationId(), ex);
96+
}
9197

9298
return new OAuth2AuthorizedClient(context.getAuthorizedClient().getClientRegistration(),
9399
context.getPrincipal().getName(), tokenResponse.getAccessToken(), tokenResponse.getRefreshToken());

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/RefreshTokenReactiveOAuth2AuthorizedClientProvider.java

Lines changed: 4 additions & 1 deletion
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-2020 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.security.oauth2.client.registration.ClientRegistration;
2222
import org.springframework.security.oauth2.core.AbstractOAuth2Token;
2323
import org.springframework.security.oauth2.core.AuthorizationGrantType;
24+
import org.springframework.security.oauth2.core.OAuth2AuthorizationException;
2425
import org.springframework.util.Assert;
2526
import reactor.core.publisher.Mono;
2627

@@ -88,6 +89,8 @@ public Mono<OAuth2AuthorizedClient> authorize(OAuth2AuthorizationContext context
8889

8990
return Mono.just(refreshTokenGrantRequest)
9091
.flatMap(this.accessTokenResponseClient::getTokenResponse)
92+
.onErrorMap(OAuth2AuthorizationException.class,
93+
e -> new ClientAuthorizationException(e.getError(), clientRegistration.getRegistrationId(), e))
9194
.map(tokenResponse -> new OAuth2AuthorizedClient(clientRegistration, context.getPrincipal().getName(),
9295
tokenResponse.getAccessToken(), tokenResponse.getRefreshToken()));
9396
}

0 commit comments

Comments
 (0)