Browse Source

Polish gh-1467

pull/1429/head
Joe Grandja 2 years ago
parent
commit
cce5b3871f
  1. 7
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationCodeAuthenticationProvider.java
  2. 7
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationCodeRequestAuthenticationProvider.java
  3. 5
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2ClientCredentialsAuthenticationProvider.java
  4. 7
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProvider.java
  5. 16
      oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2RefreshTokenAuthenticationProvider.java

7
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationCodeAuthenticationProvider.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 the original author or authors.
* Copyright 2020-2024 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.
@ -148,8 +148,9 @@ public final class OAuth2AuthorizationCodeAuthenticationProvider implements Auth @@ -148,8 +148,9 @@ public final class OAuth2AuthorizationCodeAuthenticationProvider implements Auth
if (StringUtils.hasText(authorizationRequest.getRedirectUri()) &&
!authorizationRequest.getRedirectUri().equals(authorizationCodeAuthentication.getRedirectUri())) {
if (this.logger.isWarnEnabled()) {
this.logger.warn(LogMessage.format("Invalidated redirect_uri used by registered client '%s'", registeredClient.getId()));
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: redirect_uri does not match" +
" for registered client '%s'", registeredClient.getId()));
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
}

7
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2AuthorizationCodeRequestAuthenticationProvider.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 the original author or authors.
* Copyright 2020-2024 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.
@ -121,8 +121,9 @@ public final class OAuth2AuthorizationCodeRequestAuthenticationProvider implemen @@ -121,8 +121,9 @@ public final class OAuth2AuthorizationCodeRequestAuthenticationProvider implemen
this.authenticationValidator.accept(authenticationContext);
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.AUTHORIZATION_CODE)) {
if (this.logger.isTraceEnabled()) {
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
" for registered client '%s'", registeredClient.getId()));
}
throwError(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT, OAuth2ParameterNames.CLIENT_ID,
authorizationCodeRequestAuthentication, registeredClient);

5
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2ClientCredentialsAuthenticationProvider.java

@ -95,8 +95,9 @@ public final class OAuth2ClientCredentialsAuthenticationProvider implements Auth @@ -95,8 +95,9 @@ public final class OAuth2ClientCredentialsAuthenticationProvider implements Auth
}
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.CLIENT_CREDENTIALS)) {
if (this.logger.isTraceEnabled()) {
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
" for registered client '%s'", registeredClient.getId()));
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT);
}

7
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2DeviceAuthorizationRequestAuthenticationProvider.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 the original author or authors.
* Copyright 2020-2024 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.
@ -102,8 +102,9 @@ public final class OAuth2DeviceAuthorizationRequestAuthenticationProvider implem @@ -102,8 +102,9 @@ public final class OAuth2DeviceAuthorizationRequestAuthenticationProvider implem
}
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.DEVICE_CODE)) {
if (this.logger.isTraceEnabled()) {
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
" for registered client '%s'", registeredClient.getId()));
}
throwError(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT, OAuth2ParameterNames.CLIENT_ID);
}

16
oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/OAuth2RefreshTokenAuthenticationProvider.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2020-2023 the original author or authors.
* Copyright 2020-2024 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.
@ -104,8 +104,8 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic @@ -104,8 +104,8 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic
OAuth2Authorization authorization = this.authorizationService.findByToken(
refreshTokenAuthentication.getRefreshToken(), OAuth2TokenType.REFRESH_TOKEN);
if (authorization == null) {
if (this.logger.isTraceEnabled()) {
this.logger.trace("The refresh token is invalid.");
if (this.logger.isDebugEnabled()) {
this.logger.debug("Invalid request: refresh_token is invalid");
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
}
@ -119,8 +119,9 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic @@ -119,8 +119,9 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic
}
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.REFRESH_TOKEN)) {
if (this.logger.isTraceEnabled()) {
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
" for registered client '%s'", registeredClient.getId()));
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT);
}
@ -130,8 +131,9 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic @@ -130,8 +131,9 @@ public final class OAuth2RefreshTokenAuthenticationProvider implements Authentic
// As per https://tools.ietf.org/html/rfc6749#section-5.2
// invalid_grant: The provided authorization grant (e.g., authorization code,
// resource owner credentials) or refresh token is invalid, expired, revoked [...].
if (this.logger.isTraceEnabled()) {
this.logger.trace("The refresh token is expired.");
if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Invalid request: refresh_token is not active" +
" for registered client '%s'", registeredClient.getId()));
}
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
}

Loading…
Cancel
Save