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

Commit

Permalink
Polish gh-1941
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrandja committed Oct 20, 2021
1 parent e96d2c7 commit 2b58aaf
Show file tree
Hide file tree
Showing 19 changed files with 28 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ private void checkResourceOwner(String user, Principal principal) {
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
if (!authentication.isClientOnly() && !user.equals(principal.getName())) {
throw new AccessDeniedException(String.format("User '%s' cannot obtain tokens for user '%s'",
principal.getName(), user));
throw new AccessDeniedException("User cannot obtain tokens for user");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ public ConsumerDetails getObject() throws Exception {
consumer.setSignatureSecret(new RSAKeySecret(cert.getPublicKey()));
}
catch (IOException e) {
throw new BeanCreationException("RSA certificate not found at " + secret + ".",
throw new BeanCreationException("RSA certificate not found",
e);
}
catch (CertificateException e) {
throw new BeanCreationException("Invalid RSA certificate at " + secret + ".", e);
throw new BeanCreationException("Invalid RSA certificate", e);
}
catch (NullPointerException e) {
throw new BeanCreationException("Could not load RSA certificate at " + secret + ".", e);
throw new BeanCreationException("Could not load RSA certificate", e);
}
finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public OAuthConsumerToken getAccessToken(ProtectedResourceDetails details, OAuth
Map<String, String> additionalParameters = new TreeMap<String, String>();
if (details.isUse10a()) {
if (verifier == null) {
throw new UnverifiedRequestTokenException("Unverified request token: " + requestToken);
throw new UnverifiedRequestTokenException("Unverified request token");
}
additionalParameters.put(OAuthConsumerParameter.oauth_verifier.toString(), verifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class InMemoryConsumerDetailsService implements ConsumerDetailsService {
public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException {
ConsumerDetails details = consumerDetailsStore.get(consumerKey);
if (details == null) {
throw new InvalidOAuthParametersException("Consumer not found: " + consumerKey);
throw new InvalidOAuthParametersException("Consumer not found");
}
return details;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ

OAuthProviderToken token = getTokenServices().getToken(requestToken);
if (token == null) {
throw new InvalidOAuthTokenException("No callback value has been provided for request token " + requestToken + ".");
throw new InvalidOAuthTokenException("No callback value has been provided for request token");
}

String callbackURL = token.getCallbackUrl();
if (isRequire10a() && callbackURL == null) {
throw new InvalidOAuthTokenException("No callback value has been provided for request token " + requestToken + ".");
throw new InvalidOAuthTokenException("No callback value has been provided for request token");
}

if (callbackURL != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void validateNonce(ConsumerDetails consumerDetails, long timestamp, Strin

synchronized (NONCES) {
if (NONCES.contains(entry)) {
throw new NonceAlreadyUsedException("Nonce already used: " + nonce);
throw new NonceAlreadyUsedException("Nonce already used");
}
else {
NONCES.add(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public OAuthProviderToken getToken(String token) throws AuthenticationException
OAuthProviderTokenImpl tokenImpl = readToken(token);

if (tokenImpl == null) {
throw new InvalidOAuthTokenException("Invalid token: " + token);
throw new InvalidOAuthTokenException("Invalid token");
}
else if (isExpired(tokenImpl)) {
removeToken(token);
Expand Down Expand Up @@ -138,7 +138,7 @@ public void authorizeRequestToken(String requestToken, String verifier, Authenti
OAuthProviderTokenImpl tokenImpl = readToken(requestToken);

if (tokenImpl == null) {
throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
throw new InvalidOAuthTokenException("Invalid token");
}
else if (isExpired(tokenImpl)) {
removeToken(requestToken);
Expand All @@ -159,7 +159,7 @@ public OAuthAccessProviderToken createAccessToken(String requestToken) throws Au
OAuthProviderTokenImpl tokenImpl = readToken(requestToken);

if (tokenImpl == null) {
throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
throw new InvalidOAuthTokenException("Invalid token");
}
else if (isExpired(tokenImpl)) {
removeToken(requestToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected final void writeToResult(E accessToken, HttpHeaders headers, Result re
createMarshaller().marshal(convertedAccessToken, result);
}
catch (MarshalException ex) {
throw new HttpMessageNotWritableException("Could not marshal [" + accessToken + "]: " + ex.getMessage(), ex);
throw new HttpMessageNotWritableException("Could not marshal accessToken: " + ex.getMessage(), ex);
}
catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizati
}
}
catch (ClientRegistrationException e) {
logger.warn("Client registration problem prevent autoapproval check for client=" + clientId);
logger.warn("Client registration problem prevent autoapproval check for client");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
String token = (String) authentication.getPrincipal();
OAuth2Authentication auth = tokenServices.loadAuthentication(token);
if (auth == null) {
throw new InvalidTokenException("Invalid token: " + token);
throw new InvalidTokenException("Invalid token");
}

Collection<String> resourceIds = auth.getOAuth2Request().getResourceIds();
Expand Down Expand Up @@ -123,7 +123,7 @@ private void checkClientDetails(OAuth2Authentication auth) {
for (String scope : auth.getOAuth2Request().getScope()) {
if (!allowed.contains(scope)) {
throw new OAuth2AccessDeniedException(
"Invalid token contains disallowed scope (" + scope + ") for this client");
"Invalid token contains disallowed scope for this client");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,28 +136,28 @@ public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyEx
jdbcTemplate.update(insertClientDetailsSql, getFields(clientDetails));
}
catch (DuplicateKeyException e) {
throw new ClientAlreadyExistsException("Client already exists: " + clientDetails.getClientId(), e);
throw new ClientAlreadyExistsException("Client already exists", e);
}
}

public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
int count = jdbcTemplate.update(updateClientDetailsSql, getFieldsForUpdate(clientDetails));
if (count != 1) {
throw new NoSuchClientException("No client found requested id");
throw new NoSuchClientException("No client found with 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 requested id");
throw new NoSuchClientException("No client found with requested id");
}
}

public void removeClientDetails(String clientId) throws NoSuchClientException {
int count = jdbcTemplate.update(deleteClientDetailsSql, clientId);
if (count != 1) {
throw new NoSuchClientException("No client found requested id");
throw new NoSuchClientException("No client found with requested id");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public ModelAndView authorize(Map<String, Object> model, @RequestParam Map<Strin
Set<String> responseTypes = authorizationRequest.getResponseTypes();

if (!responseTypes.contains("token") && !responseTypes.contains("code")) {
throw new UnsupportedResponseTypeException("Unsupported response types: " + responseTypes);
throw new UnsupportedResponseTypeException("Unsupported response types");
}

if (authorizationRequest.getClientId() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ private String obtainMatchingRedirect(Set<String> redirectUris, String requested
}
}

throw new RedirectMismatchException("Invalid redirect: " + requestedRedirect
+ " does not match one of the registered values.");
throw new RedirectMismatchException("Invalid redirect uri does not match one of the registered values.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
if (credentials != null) {

if (debug) {
logger.debug("Authentication credentials found for '" + credentials.getName() + "'");
logger.debug("Authentication credentials found");
}

Authentication authResult = authenticationManager.authenticate(credentials);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void validateScope(Set<String> requestScopes, Set<String> clientScopes)
if (clientScopes != null && !clientScopes.isEmpty()) {
for (String scope : requestScopes) {
if (!clientScopes.contains(scope)) {
throw new InvalidScopeException("Invalid scope: " + scope, clientScopes);
throw new InvalidScopeException("Invalid scope", clientScopes);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
validateGrantType(grantType, client);

if (logger.isDebugEnabled()) {
logger.debug("Getting access token for: " + clientId);
logger.debug("Getting access token for clientId");
}

return getAccessToken(client, tokenRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ private OAuth2Authentication createRefreshedAuthentication(OAuth2Authentication
if (scope != null && !scope.isEmpty()) {
Set<String> originalScope = clientAuth.getScope();
if (originalScope == null || !originalScope.containsAll(scope)) {
throw new InvalidScopeException("Unable to narrow the scope of the client authentication to " + scope
+ ".", originalScope);
throw new InvalidScopeException("Unable to narrow the scope of the client authentication", originalScope);
}
else {
clientAuth = clientAuth.narrowScope(scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void verifyCreateAndConsumeAuthorizationCode() {
}
catch (InvalidGrantException e) {
assertThat("Wrong error message!", e.getMessage(),
allOf(containsString("Invalid"), containsString(authorizationCode)));
allOf(containsString("Invalid authorization code")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void testRedirectNotMatchingReturnsGenericErrorMessage() throws Exception
resolver.resolveRedirect(requestedRedirect, client);
fail();
} catch (RedirectMismatchException ex) {
assertEquals("Invalid redirect: https://anywhere.com/myendpoint does not match one of the registered values.", ex.getMessage());
assertEquals("Invalid redirect uri does not match one of the registered values.", ex.getMessage());
}
}

Expand Down

0 comments on commit 2b58aaf

Please sign in to comment.