diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistration.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistration.java index 61338dc16d9..3c333622ec0 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistration.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistration.java @@ -264,7 +264,7 @@ protected void setProperties(ClientRegistration clientRegistration) { protected void validateClientWithAuthorizationCodeGrantType() { Assert.isTrue(AuthorizationGrantType.AUTHORIZATION_CODE.equals(this.authorizedGrantType), - "authorizedGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.value()); + "authorizedGrantType must be " + AuthorizationGrantType.AUTHORIZATION_CODE.getValue()); Assert.hasText(this.clientId, "clientId cannot be empty"); Assert.hasText(this.clientSecret, "clientSecret cannot be empty"); Assert.notNull(this.clientAuthenticationMethod, "clientAuthenticationMethod cannot be null"); diff --git a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/AuthorizationGrantType.java b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/AuthorizationGrantType.java index dc36331720d..95b5d5d0f5b 100644 --- a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/AuthorizationGrantType.java +++ b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/AuthorizationGrantType.java @@ -15,6 +15,8 @@ */ package org.springframework.security.oauth2.core; +import org.springframework.util.Assert; + /** * An authorization grant is a credential representing the resource owner's authorization * (to access it's protected resources) to the client and used by the client to obtain an access token. @@ -31,16 +33,33 @@ * @since 5.0 * @see Section 1.3 Authorization Grant */ -public enum AuthorizationGrantType { - AUTHORIZATION_CODE("authorization_code"); - +public final class AuthorizationGrantType { + public static final AuthorizationGrantType AUTHORIZATION_CODE = new AuthorizationGrantType("authorization_code"); private final String value; - AuthorizationGrantType(String value) { + public AuthorizationGrantType(String value) { + Assert.hasText(value, "value cannot be empty"); this.value = value; } - public String value() { + public String getValue() { return this.value; } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || this.getClass() != obj.getClass()) { + return false; + } + AuthorizationGrantType that = (AuthorizationGrantType) obj; + return this.getValue().equals(that.getValue()); + } + + @Override + public int hashCode() { + return this.getValue().hashCode(); + } }