Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.

Commit

Permalink
Polish logs
Browse files Browse the repository at this point in the history
Closes gh-1941
  • Loading branch information
jzheaux authored and jgrandja committed Oct 20, 2021
1 parent e525a0e commit e96d2c7
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void validateGrantType(String grantType, ClientDetails clientDetails)
Collection<String> authorizedGrantTypes = clientDetails.getAuthorizedGrantTypes();
if (authorizedGrantTypes != null && !authorizedGrantTypes.isEmpty()
&& !authorizedGrantTypes.contains(grantType)) {
throw new InvalidClientException("Unauthorized grant type: " + grantType);
throw new InvalidClientException("Unauthorized grant type");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -248,25 +248,25 @@ 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();
try {
clientDetailsService.loadClientByClientId(clientId);
}
catch (ClientRegistrationException e) {
throw new InvalidTokenException("Client not valid: " + clientId, e);
throw new InvalidTokenException("Client not valid", e);
}
}
return result;
Expand All @@ -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();
}
Expand Down

0 comments on commit e96d2c7

Please sign in to comment.