Skip to content

Commit cce5b38

Browse files
committed
Polish gh-1467
1 parent 6638181 commit cce5b38

5 files changed

+24
-18
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -148,8 +148,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
148148

149149
if (StringUtils.hasText(authorizationRequest.getRedirectUri()) &&
150150
!authorizationRequest.getRedirectUri().equals(authorizationCodeAuthentication.getRedirectUri())) {
151-
if (this.logger.isWarnEnabled()) {
152-
this.logger.warn(LogMessage.format("Invalidated redirect_uri used by registered client '%s'", registeredClient.getId()));
151+
if (this.logger.isDebugEnabled()) {
152+
this.logger.debug(LogMessage.format("Invalid request: redirect_uri does not match" +
153+
" for registered client '%s'", registeredClient.getId()));
153154
}
154155
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
155156
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -121,8 +121,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
121121
this.authenticationValidator.accept(authenticationContext);
122122

123123
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.AUTHORIZATION_CODE)) {
124-
if (this.logger.isTraceEnabled()) {
125-
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
124+
if (this.logger.isDebugEnabled()) {
125+
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
126+
" for registered client '%s'", registeredClient.getId()));
126127
}
127128
throwError(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT, OAuth2ParameterNames.CLIENT_ID,
128129
authorizationCodeRequestAuthentication, registeredClient);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
9595
}
9696

9797
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.CLIENT_CREDENTIALS)) {
98-
if (this.logger.isTraceEnabled()) {
99-
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
98+
if (this.logger.isDebugEnabled()) {
99+
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
100+
" for registered client '%s'", registeredClient.getId()));
100101
}
101102
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT);
102103
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -102,8 +102,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
102102
}
103103

104104
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.DEVICE_CODE)) {
105-
if (this.logger.isTraceEnabled()) {
106-
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
105+
if (this.logger.isDebugEnabled()) {
106+
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
107+
" for registered client '%s'", registeredClient.getId()));
107108
}
108109
throwError(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT, OAuth2ParameterNames.CLIENT_ID);
109110
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2023 the original author or authors.
2+
* Copyright 2020-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,8 +104,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
104104
OAuth2Authorization authorization = this.authorizationService.findByToken(
105105
refreshTokenAuthentication.getRefreshToken(), OAuth2TokenType.REFRESH_TOKEN);
106106
if (authorization == null) {
107-
if (this.logger.isTraceEnabled()) {
108-
this.logger.trace("The refresh token is invalid.");
107+
if (this.logger.isDebugEnabled()) {
108+
this.logger.debug("Invalid request: refresh_token is invalid");
109109
}
110110
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
111111
}
@@ -119,8 +119,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
119119
}
120120

121121
if (!registeredClient.getAuthorizationGrantTypes().contains(AuthorizationGrantType.REFRESH_TOKEN)) {
122-
if (this.logger.isTraceEnabled()) {
123-
this.logger.warn(LogMessage.format("Invalid request: requested grant_type is not allowed for registered client '%s'", registeredClient.getId()));
122+
if (this.logger.isDebugEnabled()) {
123+
this.logger.debug(LogMessage.format("Invalid request: requested grant_type is not allowed" +
124+
" for registered client '%s'", registeredClient.getId()));
124125
}
125126
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.UNAUTHORIZED_CLIENT);
126127
}
@@ -130,8 +131,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
130131
// As per https://tools.ietf.org/html/rfc6749#section-5.2
131132
// invalid_grant: The provided authorization grant (e.g., authorization code,
132133
// resource owner credentials) or refresh token is invalid, expired, revoked [...].
133-
if (this.logger.isTraceEnabled()) {
134-
this.logger.trace("The refresh token is expired.");
134+
if (this.logger.isDebugEnabled()) {
135+
this.logger.debug(LogMessage.format("Invalid request: refresh_token is not active" +
136+
" for registered client '%s'", registeredClient.getId()));
135137
}
136138
throw new OAuth2AuthenticationException(OAuth2ErrorCodes.INVALID_GRANT);
137139
}

0 commit comments

Comments
 (0)