diff --git a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java index 292565cfb4..e9bdabc1d7 100644 --- a/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java +++ b/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java @@ -38,7 +38,7 @@ public class DefaultAuthorizationRequestUriBuilder implements AuthorizationReque public URI build(AuthorizationRequestAttributes authorizationRequestAttributes) { UriComponentsBuilder uriBuilder = UriComponentsBuilder .fromUriString(authorizationRequestAttributes.getAuthorizeUri()) - .queryParam(OAuth2Parameter.RESPONSE_TYPE, ResponseType.CODE.value()); + .queryParam(OAuth2Parameter.RESPONSE_TYPE, ResponseType.CODE.getValue()); if (authorizationRequestAttributes.getRedirectUri() != null) { uriBuilder.queryParam(OAuth2Parameter.REDIRECT_URI, authorizationRequestAttributes.getRedirectUri()); } diff --git a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java index c443682442..6b42212d40 100644 --- a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java +++ b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java @@ -15,6 +15,8 @@ */ package org.springframework.security.oauth2.core.endpoint; +import org.springframework.util.Assert; + /** * The response_type parameter is consumed by the authorization endpoint which * is used by the authorization code grant type and implicit grant type flows. @@ -31,16 +33,33 @@ package org.springframework.security.oauth2.core.endpoint; * @since 5.0 * @see Section 3.1.1 Response Type */ -public enum ResponseType { - CODE("code"); - +public final class ResponseType { + public static final ResponseType CODE = new ResponseType("code"); private final String value; - ResponseType(String value) { + public ResponseType(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; + } + ResponseType that = (ResponseType) obj; + return this.getValue().equals(that.getValue()); + } + + @Override + public int hashCode() { + return this.getValue().hashCode(); + } } diff --git a/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java b/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java index fde0a8d610..07a109a6de 100644 --- a/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java +++ b/samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java @@ -130,7 +130,7 @@ public class OAuth2LoginApplicationTests { Map params = uriComponents.getQueryParams().toSingleValueMap(); - assertThat(params.get(OAuth2Parameter.RESPONSE_TYPE)).isEqualTo(ResponseType.CODE.value()); + assertThat(params.get(OAuth2Parameter.RESPONSE_TYPE)).isEqualTo(ResponseType.CODE.getValue()); assertThat(params.get(OAuth2Parameter.CLIENT_ID)).isEqualTo(this.githubClientRegistration.getClientId()); String redirectUri = AUTHORIZE_BASE_URL + "/" + this.githubClientRegistration.getClientAlias(); assertThat(URLDecoder.decode(params.get(OAuth2Parameter.REDIRECT_URI), "UTF-8")).isEqualTo(redirectUri);