Skip to content

Commit

Permalink
Polish gh-1467
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandja committed Jan 15, 2024
1 parent 6638181 commit cce5b38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -148,8 +148,9 @@ public Authentication authenticate(Authentication authentication) throws Authent

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -121,8 +121,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -102,8 +102,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -104,8 +104,8 @@ public Authentication authenticate(Authentication authentication) throws Authent
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);
}
Expand All @@ -119,8 +119,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
}

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);
}
Expand All @@ -130,8 +131,9 @@ public Authentication authenticate(Authentication authentication) throws Authent
// 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);
}
Expand Down

0 comments on commit cce5b38

Please sign in to comment.