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

Commit 2b58aaf

Browse files
committed
Polish gh-1941
1 parent e96d2c7 commit 2b58aaf

File tree

19 files changed

+28
-31
lines changed

19 files changed

+28
-31
lines changed

Diff for: samples/oauth2/sparklr/src/main/java/org/springframework/security/oauth/examples/sparklr/mvc/AdminController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ private void checkResourceOwner(String user, Principal principal) {
9797
if (principal instanceof OAuth2Authentication) {
9898
OAuth2Authentication authentication = (OAuth2Authentication) principal;
9999
if (!authentication.isClientOnly() && !user.equals(principal.getName())) {
100-
throw new AccessDeniedException(String.format("User '%s' cannot obtain tokens for user '%s'",
101-
principal.getName(), user));
100+
throw new AccessDeniedException("User cannot obtain tokens for user");
102101
}
103102
}
104103
}

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/config/ConsumerDetailsFactoryBean.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public ConsumerDetails getObject() throws Exception {
9696
consumer.setSignatureSecret(new RSAKeySecret(cert.getPublicKey()));
9797
}
9898
catch (IOException e) {
99-
throw new BeanCreationException("RSA certificate not found at " + secret + ".",
99+
throw new BeanCreationException("RSA certificate not found",
100100
e);
101101
}
102102
catch (CertificateException e) {
103-
throw new BeanCreationException("Invalid RSA certificate at " + secret + ".", e);
103+
throw new BeanCreationException("Invalid RSA certificate", e);
104104
}
105105
catch (NullPointerException e) {
106-
throw new BeanCreationException("Could not load RSA certificate at " + secret + ".", e);
106+
throw new BeanCreationException("Could not load RSA certificate", e);
107107
}
108108
finally {
109109
try {

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/consumer/client/CoreOAuthConsumerSupport.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public OAuthConsumerToken getAccessToken(ProtectedResourceDetails details, OAuth
138138
Map<String, String> additionalParameters = new TreeMap<String, String>();
139139
if (details.isUse10a()) {
140140
if (verifier == null) {
141-
throw new UnverifiedRequestTokenException("Unverified request token: " + requestToken);
141+
throw new UnverifiedRequestTokenException("Unverified request token");
142142
}
143143
additionalParameters.put(OAuthConsumerParameter.oauth_verifier.toString(), verifier);
144144
}

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/provider/InMemoryConsumerDetailsService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class InMemoryConsumerDetailsService implements ConsumerDetailsService {
3737
public ConsumerDetails loadConsumerByConsumerKey(String consumerKey) throws OAuthException {
3838
ConsumerDetails details = consumerDetailsStore.get(consumerKey);
3939
if (details == null) {
40-
throw new InvalidOAuthParametersException("Consumer not found: " + consumerKey);
40+
throw new InvalidOAuthParametersException("Consumer not found");
4141
}
4242
return details;
4343
}

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/provider/filter/UserAuthorizationProcessingFilter.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ
8080

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

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

9191
if (callbackURL != null) {

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/provider/nonce/InMemoryNonceServices.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void validateNonce(ConsumerDetails consumerDetails, long timestamp, Strin
6565

6666
synchronized (NONCES) {
6767
if (NONCES.contains(entry)) {
68-
throw new NonceAlreadyUsedException("Nonce already used: " + nonce);
68+
throw new NonceAlreadyUsedException("Nonce already used");
6969
}
7070
else {
7171
NONCES.add(entry);

Diff for: spring-security-oauth/src/main/java/org/springframework/security/oauth/provider/token/RandomValueProviderTokenServices.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public OAuthProviderToken getToken(String token) throws AuthenticationException
8484
OAuthProviderTokenImpl tokenImpl = readToken(token);
8585

8686
if (tokenImpl == null) {
87-
throw new InvalidOAuthTokenException("Invalid token: " + token);
87+
throw new InvalidOAuthTokenException("Invalid token");
8888
}
8989
else if (isExpired(tokenImpl)) {
9090
removeToken(token);
@@ -138,7 +138,7 @@ public void authorizeRequestToken(String requestToken, String verifier, Authenti
138138
OAuthProviderTokenImpl tokenImpl = readToken(requestToken);
139139

140140
if (tokenImpl == null) {
141-
throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
141+
throw new InvalidOAuthTokenException("Invalid token");
142142
}
143143
else if (isExpired(tokenImpl)) {
144144
removeToken(requestToken);
@@ -159,7 +159,7 @@ public OAuthAccessProviderToken createAccessToken(String requestToken) throws Au
159159
OAuthProviderTokenImpl tokenImpl = readToken(requestToken);
160160

161161
if (tokenImpl == null) {
162-
throw new InvalidOAuthTokenException("Invalid token: " + requestToken);
162+
throw new InvalidOAuthTokenException("Invalid token");
163163
}
164164
else if (isExpired(tokenImpl)) {
165165
removeToken(requestToken);

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/http/converter/jaxb/AbstractJaxbMessageConverter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected final void writeToResult(E accessToken, HttpHeaders headers, Result re
8484
createMarshaller().marshal(convertedAccessToken, result);
8585
}
8686
catch (MarshalException ex) {
87-
throw new HttpMessageNotWritableException("Could not marshal [" + accessToken + "]: " + ex.getMessage(), ex);
87+
throw new HttpMessageNotWritableException("Could not marshal accessToken: " + ex.getMessage(), ex);
8888
}
8989
catch (JAXBException ex) {
9090
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/approval/ApprovalStoreUserApprovalHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public AuthorizationRequest checkForPreApproval(AuthorizationRequest authorizati
135135
}
136136
}
137137
catch (ClientRegistrationException e) {
138-
logger.warn("Client registration problem prevent autoapproval check for client=" + clientId);
138+
logger.warn("Client registration problem prevent autoapproval check for client");
139139
}
140140
}
141141

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/authentication/OAuth2AuthenticationManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
8686
String token = (String) authentication.getPrincipal();
8787
OAuth2Authentication auth = tokenServices.loadAuthentication(token);
8888
if (auth == null) {
89-
throw new InvalidTokenException("Invalid token: " + token);
89+
throw new InvalidTokenException("Invalid token");
9090
}
9191

9292
Collection<String> resourceIds = auth.getOAuth2Request().getResourceIds();
@@ -123,7 +123,7 @@ private void checkClientDetails(OAuth2Authentication auth) {
123123
for (String scope : auth.getOAuth2Request().getScope()) {
124124
if (!allowed.contains(scope)) {
125125
throw new OAuth2AccessDeniedException(
126-
"Invalid token contains disallowed scope (" + scope + ") for this client");
126+
"Invalid token contains disallowed scope for this client");
127127
}
128128
}
129129
}

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/client/JdbcClientDetailsService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,28 @@ public void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyEx
136136
jdbcTemplate.update(insertClientDetailsSql, getFields(clientDetails));
137137
}
138138
catch (DuplicateKeyException e) {
139-
throw new ClientAlreadyExistsException("Client already exists: " + clientDetails.getClientId(), e);
139+
throw new ClientAlreadyExistsException("Client already exists", e);
140140
}
141141
}
142142

143143
public void updateClientDetails(ClientDetails clientDetails) throws NoSuchClientException {
144144
int count = jdbcTemplate.update(updateClientDetailsSql, getFieldsForUpdate(clientDetails));
145145
if (count != 1) {
146-
throw new NoSuchClientException("No client found requested id");
146+
throw new NoSuchClientException("No client found with requested id");
147147
}
148148
}
149149

150150
public void updateClientSecret(String clientId, String secret) throws NoSuchClientException {
151151
int count = jdbcTemplate.update(updateClientSecretSql, passwordEncoder.encode(secret), clientId);
152152
if (count != 1) {
153-
throw new NoSuchClientException("No client found requested id");
153+
throw new NoSuchClientException("No client found with requested id");
154154
}
155155
}
156156

157157
public void removeClientDetails(String clientId) throws NoSuchClientException {
158158
int count = jdbcTemplate.update(deleteClientDetailsSql, clientId);
159159
if (count != 1) {
160-
throw new NoSuchClientException("No client found requested id");
160+
throw new NoSuchClientException("No client found with requested id");
161161
}
162162
}
163163

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/endpoint/AuthorizationEndpoint.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public ModelAndView authorize(Map<String, Object> model, @RequestParam Map<Strin
139139
Set<String> responseTypes = authorizationRequest.getResponseTypes();
140140

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

145145
if (authorizationRequest.getClientId() == null) {

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/endpoint/DefaultRedirectResolver.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ private String obtainMatchingRedirect(Set<String> redirectUris, String requested
230230
}
231231
}
232232

233-
throw new RedirectMismatchException("Invalid redirect: " + requestedRedirect
234-
+ " does not match one of the registered values.");
233+
throw new RedirectMismatchException("Invalid redirect uri does not match one of the registered values.");
235234
}
236235
}

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/endpoint/TokenEndpointAuthenticationFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
128128
if (credentials != null) {
129129

130130
if (debug) {
131-
logger.debug("Authentication credentials found for '" + credentials.getName() + "'");
131+
logger.debug("Authentication credentials found");
132132
}
133133

134134
Authentication authResult = authenticationManager.authenticate(credentials);

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/request/DefaultOAuth2RequestValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ private void validateScope(Set<String> requestScopes, Set<String> clientScopes)
3333
if (clientScopes != null && !clientScopes.isEmpty()) {
3434
for (String scope : requestScopes) {
3535
if (!clientScopes.contains(scope)) {
36-
throw new InvalidScopeException("Invalid scope: " + scope, clientScopes);
36+
throw new InvalidScopeException("Invalid scope", clientScopes);
3737
}
3838
}
3939
}

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/AbstractTokenGranter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
6565
validateGrantType(grantType, client);
6666

6767
if (logger.isDebugEnabled()) {
68-
logger.debug("Getting access token for: " + clientId);
68+
logger.debug("Getting access token for clientId");
6969
}
7070

7171
return getAccessToken(client, tokenRequest);

Diff for: spring-security-oauth2/src/main/java/org/springframework/security/oauth2/provider/token/DefaultTokenServices.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ private OAuth2Authentication createRefreshedAuthentication(OAuth2Authentication
220220
if (scope != null && !scope.isEmpty()) {
221221
Set<String> originalScope = clientAuth.getScope();
222222
if (originalScope == null || !originalScope.containsAll(scope)) {
223-
throw new InvalidScopeException("Unable to narrow the scope of the client authentication to " + scope
224-
+ ".", originalScope);
223+
throw new InvalidScopeException("Unable to narrow the scope of the client authentication", originalScope);
225224
}
226225
else {
227226
clientAuth = clientAuth.narrowScope(scope);

Diff for: spring-security-oauth2/src/test/java/org/springframework/security/oauth2/provider/code/RedisAuthorizationCodeServicesTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void verifyCreateAndConsumeAuthorizationCode() {
100100
}
101101
catch (InvalidGrantException e) {
102102
assertThat("Wrong error message!", e.getMessage(),
103-
allOf(containsString("Invalid"), containsString(authorizationCode)));
103+
allOf(containsString("Invalid authorization code")));
104104
}
105105
}
106106
}

Diff for: spring-security-oauth2/src/test/java/org/springframework/security/oauth2/provider/endpoint/DefaultRedirectResolverTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void testRedirectNotMatchingReturnsGenericErrorMessage() throws Exception
204204
resolver.resolveRedirect(requestedRedirect, client);
205205
fail();
206206
} catch (RedirectMismatchException ex) {
207-
assertEquals("Invalid redirect: https://anywhere.com/myendpoint does not match one of the registered values.", ex.getMessage());
207+
assertEquals("Invalid redirect uri does not match one of the registered values.", ex.getMessage());
208208
}
209209
}
210210

0 commit comments

Comments
 (0)