Skip to content

Commit

Permalink
One more place that improperly evaluates EMAIL as a required claim
Browse files Browse the repository at this point in the history
  • Loading branch information
fhanik committed Oct 20, 2016
1 parent 22ebadf commit 57a9d0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
Expand Up @@ -1081,16 +1081,13 @@ public OAuth2AccessToken readAccessToken(String accessToken) {
@SuppressWarnings("unchecked")
ArrayList<String> scopes = (ArrayList<String>) claims.get(SCOPE);
if (null != scopes && scopes.size() > 0) {
token.setScope(new HashSet<String>(scopes));
token.setScope(new HashSet<>(scopes));
}
String clientId = (String) claims.get(CID);
ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
String email = (String) claims.get(EMAIL);

String userId = (String)claims.get(USER_ID);
// Only check user access tokens
if (null != email) {
String userId = (String)claims.get(USER_ID);

if (null != userId) {
@SuppressWarnings("unchecked")
ArrayList<String> tokenScopes = (ArrayList<String>) claims.get(SCOPE);
Set<String> autoApprovedScopes = getAutoApprovedScopes(claims.get(GRANT_TYPE), tokenScopes, client);
Expand Down
Expand Up @@ -93,6 +93,7 @@
import java.util.Map;
import java.util.Set;

import static java.util.Collections.EMPTY_SET;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singleton;
import static org.cloudfoundry.identity.uaa.oauth.UaaTokenServices.UAA_REFRESH_TOKEN;
Expand Down Expand Up @@ -1624,6 +1625,16 @@ public void refreshAccessTokenWithGrantTypeRestricted_butRefreshScopePresent() {

@Test
public void testReadAccessToken() {
readAccessToken(EMPTY_SET);
}

@Test
public void testReadAccessToken_No_PII() {
readAccessToken(new HashSet<>(Arrays.asList(ClaimConstants.EMAIL, ClaimConstants.USER_NAME)));
}

public void readAccessToken(Set<String> excludedClaims) {
tokenServices.setExcludedClaims(excludedClaims);
AuthorizationRequest authorizationRequest =new AuthorizationRequest(CLIENT_ID, requestedAuthScopes);
authorizationRequest.setResourceIds(new HashSet<>(resourceIds));
Map<String, String> azParameters = new HashMap<>(authorizationRequest.getRequestParameters());
Expand All @@ -1650,18 +1661,27 @@ public void testReadAccessToken() {
.setExpiresAt(expiresAt.getTime())
.setStatus(ApprovalStatus.APPROVED)
.setLastUpdatedAt(updatedAt.getTime()));
Approval approval = new Approval()
.setUserId(userId)
.setClientId(CLIENT_ID)
.setScope(OPENID)
.setExpiresAt(expiresAt.getTime())
.setStatus(ApprovalStatus.APPROVED)
.setLastUpdatedAt(updatedAt.getTime());
approvalStore.addApproval(
new Approval()
.setUserId(userId)
.setClientId(CLIENT_ID)
.setScope(OPENID)
.setExpiresAt(expiresAt.getTime())
.setStatus(ApprovalStatus.APPROVED)
.setLastUpdatedAt(updatedAt.getTime()));
approval);

OAuth2Authentication authentication = new OAuth2Authentication(authorizationRequest.createOAuth2Request(), userAuthentication);
OAuth2AccessToken accessToken = tokenServices.createAccessToken(authentication);
assertEquals(accessToken, tokenServices.readAccessToken(accessToken.getValue()));

approvalStore.revokeApproval(approval);
try {
tokenServices.readAccessToken(accessToken.getValue());
fail("Approval has been revoked");
} catch (InvalidTokenException x) {
assertThat("Exception should be about approvals", x.getMessage().contains("some requested scopes are not approved"));
}
}

@Test(expected = InvalidTokenException.class)
Expand Down

0 comments on commit 57a9d0a

Please sign in to comment.