Browse Source
* Remove ErrorResponseAttributes * Rename AuthorizationRequestAttributes -> AuthorizationRequest * Remove AuthorizationCodeTokenRequestAttributes * Rename TokenResponseAttributes -> TokenResponse Issue gh-4593pull/4623/head
26 changed files with 131 additions and 461 deletions
@ -1,56 +0,0 @@
@@ -1,56 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.client.web.converter; |
||||
|
||||
import org.springframework.security.oauth2.core.endpoint.ErrorResponseAttributes; |
||||
import org.springframework.security.oauth2.core.endpoint.OAuth2Parameter; |
||||
import org.springframework.util.StringUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.function.Function; |
||||
|
||||
/** |
||||
* A <code>Function</code> that converts an <i>OAuth 2.0 Error Response</i> |
||||
* (in the form of a {@link HttpServletRequest}) to a {@link ErrorResponseAttributes}. |
||||
* |
||||
* @author Joe Grandja |
||||
* @since 5.0 |
||||
* @see ErrorResponseAttributes |
||||
*/ |
||||
public final class ErrorResponseAttributesConverter implements Function<HttpServletRequest, ErrorResponseAttributes> { |
||||
|
||||
@Override |
||||
public ErrorResponseAttributes apply(HttpServletRequest request) { |
||||
ErrorResponseAttributes response; |
||||
|
||||
String errorCode = request.getParameter(OAuth2Parameter.ERROR); |
||||
if (!StringUtils.hasText(errorCode)) { |
||||
return null; |
||||
} |
||||
|
||||
String description = request.getParameter(OAuth2Parameter.ERROR_DESCRIPTION); |
||||
String uri = request.getParameter(OAuth2Parameter.ERROR_URI); |
||||
String state = request.getParameter(OAuth2Parameter.STATE); |
||||
|
||||
response = ErrorResponseAttributes.withErrorCode(errorCode) |
||||
.description(description) |
||||
.uri(uri) |
||||
.state(state) |
||||
.build(); |
||||
|
||||
return response; |
||||
} |
||||
} |
||||
@ -1,76 +0,0 @@
@@ -1,76 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* A representation of an <i>OAuth 2.0 Access Token Request</i> for the authorization code grant type. |
||||
* |
||||
* @author Joe Grandja |
||||
* @since 5.0 |
||||
* @see <a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.3">Section 4.1.3 Access Token Request</a> |
||||
*/ |
||||
public final class AuthorizationCodeTokenRequestAttributes { |
||||
private String code; |
||||
private String clientId; |
||||
private String redirectUri; |
||||
|
||||
private AuthorizationCodeTokenRequestAttributes() { |
||||
} |
||||
|
||||
public String getCode() { |
||||
return this.code; |
||||
} |
||||
|
||||
public String getClientId() { |
||||
return this.clientId; |
||||
} |
||||
|
||||
public String getRedirectUri() { |
||||
return this.redirectUri; |
||||
} |
||||
|
||||
public static Builder withCode(String code) { |
||||
return new Builder(code); |
||||
} |
||||
|
||||
public static class Builder { |
||||
private final AuthorizationCodeTokenRequestAttributes authorizationCodeTokenRequest; |
||||
|
||||
private Builder(String code) { |
||||
Assert.hasText(code, "code cannot be empty"); |
||||
this.authorizationCodeTokenRequest = new AuthorizationCodeTokenRequestAttributes(); |
||||
this.authorizationCodeTokenRequest.code = code; |
||||
} |
||||
|
||||
public Builder clientId(String clientId) { |
||||
this.authorizationCodeTokenRequest.clientId = clientId; |
||||
return this; |
||||
} |
||||
|
||||
public Builder redirectUri(String redirectUri) { |
||||
this.authorizationCodeTokenRequest.redirectUri = redirectUri; |
||||
return this; |
||||
} |
||||
|
||||
public AuthorizationCodeTokenRequestAttributes build() { |
||||
Assert.hasText(this.authorizationCodeTokenRequest.clientId, "clientId cannot be empty"); |
||||
Assert.hasText(this.authorizationCodeTokenRequest.redirectUri, "redirectUri cannot be empty"); |
||||
return this.authorizationCodeTokenRequest; |
||||
} |
||||
} |
||||
} |
||||
@ -1,96 +0,0 @@
@@ -1,96 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.springframework.security.oauth2.core.OAuth2Error; |
||||
import org.springframework.util.Assert; |
||||
|
||||
/** |
||||
* A representation of an <i>OAuth 2.0 Error Response</i>. |
||||
* |
||||
* <p> |
||||
* An error response may be returned from either of the following locations: |
||||
* <ul> |
||||
* <li><a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.1.2.1">Section 4.1.2.1</a> Authorization Code Grant Response</li> |
||||
* <li><a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-4.2.2.1">Section 4.2.2.1</a> Implicit Grant Response</li> |
||||
* <li><a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-5.2">Section 5.2</a> Access Token Response</li> |
||||
* <li><a target="_blank" href="https://tools.ietf.org/html/rfc6749#section-7.2">Section 7.2</a> Protected Resource Response</li> |
||||
* </ul> |
||||
* |
||||
* @author Joe Grandja |
||||
* @since 5.0 |
||||
*/ |
||||
public final class ErrorResponseAttributes { |
||||
private OAuth2Error errorObject; |
||||
private String state; |
||||
|
||||
private ErrorResponseAttributes() { |
||||
} |
||||
|
||||
public String getErrorCode() { |
||||
return this.errorObject.getErrorCode(); |
||||
} |
||||
|
||||
public String getDescription() { |
||||
return this.errorObject.getDescription(); |
||||
} |
||||
|
||||
public String getUri() { |
||||
return this.errorObject.getUri(); |
||||
} |
||||
|
||||
public String getState() { |
||||
return this.state; |
||||
} |
||||
|
||||
public static Builder withErrorCode(String errorCode) { |
||||
return new Builder(errorCode); |
||||
} |
||||
|
||||
public static class Builder { |
||||
private String errorCode; |
||||
private String description; |
||||
private String uri; |
||||
private String state; |
||||
|
||||
private Builder(String errorCode) { |
||||
Assert.hasText(errorCode, "errorCode cannot be empty"); |
||||
this.errorCode = errorCode; |
||||
} |
||||
|
||||
public Builder description(String description) { |
||||
this.description = description; |
||||
return this; |
||||
} |
||||
|
||||
public Builder uri(String uri) { |
||||
this.uri = uri; |
||||
return this; |
||||
} |
||||
|
||||
public Builder state(String state) { |
||||
this.state = state; |
||||
return this; |
||||
} |
||||
|
||||
public ErrorResponseAttributes build() { |
||||
ErrorResponseAttributes errorResponse = new ErrorResponseAttributes(); |
||||
errorResponse.errorObject = new OAuth2Error(this.errorCode, this.description, this.uri); |
||||
errorResponse.state = this.state; |
||||
return errorResponse; |
||||
} |
||||
} |
||||
} |
||||
@ -1,75 +0,0 @@
@@ -1,75 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.security.oauth2.core.AuthorizationGrantType; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests {@link AuthorizationCodeTokenRequestAttributes} |
||||
* |
||||
* @author Luander Ribeiro |
||||
*/ |
||||
public class AuthorizationCodeTokenRequestAttributesTest { |
||||
private static final String CODE = "code"; |
||||
private static final String CLIENT_ID = "client id"; |
||||
private static final String REDIRECT_URI = "http://redirect.uri/"; |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildWhenCodeIsNullThenThrowIllegalArgumentException() { |
||||
AuthorizationCodeTokenRequestAttributes |
||||
.withCode(null) |
||||
.clientId(CLIENT_ID) |
||||
.redirectUri(REDIRECT_URI) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildWhenClientIdIsNullThenThrowIllegalArgumentException() { |
||||
AuthorizationCodeTokenRequestAttributes |
||||
.withCode(CODE) |
||||
.clientId(null) |
||||
.redirectUri(REDIRECT_URI) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildWhenRedirectUriIsNullThenThrowIllegalArgumentException() { |
||||
AuthorizationCodeTokenRequestAttributes |
||||
.withCode(CODE) |
||||
.clientId(CLIENT_ID) |
||||
.redirectUri(null) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildWhenClientIdNotSetThenThrowIllegalArgumentException() { |
||||
AuthorizationCodeTokenRequestAttributes |
||||
.withCode(CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildWhenRedirectUriNotSetThenThrowIllegalArgumentException() { |
||||
AuthorizationCodeTokenRequestAttributes |
||||
.withCode(CODE) |
||||
.clientId(CLIENT_ID) |
||||
.build(); |
||||
} |
||||
} |
||||
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
/* |
||||
* Copyright 2012-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
/** |
||||
* Tests {@link ErrorResponseAttributes} |
||||
* |
||||
* @author Luander Ribeiro |
||||
*/ |
||||
public class ErrorResponseAttributesTest { |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void withErrorCodeWhenCodeIsNullThenThrowIllegalArgumentException() { |
||||
ErrorResponseAttributes.withErrorCode(null) |
||||
.build(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue