Change AuthorizationGrantType from enum to class

Fixes gh-4291
This commit is contained in:
Joe Grandja 2017-05-30 16:22:53 -04:00
parent 4476df93e9
commit 545339c663
2 changed files with 25 additions and 6 deletions

View File

@ -264,7 +264,7 @@ public class 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");

View File

@ -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 @@ package org.springframework.security.oauth2.core;
* @since 5.0
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-1.3">Section 1.3 Authorization Grant</a>
*/
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();
}
}