Rename scopes -> scope

This commit is contained in:
Joe Grandja
2017-10-02 15:50:16 -04:00
parent fb57111ecd
commit 0d516ca32c
9 changed files with 34 additions and 34 deletions

View File

@@ -120,7 +120,7 @@ public class AuthorizationCodeAuthenticationProvider implements AuthenticationPr
AccessToken accessToken = new AccessToken(tokenResponse.getTokenType(),
tokenResponse.getTokenValue(), tokenResponse.getIssuedAt(),
tokenResponse.getExpiresAt(), tokenResponse.getScopes());
tokenResponse.getExpiresAt(), tokenResponse.getScope());
IdToken idToken = null;
if (tokenResponse.getAdditionalParameters().containsKey(OidcParameter.ID_TOKEN)) {

View File

@@ -74,13 +74,13 @@ public class OAuth2ClientAuthenticationToken extends AbstractAuthenticationToken
return this.accessToken;
}
public Set<String> getAuthorizedScopes() {
public Set<String> getAuthorizedScope() {
// As per spec, in section 5.1 Successful Access Token Response
// https://tools.ietf.org/html/rfc6749#section-5.1
// If AccessToken.scopes is empty, then default to the scopes
// If AccessToken.scope is empty, then default to the scope
// originally requested by the client in the Authorization Request
return (!CollectionUtils.isEmpty(this.getAccessToken().getScopes()) ?
this.getAccessToken().getScopes() :
return (!CollectionUtils.isEmpty(this.getAccessToken().getScope()) ?
this.getAccessToken().getScope() :
this.getClientRegistration().getScope());
}
}

View File

@@ -127,9 +127,9 @@ public class NimbusAuthorizationCodeTokenExchanger implements AuthorizationGrant
accessTokenType = AccessToken.TokenType.BEARER;
}
long expiresIn = accessTokenResponse.getTokens().getAccessToken().getLifetime();
Set<String> scopes = Collections.emptySet();
Set<String> scope = Collections.emptySet();
if (!CollectionUtils.isEmpty(accessTokenResponse.getTokens().getAccessToken().getScope())) {
scopes = new HashSet<>(accessTokenResponse.getTokens().getAccessToken().getScope().toStringList());
scope = new HashSet<>(accessTokenResponse.getTokens().getAccessToken().getScope().toStringList());
}
Map<String, Object> additionalParameters = accessTokenResponse.getCustomParameters().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
@@ -137,7 +137,7 @@ public class NimbusAuthorizationCodeTokenExchanger implements AuthorizationGrant
return TokenResponseAttributes.withToken(accessToken)
.tokenType(accessTokenType)
.expiresIn(expiresIn)
.scopes(scopes)
.scope(scope)
.additionalParameters(additionalParameters)
.build();
}

View File

@@ -103,7 +103,7 @@ public class OidcUserService implements OAuth2UserService {
oidcClientAuthentication.getClientRegistration().getAuthorizationGrantType())) {
// Return true if there is at least one match between the authorized scope(s) and UserInfo scope(s)
return oidcClientAuthentication.getAuthorizedScopes().stream().anyMatch(userInfoScopes::contains);
return oidcClientAuthentication.getAuthorizedScope().stream().anyMatch(userInfoScopes::contains);
}
return false;

View File

@@ -36,7 +36,7 @@ import java.util.Set;
*/
public class AccessToken extends SecurityToken {
private final TokenType tokenType;
private final Set<String> scopes;
private final Set<String> scope;
public static final class TokenType {
public static final TokenType BEARER = new TokenType("Bearer");
@@ -73,19 +73,19 @@ public class AccessToken extends SecurityToken {
this(tokenType, tokenValue, issuedAt, expiresAt, Collections.emptySet());
}
public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt, Set<String> scopes) {
public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt, Set<String> scope) {
super(tokenValue, issuedAt, expiresAt);
Assert.notNull(tokenType, "tokenType cannot be null");
this.tokenType = tokenType;
this.scopes = Collections.unmodifiableSet(
scopes != null ? scopes : Collections.emptySet());
this.scope = Collections.unmodifiableSet(
scope != null ? scope : Collections.emptySet());
}
public TokenType getTokenType() {
return this.tokenType;
}
public Set<String> getScopes() {
return this.scopes;
public Set<String> getScope() {
return this.scope;
}
}

View File

@@ -54,8 +54,8 @@ public final class TokenResponseAttributes {
return this.accessToken.getExpiresAt();
}
public Set<String> getScopes() {
return this.accessToken.getScopes();
public Set<String> getScope() {
return this.accessToken.getScope();
}
public Map<String, Object> getAdditionalParameters() {
@@ -70,7 +70,7 @@ public final class TokenResponseAttributes {
private String tokenValue;
private AccessToken.TokenType tokenType;
private long expiresIn;
private Set<String> scopes;
private Set<String> scope;
private Map<String,Object> additionalParameters;
private Builder(String tokenValue) {
@@ -87,8 +87,8 @@ public final class TokenResponseAttributes {
return this;
}
public Builder scopes(Set<String> scopes) {
this.scopes = scopes;
public Builder scope(Set<String> scope) {
this.scope = scope;
return this;
}
@@ -101,7 +101,7 @@ public final class TokenResponseAttributes {
Assert.isTrue(this.expiresIn >= 0, "expiresIn must be a positive number");
Instant issuedAt = Instant.now();
AccessToken accessToken = new AccessToken(this.tokenType, this.tokenValue, issuedAt,
issuedAt.plusSeconds(this.expiresIn), this.scopes);
issuedAt.plusSeconds(this.expiresIn), this.scope);
TokenResponseAttributes tokenResponse = new TokenResponseAttributes();
tokenResponse.accessToken = accessToken;
tokenResponse.additionalParameters = Collections.unmodifiableMap(

View File

@@ -36,7 +36,7 @@ public class TokenResponseAttributesTest {
TokenResponseAttributes.withToken(null)
.expiresIn(EXPIRES_IN)
.additionalParameters(Collections.emptyMap())
.scopes(Collections.emptySet())
.scope(Collections.emptySet())
.tokenType(AccessToken.TokenType.BEARER)
.build();
}
@@ -46,7 +46,7 @@ public class TokenResponseAttributesTest {
TokenResponseAttributes.withToken(TOKEN)
.expiresIn(INVALID_EXPIRES_IN)
.additionalParameters(Collections.emptyMap())
.scopes(Collections.emptySet())
.scope(Collections.emptySet())
.tokenType(AccessToken.TokenType.BEARER)
.build();
}