Change AccessToken.TokenType from enum to class

Fixes gh-4293
This commit is contained in:
Joe Grandja 2017-05-30 15:37:33 -04:00
parent 435e389609
commit 336e247e70
2 changed files with 23 additions and 6 deletions

View File

@ -113,7 +113,7 @@ public class NimbusAuthorizationCodeTokenExchanger implements AuthorizationGrant
String accessToken = accessTokenResponse.getTokens().getAccessToken().getValue(); String accessToken = accessTokenResponse.getTokens().getAccessToken().getValue();
AccessToken.TokenType accessTokenType = null; AccessToken.TokenType accessTokenType = null;
if (AccessToken.TokenType.BEARER.value().equals(accessTokenResponse.getTokens().getAccessToken().getType().getValue())) { if (AccessToken.TokenType.BEARER.getValue().equalsIgnoreCase(accessTokenResponse.getTokens().getAccessToken().getType().getValue())) {
accessTokenType = AccessToken.TokenType.BEARER; accessTokenType = AccessToken.TokenType.BEARER;
} }
long expiresIn = accessTokenResponse.getTokens().getAccessToken().getLifetime(); long expiresIn = accessTokenResponse.getTokens().getAccessToken().getLifetime();

View File

@ -40,18 +40,35 @@ public class AccessToken extends AbstractToken {
private final Set<String> scopes; private final Set<String> scopes;
private final Map<String,Object> additionalParameters; private final Map<String,Object> additionalParameters;
public enum TokenType { public static final class TokenType {
BEARER("Bearer"); public static final TokenType BEARER = new TokenType("Bearer");
private final String value; private final String value;
TokenType(String value) { public TokenType(String value) {
Assert.hasText(value, "value cannot be empty");
this.value = value; this.value = value;
} }
public String value() { public String getValue() {
return this.value; return this.value;
} }
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || this.getClass() != obj.getClass()) {
return false;
}
TokenType that = (TokenType) obj;
return this.getValue().equalsIgnoreCase(that.getValue());
}
@Override
public int hashCode() {
return this.getValue().hashCode();
}
} }
public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt) { public AccessToken(TokenType tokenType, String tokenValue, Instant issuedAt, Instant expiresAt) {