1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Change ClientAuthenticationMethod from enum to class

Fixes gh-4313
This commit is contained in:
Joe Grandja
2017-05-30 14:19:28 -04:00
parent e5ceeb4e22
commit 435e389609
6 changed files with 41 additions and 22 deletions
@@ -78,7 +78,7 @@ public class NimbusAuthorizationCodeTokenExchanger implements AuthorizationGrant
ClientID clientId = new ClientID(clientRegistration.getClientId());
Secret clientSecret = new Secret(clientRegistration.getClientSecret());
ClientAuthentication clientAuthentication;
if (ClientAuthenticationMethod.FORM.equals(clientRegistration.getClientAuthenticationMethod())) {
if (ClientAuthenticationMethod.POST.equals(clientRegistration.getClientAuthenticationMethod())) {
clientAuthentication = new ClientSecretPost(clientId, clientSecret);
} else {
clientAuthentication = new ClientSecretBasic(clientId, clientSecret);
@@ -35,7 +35,7 @@ import java.util.Set;
public class ClientRegistration {
private String clientId;
private String clientSecret;
private ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.HEADER;
private ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.BASIC;
private AuthorizationGrantType authorizedGrantType;
private String redirectUri;
private Set<String> scopes = Collections.emptySet();
@@ -154,7 +154,7 @@ public class ClientRegistration {
public static class Builder {
protected String clientId;
protected String clientSecret;
protected ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.HEADER;
protected ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.BASIC;
protected AuthorizationGrantType authorizedGrantType;
protected String redirectUri;
protected Set<String> scopes;
@@ -35,7 +35,7 @@ import java.util.Set;
public class ClientRegistrationProperties {
private String clientId;
private String clientSecret;
private ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.HEADER;
private ClientAuthenticationMethod clientAuthenticationMethod = ClientAuthenticationMethod.BASIC;
private AuthorizationGrantType authorizedGrantType;
private String redirectUri;
private Set<String> scopes;
@@ -15,6 +15,8 @@
*/
package org.springframework.security.oauth2.core;
import org.springframework.util.Assert;
/**
* The available authentication methods used when authenticating the client with the authorization server.
*
@@ -22,17 +24,34 @@ package org.springframework.security.oauth2.core;
* @since 5.0
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-2.3">Section 2.3 Client Authentication</a>
*/
public enum ClientAuthenticationMethod {
HEADER("header"),
FORM("form");
public final class ClientAuthenticationMethod {
public static final ClientAuthenticationMethod BASIC = new ClientAuthenticationMethod("basic");
public static final ClientAuthenticationMethod POST = new ClientAuthenticationMethod("post");
private final String value;
ClientAuthenticationMethod(String value) {
public ClientAuthenticationMethod(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;
}
ClientAuthenticationMethod that = (ClientAuthenticationMethod) obj;
return this.getValue().equalsIgnoreCase(that.getValue());
}
@Override
public int hashCode() {
return this.getValue().hashCode();
}
}