use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.
the class TokenResponseType method createToken.
public CoreToken createToken(Token accessToken, Map<String, Object> data) throws NotFoundException {
final String tokenType = (String) data.get(OAuth2Constants.CoreTokenParams.TOKEN_TYPE);
final Set<String> scope = (Set<String>) data.get(OAuth2Constants.CoreTokenParams.SCOPE);
final OAuth2Request request = requestFactory.create(Request.getCurrent());
final ResourceOwner resourceOwner = ownerAuthenticator.authenticate(request, true);
final String clientId = (String) data.get(OAuth2Constants.CoreTokenParams.CLIENT_ID);
final String redirectUri = (String) data.get(OAuth2Constants.CoreTokenParams.REDIRECT_URI);
final String codeChallenge = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE);
final String codeChallengeMethod = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE_METHOD);
try {
final Map.Entry<String, Token> tokenEntry = handler.handle(tokenType, scope, resourceOwner, clientId, redirectUri, null, requestFactory.create(Request.getCurrent()), codeChallenge, codeChallengeMethod);
return new LegacyAccessTokenAdapter((AccessToken) tokenEntry.getValue());
} catch (ServerException e) {
throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(Request.getCurrent(), e.getMessage());
}
}
use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.
the class OpenAMScopeValidatorTest method shouldReturnScopesWithoutValues.
@Test
public void shouldReturnScopesWithoutValues() throws Exception {
// given
String scopeKey1 = "mail";
String scopeKey2 = "phone";
AccessToken accessToken = mock(AccessToken.class);
when(accessToken.getScope()).thenReturn(new HashSet<>(Arrays.asList(scopeKey1, scopeKey2)));
when(accessToken.getResourceOwnerId()).thenReturn(anyString());
when(identity.getAttribute(scopeKey1)).thenReturn(Collections.emptySet());
when(identity.getAttribute(scopeKey2)).thenReturn(null);
// when
Map<String, Object> result = validator.evaluateScope(accessToken);
// then
assertThat(result).isNotNull();
assertThat(result).isNotEmpty();
assertThat(result.get(scopeKey1)).isEqualTo("");
assertThat(result.get(scopeKey2)).isEqualTo("");
}
use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.
the class OpenAMScopeValidatorTest method shouldReturnScopesWithValues.
@Test
public void shouldReturnScopesWithValues() throws Exception {
// given
String scopeKey1 = "mail";
String scopeKey2 = "phone";
String scopeValue1 = "test@example.com";
String scopeValue2 = "1234567890";
AccessToken accessToken = mock(AccessToken.class);
when(accessToken.getScope()).thenReturn(new HashSet<>(Arrays.asList(scopeKey1, scopeKey2)));
when(accessToken.getResourceOwnerId()).thenReturn(anyString());
when(identity.getAttribute(scopeKey1)).thenReturn(Collections.singleton(scopeValue1));
when(identity.getAttribute(scopeKey2)).thenReturn(Collections.singleton(scopeValue2));
// when
Map<String, Object> result = validator.evaluateScope(accessToken);
// then
assertThat(result).isNotNull();
assertThat(result).isNotEmpty();
assertThat(result.get(scopeKey1)).isEqualTo(scopeValue1);
assertThat(result.get(scopeKey2)).isEqualTo(scopeValue2);
}
use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.
the class OAuth2AuditAccessTokenContextProvider method retrieveAccessTokenFromRequest.
private AccessToken retrieveAccessTokenFromRequest(Request request) {
AccessToken token;
token = requestFactory.create(request).getToken(AccessToken.class);
return token;
}
use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.
the class OAuth2AuditAccessTokenContextProvider method getUserIdFromAccessTokenFromAuthorizationHeader.
private String getUserIdFromAccessTokenFromAuthorizationHeader(Request request) {
String userId = null;
AccessToken accessToken = retrieveAccessTokenFromChallengeResponse(request);
if (accessToken != null) {
userId = getUserIdFromToken(accessToken);
}
return userId;
}
Aggregations