Browse Source

Change ResponseType from enum to class

Fixes gh-4292
pull/234/merge
Joe Grandja 9 years ago
parent
commit
4476df93e9
  1. 2
      oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java
  2. 29
      oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java
  3. 2
      samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java

2
oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/authentication/DefaultAuthorizationRequestUriBuilder.java

@ -38,7 +38,7 @@ public class DefaultAuthorizationRequestUriBuilder implements AuthorizationReque @@ -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());
}

29
oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/endpoint/ResponseType.java

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
*/
package org.springframework.security.oauth2.core.endpoint;
import org.springframework.util.Assert;
/**
* The <i>response_type</i> 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; @@ -31,16 +33,33 @@ package org.springframework.security.oauth2.core.endpoint;
* @since 5.0
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-3.1.1">Section 3.1.1 Response Type</a>
*/
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();
}
}

2
samples/boot/oauth2login/src/integration-test/java/org/springframework/security/samples/OAuth2LoginApplicationTests.java

@ -130,7 +130,7 @@ public class OAuth2LoginApplicationTests { @@ -130,7 +130,7 @@ public class OAuth2LoginApplicationTests {
Map<String, String> 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);

Loading…
Cancel
Save