Skip to content

Commit 2915a70

Browse files
author
Steve Riesenberg
committed
Merge branch '5.6.x' into 5.7.x
2 parents aed7a86 + 6530777 commit 2915a70

19 files changed

+369
-142
lines changed

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/AbstractWebClientReactiveOAuth2AccessTokenResponseClient.java

Lines changed: 2 additions & 2 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.
@@ -214,7 +214,7 @@ BodyInserters.FormInserter<String> populateTokenRequestBody(T grantRequest,
214214
* no scopes.
215215
*/
216216
Set<String> defaultScopes(T grantRequest) {
217-
return scopes(grantRequest);
217+
return Collections.emptySet();
218218
}
219219

220220
/**

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/DefaultAuthorizationCodeTokenResponseClient.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 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.
@@ -30,7 +30,6 @@
3030
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
3131
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
3232
import org.springframework.util.Assert;
33-
import org.springframework.util.CollectionUtils;
3433
import org.springframework.web.client.ResponseErrorHandler;
3534
import org.springframework.web.client.RestClientException;
3635
import org.springframework.web.client.RestOperations;
@@ -76,19 +75,12 @@ public OAuth2AccessTokenResponse getTokenResponse(
7675
Assert.notNull(authorizationCodeGrantRequest, "authorizationCodeGrantRequest cannot be null");
7776
RequestEntity<?> request = this.requestEntityConverter.convert(authorizationCodeGrantRequest);
7877
ResponseEntity<OAuth2AccessTokenResponse> response = getResponse(request);
79-
OAuth2AccessTokenResponse tokenResponse = response.getBody();
80-
if (CollectionUtils.isEmpty(tokenResponse.getAccessToken().getScopes())) {
81-
// As per spec, in Section 5.1 Successful Access Token Response
82-
// https://tools.ietf.org/html/rfc6749#section-5.1
83-
// If AccessTokenResponse.scope is empty, then default to the scope
84-
// originally requested by the client in the Token Request
85-
// @formatter:off
86-
tokenResponse = OAuth2AccessTokenResponse.withResponse(tokenResponse)
87-
.scopes(authorizationCodeGrantRequest.getClientRegistration().getScopes())
88-
.build();
89-
// @formatter:on
90-
}
91-
return tokenResponse;
78+
// As per spec, in Section 5.1 Successful Access Token Response
79+
// https://tools.ietf.org/html/rfc6749#section-5.1
80+
// If AccessTokenResponse.scope is empty, then we assume all requested scopes were
81+
// granted.
82+
// However, we use the explicit scopes returned in the response (if any).
83+
return response.getBody();
9284
}
9385

9486
private ResponseEntity<OAuth2AccessTokenResponse> getResponse(RequestEntity<?> request) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/DefaultClientCredentialsTokenResponseClient.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 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.
@@ -30,7 +30,6 @@
3030
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
3131
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
3232
import org.springframework.util.Assert;
33-
import org.springframework.util.CollectionUtils;
3433
import org.springframework.web.client.ResponseErrorHandler;
3534
import org.springframework.web.client.RestClientException;
3635
import org.springframework.web.client.RestOperations;
@@ -76,19 +75,12 @@ public OAuth2AccessTokenResponse getTokenResponse(
7675
Assert.notNull(clientCredentialsGrantRequest, "clientCredentialsGrantRequest cannot be null");
7776
RequestEntity<?> request = this.requestEntityConverter.convert(clientCredentialsGrantRequest);
7877
ResponseEntity<OAuth2AccessTokenResponse> response = getResponse(request);
79-
OAuth2AccessTokenResponse tokenResponse = response.getBody();
80-
if (CollectionUtils.isEmpty(tokenResponse.getAccessToken().getScopes())) {
81-
// As per spec, in Section 5.1 Successful Access Token Response
82-
// https://tools.ietf.org/html/rfc6749#section-5.1
83-
// If AccessTokenResponse.scope is empty, then default to the scope
84-
// originally requested by the client in the Token Request
85-
// @formatter:off
86-
tokenResponse = OAuth2AccessTokenResponse.withResponse(tokenResponse)
87-
.scopes(clientCredentialsGrantRequest.getClientRegistration().getScopes())
88-
.build();
89-
// @formatter:on
90-
}
91-
return tokenResponse;
78+
// As per spec, in Section 5.1 Successful Access Token Response
79+
// https://tools.ietf.org/html/rfc6749#section-5.1
80+
// If AccessTokenResponse.scope is empty, then we assume all requested scopes were
81+
// granted.
82+
// However, we use the explicit scopes returned in the response (if any).
83+
return response.getBody();
9284
}
9385

9486
private ResponseEntity<OAuth2AccessTokenResponse> getResponse(RequestEntity<?> request) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/DefaultJwtBearerTokenResponseClient.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
3131
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
3232
import org.springframework.util.Assert;
33-
import org.springframework.util.CollectionUtils;
3433
import org.springframework.web.client.ResponseErrorHandler;
3534
import org.springframework.web.client.RestClientException;
3635
import org.springframework.web.client.RestOperations;
@@ -73,19 +72,12 @@ public OAuth2AccessTokenResponse getTokenResponse(JwtBearerGrantRequest jwtBeare
7372
Assert.notNull(jwtBearerGrantRequest, "jwtBearerGrantRequest cannot be null");
7473
RequestEntity<?> request = this.requestEntityConverter.convert(jwtBearerGrantRequest);
7574
ResponseEntity<OAuth2AccessTokenResponse> response = getResponse(request);
76-
OAuth2AccessTokenResponse tokenResponse = response.getBody();
77-
if (CollectionUtils.isEmpty(tokenResponse.getAccessToken().getScopes())) {
78-
// As per spec, in Section 5.1 Successful Access Token Response
79-
// https://tools.ietf.org/html/rfc6749#section-5.1
80-
// If AccessTokenResponse.scope is empty, then default to the scope
81-
// originally requested by the client in the Token Request
82-
// @formatter:off
83-
tokenResponse = OAuth2AccessTokenResponse.withResponse(tokenResponse)
84-
.scopes(jwtBearerGrantRequest.getClientRegistration().getScopes())
85-
.build();
86-
// @formatter:on
87-
}
88-
return tokenResponse;
75+
// As per spec, in Section 5.1 Successful Access Token Response
76+
// https://tools.ietf.org/html/rfc6749#section-5.1
77+
// If AccessTokenResponse.scope is empty, then we assume all requested scopes were
78+
// granted.
79+
// However, we use the explicit scopes returned in the response (if any).
80+
return response.getBody();
8981
}
9082

9183
private ResponseEntity<OAuth2AccessTokenResponse> getResponse(RequestEntity<?> request) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/DefaultPasswordTokenResponseClient.java

Lines changed: 7 additions & 12 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.
@@ -30,7 +30,6 @@
3030
import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse;
3131
import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter;
3232
import org.springframework.util.Assert;
33-
import org.springframework.util.CollectionUtils;
3433
import org.springframework.web.client.ResponseErrorHandler;
3534
import org.springframework.web.client.RestClientException;
3635
import org.springframework.web.client.RestOperations;
@@ -75,16 +74,12 @@ public OAuth2AccessTokenResponse getTokenResponse(OAuth2PasswordGrantRequest pas
7574
Assert.notNull(passwordGrantRequest, "passwordGrantRequest cannot be null");
7675
RequestEntity<?> request = this.requestEntityConverter.convert(passwordGrantRequest);
7776
ResponseEntity<OAuth2AccessTokenResponse> response = getResponse(request);
78-
OAuth2AccessTokenResponse tokenResponse = response.getBody();
79-
if (CollectionUtils.isEmpty(tokenResponse.getAccessToken().getScopes())) {
80-
// As per spec, in Section 5.1 Successful Access Token Response
81-
// https://tools.ietf.org/html/rfc6749#section-5.1
82-
// If AccessTokenResponse.scope is empty, then default to the scope
83-
// originally requested by the client in the Token Request
84-
tokenResponse = OAuth2AccessTokenResponse.withResponse(tokenResponse)
85-
.scopes(passwordGrantRequest.getClientRegistration().getScopes()).build();
86-
}
87-
return tokenResponse;
77+
// As per spec, in Section 5.1 Successful Access Token Response
78+
// https://tools.ietf.org/html/rfc6749#section-5.1
79+
// If AccessTokenResponse.scope is empty, then we assume all requested scopes were
80+
// granted.
81+
// However, we use the explicit scopes returned in the response (if any).
82+
return response.getBody();
8883
}
8984

9085
private ResponseEntity<OAuth2AccessTokenResponse> getResponse(RequestEntity<?> request) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveAuthorizationCodeTokenResponseClient.java

Lines changed: 1 addition & 6 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.
@@ -65,11 +65,6 @@ Set<String> scopes(OAuth2AuthorizationCodeGrantRequest grantRequest) {
6565
return Collections.emptySet();
6666
}
6767

68-
@Override
69-
Set<String> defaultScopes(OAuth2AuthorizationCodeGrantRequest grantRequest) {
70-
return grantRequest.getAuthorizationExchange().getAuthorizationRequest().getScopes();
71-
}
72-
7368
@Override
7469
BodyInserters.FormInserter<String> populateTokenRequestBody(OAuth2AuthorizationCodeGrantRequest grantRequest,
7570
BodyInserters.FormInserter<String> body) {

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/WebClientReactiveClientCredentialsTokenResponseClient.java

Lines changed: 1 addition & 1 deletion
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.

oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/endpoint/WebClientReactivePasswordTokenResponseClient.java

Lines changed: 1 addition & 1 deletion
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.

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/DefaultAuthorizationCodeTokenResponseClientTests.java

Lines changed: 3 additions & 3 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.
@@ -295,7 +295,7 @@ public void getTokenResponseWhenSuccessResponseIncludesScopeThenAccessTokenHasRe
295295
}
296296

297297
@Test
298-
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessTokenHasDefaultScope() {
298+
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessTokenHasNoScope() {
299299
// @formatter:off
300300
String accessTokenSuccessResponse = "{\n"
301301
+ " \"access_token\": \"access-token-1234\",\n"
@@ -307,7 +307,7 @@ public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessToke
307307
this.server.enqueue(jsonResponse(accessTokenSuccessResponse));
308308
OAuth2AccessTokenResponse accessTokenResponse = this.tokenResponseClient
309309
.getTokenResponse(authorizationCodeGrantRequest(this.clientRegistration.build()));
310-
assertThat(accessTokenResponse.getAccessToken().getScopes()).containsExactly("read", "write");
310+
assertThat(accessTokenResponse.getAccessToken().getScopes()).isEmpty();
311311
}
312312

313313
@Test

oauth2/oauth2-client/src/test/java/org/springframework/security/oauth2/client/endpoint/DefaultClientCredentialsTokenResponseClientTests.java

Lines changed: 3 additions & 3 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.
@@ -304,7 +304,7 @@ public void getTokenResponseWhenSuccessResponseIncludesScopeThenAccessTokenHasRe
304304
}
305305

306306
@Test
307-
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessTokenHasDefaultScope() {
307+
public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessTokenHasNoScope() {
308308
// @formatter:off
309309
String accessTokenSuccessResponse = "{\n"
310310
+ " \"access_token\": \"access-token-1234\",\n"
@@ -317,7 +317,7 @@ public void getTokenResponseWhenSuccessResponseDoesNotIncludeScopeThenAccessToke
317317
this.clientRegistration.build());
318318
OAuth2AccessTokenResponse accessTokenResponse = this.tokenResponseClient
319319
.getTokenResponse(clientCredentialsGrantRequest);
320-
assertThat(accessTokenResponse.getAccessToken().getScopes()).containsExactly("read", "write");
320+
assertThat(accessTokenResponse.getAccessToken().getScopes()).isEmpty();
321321
}
322322

323323
@Test

0 commit comments

Comments
 (0)