Polish gh-319

This commit is contained in:
Joe Grandja
2021-07-06 14:39:40 -04:00
parent 4517022f36
commit cf235ceb4e
5 changed files with 25 additions and 10 deletions

View File

@@ -94,6 +94,7 @@ public class OAuth2TokenEndpointFilter extends OncePerRequestFilter {
*/ */
public static final String DEFAULT_TOKEN_ENDPOINT_URI = "/oauth2/token"; public static final String DEFAULT_TOKEN_ENDPOINT_URI = "/oauth2/token";
private static final String DEFAULT_ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc6749#section-5.2";
private final AuthenticationManager authenticationManager; private final AuthenticationManager authenticationManager;
private final RequestMatcher tokenEndpointMatcher; private final RequestMatcher tokenEndpointMatcher;
private final HttpMessageConverter<OAuth2AccessTokenResponse> accessTokenHttpResponseConverter = private final HttpMessageConverter<OAuth2AccessTokenResponse> accessTokenHttpResponseConverter =
@@ -231,8 +232,7 @@ public class OAuth2TokenEndpointFilter extends OncePerRequestFilter {
} }
private static void throwError(String errorCode, String parameterName) { private static void throwError(String errorCode, String parameterName) {
OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, DEFAULT_ERROR_URI);
"https://tools.ietf.org/html/rfc6749#section-5.2");
throw new OAuth2AuthenticationException(error); throw new OAuth2AuthenticationException(error);
} }

View File

@@ -61,7 +61,10 @@ public final class OAuth2AuthorizationCodeAuthenticationConverter implements Aut
String code = parameters.getFirst(OAuth2ParameterNames.CODE); String code = parameters.getFirst(OAuth2ParameterNames.CODE);
if (!StringUtils.hasText(code) || if (!StringUtils.hasText(code) ||
parameters.get(OAuth2ParameterNames.CODE).size() != 1) { parameters.get(OAuth2ParameterNames.CODE).size() != 1) {
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.CODE); OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
OAuth2ParameterNames.CODE,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }
// redirect_uri (REQUIRED) // redirect_uri (REQUIRED)
@@ -69,7 +72,10 @@ public final class OAuth2AuthorizationCodeAuthenticationConverter implements Aut
String redirectUri = parameters.getFirst(OAuth2ParameterNames.REDIRECT_URI); String redirectUri = parameters.getFirst(OAuth2ParameterNames.REDIRECT_URI);
if (StringUtils.hasText(redirectUri) && if (StringUtils.hasText(redirectUri) &&
parameters.get(OAuth2ParameterNames.REDIRECT_URI).size() != 1) { parameters.get(OAuth2ParameterNames.REDIRECT_URI).size() != 1) {
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.REDIRECT_URI); OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
OAuth2ParameterNames.REDIRECT_URI,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }
// @formatter:off // @formatter:off

View File

@@ -64,7 +64,10 @@ public final class OAuth2ClientCredentialsAuthenticationConverter implements Aut
String scope = parameters.getFirst(OAuth2ParameterNames.SCOPE); String scope = parameters.getFirst(OAuth2ParameterNames.SCOPE);
if (StringUtils.hasText(scope) && if (StringUtils.hasText(scope) &&
parameters.get(OAuth2ParameterNames.SCOPE).size() != 1) { parameters.get(OAuth2ParameterNames.SCOPE).size() != 1) {
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.SCOPE); OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
OAuth2ParameterNames.SCOPE,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }
Set<String> requestedScopes = null; Set<String> requestedScopes = null;
if (StringUtils.hasText(scope)) { if (StringUtils.hasText(scope)) {

View File

@@ -31,6 +31,7 @@ import org.springframework.util.MultiValueMap;
* @since 0.1.2 * @since 0.1.2
*/ */
final class OAuth2EndpointUtils { final class OAuth2EndpointUtils {
static final String ACCESS_TOKEN_REQUEST_ERROR_URI = "https://datatracker.ietf.org/doc/html/rfc6749#section-5.2";
private OAuth2EndpointUtils() { private OAuth2EndpointUtils() {
} }
@@ -48,9 +49,8 @@ final class OAuth2EndpointUtils {
return parameters; return parameters;
} }
static void throwError(String errorCode, String parameterName) { static void throwError(String errorCode, String parameterName, String errorUri) {
OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, OAuth2Error error = new OAuth2Error(errorCode, "OAuth 2.0 Parameter: " + parameterName, errorUri);
"https://tools.ietf.org/html/rfc6749#section-5.2");
throw new OAuth2AuthenticationException(error); throw new OAuth2AuthenticationException(error);
} }

View File

@@ -64,14 +64,20 @@ public final class OAuth2RefreshTokenAuthenticationConverter implements Authenti
String refreshToken = parameters.getFirst(OAuth2ParameterNames.REFRESH_TOKEN); String refreshToken = parameters.getFirst(OAuth2ParameterNames.REFRESH_TOKEN);
if (!StringUtils.hasText(refreshToken) || if (!StringUtils.hasText(refreshToken) ||
parameters.get(OAuth2ParameterNames.REFRESH_TOKEN).size() != 1) { parameters.get(OAuth2ParameterNames.REFRESH_TOKEN).size() != 1) {
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.REFRESH_TOKEN); OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
OAuth2ParameterNames.REFRESH_TOKEN,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }
// scope (OPTIONAL) // scope (OPTIONAL)
String scope = parameters.getFirst(OAuth2ParameterNames.SCOPE); String scope = parameters.getFirst(OAuth2ParameterNames.SCOPE);
if (StringUtils.hasText(scope) && if (StringUtils.hasText(scope) &&
parameters.get(OAuth2ParameterNames.SCOPE).size() != 1) { parameters.get(OAuth2ParameterNames.SCOPE).size() != 1) {
OAuth2EndpointUtils.throwError(OAuth2ErrorCodes.INVALID_REQUEST, OAuth2ParameterNames.SCOPE); OAuth2EndpointUtils.throwError(
OAuth2ErrorCodes.INVALID_REQUEST,
OAuth2ParameterNames.SCOPE,
OAuth2EndpointUtils.ACCESS_TOKEN_REQUEST_ERROR_URI);
} }
Set<String> requestedScopes = null; Set<String> requestedScopes = null;
if (StringUtils.hasText(scope)) { if (StringUtils.hasText(scope)) {