Skip to content

Commit

Permalink
[spring-atticgh-51]: added flag to DefaultAuthorizationEquestManager …
Browse files Browse the repository at this point in the history
…to hide valid scopes by default from client
  • Loading branch information
dsyer committed Apr 12, 2013
1 parent f781368 commit 88dea7e
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public class DefaultAuthorizationRequestManager implements AuthorizationRequestM

private final ClientDetailsService clientDetailsService;

private boolean revealValidScopes = false;

/**
* Flag to indicate that when an invalid scope is requested, the valid values should be revealed in the exception
* (which is then seen by the client). Default false;
*
* @param revealValidScopes the revealValidScopes to set
*/
public void setRevealValidScopes(boolean revealValidScopes) {
this.revealValidScopes = revealValidScopes;
}

public DefaultAuthorizationRequestManager(ClientDetailsService clientDetailsService) {
this.clientDetailsService = clientDetailsService;
}
Expand All @@ -49,8 +61,8 @@ public AuthorizationRequest createAuthorizationRequest(Map<String, String> param
// least obnoxious choice as a default).
scopes = clientDetails.getScope();
}
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest(parameters, Collections.<String, String> emptyMap(),
clientId, scopes);
DefaultAuthorizationRequest request = new DefaultAuthorizationRequest(parameters,
Collections.<String, String> emptyMap(), clientId, scopes);
request.addClientDetails(clientDetails);
return request;

Expand All @@ -62,7 +74,14 @@ public void validateParameters(Map<String, String> parameters, ClientDetails cli
Set<String> validScope = clientDetails.getScope();
for (String scope : OAuth2Utils.parseParameterList(parameters.get("scope"))) {
if (!validScope.contains(scope)) {
throw new InvalidScopeException("Invalid scope: " + scope, validScope);
InvalidScopeException exception;
if (revealValidScopes) {
exception = new InvalidScopeException("Invalid scope: " + scope, validScope);
}
else {
exception = new InvalidScopeException("Invalid scope: " + scope);
}
throw exception;
}
}
}
Expand Down

0 comments on commit 88dea7e

Please sign in to comment.