From e96d2c738757146234c7e8a1962a7a755776b512 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Tue, 12 Oct 2021 16:48:18 -0600 Subject: [PATCH] Polish logs Closes gh-1941 --- .../client/InMemoryClientDetailsService.java | 2 +- .../client/JdbcClientDetailsService.java | 8 ++++---- .../code/AuthorizationCodeTokenGranter.java | 2 +- .../RandomValueAuthorizationCodeServices.java | 2 +- .../ResourceOwnerPasswordTokenGranter.java | 4 ++-- .../provider/refresh/RefreshTokenGranter.java | 2 +- .../provider/token/AbstractTokenGranter.java | 2 +- .../provider/token/DefaultTokenServices.java | 20 +++++++++---------- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/InMemoryClientDetailsService.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/InMemoryClientDetailsService.java index 502251839..1ce56e397 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/InMemoryClientDetailsService.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/InMemoryClientDetailsService.java @@ -40,7 +40,7 @@ public class InMemoryClientDetailsService implements ClientDetailsService { public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException { ClientDetails details = clientDetailsStore.get(clientId); if (details == null) { - throw new NoSuchClientException("No client with requested id: " + clientId); + throw new NoSuchClientException("No client with requested id"); } return details; } diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/JdbcClientDetailsService.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/JdbcClientDetailsService.java index f3b513813..be4d3af90 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/JdbcClientDetailsService.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/JdbcClientDetailsService.java @@ -125,7 +125,7 @@ public ClientDetails loadClientByClientId(String clientId) throws InvalidClientE details = jdbcTemplate.queryForObject(selectClientDetailsSql, new ClientDetailsRowMapper(), clientId); } catch (EmptyResultDataAccessException e) { - throw new NoSuchClientException("No client with requested id: " + clientId); + throw new NoSuchClientException("No client with requested id"); } return details; @@ -143,21 +143,21 @@ public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyEx public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException { int count = jdbcTemplate.update(updateClientDetailsSql, getFieldsForUpdate(clientDetails)); if (count != 1) { - throw new NoSuchClientException("No client found with id = " + clientDetails.getClientId()); + throw new NoSuchClientException("No client found requested id"); } } public void updateClientSecret(String clientId, String secret) throws NoSuchClientException { int count = jdbcTemplate.update(updateClientSecretSql, passwordEncoder.encode(secret), clientId); if (count != 1) { - throw new NoSuchClientException("No client found with id = " + clientId); + throw new NoSuchClientException("No client found requested id"); } } public void removeClientDetails(String clientId) throws NoSuchClientException { int count = jdbcTemplate.update(deleteClientDetailsSql, clientId); if (count != 1) { - throw new NoSuchClientException("No client found with id = " + clientId); + throw new NoSuchClientException("No client found requested id"); } } diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/AuthorizationCodeTokenGranter.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/AuthorizationCodeTokenGranter.java index a1ca14e00..968e677c8 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/AuthorizationCodeTokenGranter.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/AuthorizationCodeTokenGranter.java @@ -74,7 +74,7 @@ protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, Tok OAuth2Authentication storedAuth = authorizationCodeServices.consumeAuthorizationCode(authorizationCode); if (storedAuth == null) { - throw new InvalidGrantException("Invalid authorization code: " + authorizationCode); + throw new InvalidGrantException("Invalid authorization code"); } OAuth2Request pendingOAuth2Request = storedAuth.getOAuth2Request(); diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/RandomValueAuthorizationCodeServices.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/RandomValueAuthorizationCodeServices.java index b4ea58665..154d12987 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/RandomValueAuthorizationCodeServices.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/code/RandomValueAuthorizationCodeServices.java @@ -32,7 +32,7 @@ public OAuth2Authentication consumeAuthorizationCode(String code) throws InvalidGrantException { OAuth2Authentication auth = this.remove(code); if (auth == null) { - throw new InvalidGrantException("Invalid authorization code: " + code); + throw new InvalidGrantException("Invalid authorization code"); } return auth; } diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/password/ResourceOwnerPasswordTokenGranter.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/password/ResourceOwnerPasswordTokenGranter.java index 365202c6e..d4b2cfedc 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/password/ResourceOwnerPasswordTokenGranter.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/password/ResourceOwnerPasswordTokenGranter.java @@ -85,10 +85,10 @@ protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, Tok } catch (UsernameNotFoundException e) { // If the user is not found, report a generic error message - throw new InvalidGrantException(e.getMessage()); + throw new InvalidGrantException("username not found"); } if (userAuth == null || !userAuth.isAuthenticated()) { - throw new InvalidGrantException("Could not authenticate user: " + username); + throw new InvalidGrantException("Could not authenticate user"); } OAuth2Request storedOAuth2Request = getRequestFactory().createOAuth2Request(client, tokenRequest); diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/refresh/RefreshTokenGranter.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/refresh/RefreshTokenGranter.java index d390a2780..242b09c32 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/refresh/RefreshTokenGranter.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/refresh/RefreshTokenGranter.java @@ -59,7 +59,7 @@ protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest to throw new InvalidGrantException(ase.getMessage()); } catch (UsernameNotFoundException e) { // If the user is not found, report a generic error message - throw new InvalidGrantException(e.getMessage()); + throw new InvalidGrantException("user not found"); } } } diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java index 3cf6c61a1..029d0feca 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java @@ -85,7 +85,7 @@ protected void validateGrantType(String grantType, ClientDetails clientDetails) Collection authorizedGrantTypes = clientDetails.getAuthorizedGrantTypes(); if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty() && !authorizedGrantTypes.contains(grantType)) { - throw new InvalidClientException("Unauthorized grant type: " + grantType); + throw new InvalidClientException("Unauthorized grant type"); } } diff --git a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/DefaultTokenServices.java b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/DefaultTokenServices.java index fe247b83f..e71871196 100644 --- a/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/DefaultTokenServices.java +++ b/spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/DefaultTokenServices.java @@ -146,12 +146,12 @@ public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenReque throws AuthenticationException { if (!supportRefreshToken) { - throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue); + throw new InvalidGrantException("Invalid refresh token"); } OAuth2RefreshToken refreshToken = tokenStore.readRefreshToken(refreshTokenValue); if (refreshToken == null) { - throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue); + throw new InvalidGrantException("Invalid refresh token"); } OAuth2Authentication authentication = tokenStore.readAuthenticationForRefreshToken(refreshToken); @@ -174,7 +174,7 @@ public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenReque } String clientId = authentication.getOAuth2Request().getClientId(); if (clientId == null || !clientId.equals(tokenRequest.getClientId())) { - throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue); + throw new InvalidGrantException("Wrong client for this refresh token"); } // clear out any access tokens already associated with the refresh @@ -183,7 +183,7 @@ public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenReque if (isExpired(refreshToken)) { tokenStore.removeRefreshToken(refreshToken); - throw new InvalidTokenException("Invalid refresh token (expired): " + refreshToken); + throw new InvalidTokenException("Invalid refresh token (expired)"); } authentication = createRefreshedAuthentication(authentication, tokenRequest); @@ -248,17 +248,17 @@ public OAuth2Authentication loadAuthentication(String accessTokenValue) throws A InvalidTokenException { OAuth2AccessToken accessToken = tokenStore.readAccessToken(accessTokenValue); if (accessToken == null) { - throw new InvalidTokenException("Invalid access token: " + accessTokenValue); + throw new InvalidTokenException("Invalid access token"); } else if (accessToken.isExpired()) { tokenStore.removeAccessToken(accessToken); - throw new InvalidTokenException("Access token expired: " + accessTokenValue); + throw new InvalidTokenException("Access token expired"); } OAuth2Authentication result = tokenStore.readAuthentication(accessToken); if (result == null) { // in case of race condition - throw new InvalidTokenException("Invalid access token: " + accessTokenValue); + throw new InvalidTokenException("Invalid access token"); } if (clientDetailsService != null) { String clientId = result.getOAuth2Request().getClientId(); @@ -266,7 +266,7 @@ else if (accessToken.isExpired()) { clientDetailsService.loadClientByClientId(clientId); } catch (ClientRegistrationException e) { - throw new InvalidTokenException("Client not valid: " + clientId, e); + throw new InvalidTokenException("Client not valid", e); } } return result; @@ -275,11 +275,11 @@ else if (accessToken.isExpired()) { public String getClientId(String tokenValue) { OAuth2Authentication authentication = tokenStore.readAuthentication(tokenValue); if (authentication == null) { - throw new InvalidTokenException("Invalid access token: " + tokenValue); + throw new InvalidTokenException("Invalid access token"); } OAuth2Request clientAuth = authentication.getOAuth2Request(); if (clientAuth == null) { - throw new InvalidTokenException("Invalid access token (no client id): " + tokenValue); + throw new InvalidTokenException("Invalid access token (no client id)"); } return clientAuth.getClientId(); }