Skip to content

Commit

Permalink
Change AuthorizationGrantType from enum to class
Browse files Browse the repository at this point in the history
Fixes gh-4291
  • Loading branch information
jgrandja committed May 30, 2017
1 parent 4476df9 commit 545339c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -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");
Expand Down
Expand Up @@ -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.
Expand All @@ -31,16 +33,33 @@
* @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();
}
}

0 comments on commit 545339c

Please sign in to comment.