use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class OpenAMTokenStoreTest method shouldReadAccessToken.
@Test
public void shouldReadAccessToken() throws Exception {
//Given
JsonValue token = json(object(field("tokenName", Collections.singleton("access_token")), field("realm", Collections.singleton("/testrealm"))));
given(tokenStore.read("TOKEN_ID")).willReturn(token);
ConcurrentHashMap<String, Object> attributes = new ConcurrentHashMap<String, Object>();
attributes.put("realm", "/testrealm");
given(request.getAttributes()).willReturn(attributes);
given(realmNormaliser.normalise("/testrealm")).willReturn("/testrealm");
OAuth2Request request = oAuth2RequestFactory.create(this.request);
//When
AccessToken accessToken = openAMtokenStore.readAccessToken(request, "TOKEN_ID");
//Then
assertThat(accessToken).isNotNull();
assertThat(request.getToken(AccessToken.class)).isSameAs(accessToken);
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class OpenAMTokenStoreTest method shouldReadValidDeviceCode.
@Test
public void shouldReadValidDeviceCode() throws Exception {
// Given
given(tokenStore.read("123")).willReturn(json(object(field("tokenName", asSet("device_code")), field("id", asSet("123")), field("user_code", asSet("456")), field("realm", asSet("/")), field("clientID", asSet("CLIENT_ID")))));
final RestletOAuth2Request oauth2Request = oAuth2RequestFactory.create(this.request);
given(request.getAttributes()).willReturn(new ConcurrentHashMap<>(singletonMap("realm", (Object) "/")));
given(realmNormaliser.normalise("/")).willReturn("/");
// When
DeviceCode code = openAMtokenStore.readDeviceCode("CLIENT_ID", "123", oauth2Request);
// Then
assertThat(code.getTokenId()).isEqualTo("123");
assertThat(code.getUserCode()).isEqualTo("456");
assertThat(code.getClientId()).isEqualTo("CLIENT_ID");
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class IdTokenClaimGathererTest method shouldNotGatherIdTokenClaimTokenWhichIsIncorrectlySigned.
@Test
public void shouldNotGatherIdTokenClaimTokenWhichIsIncorrectlySigned() {
//Given
AccessToken authorizationApiToken = mockAuthorizationApiToken();
JsonValue claimToken = mockInvalidIdTokenClaimToken("ISSUER");
setIdTokenAndOAuth2ProviderIssuers("ISSUER");
//When
String requestingPartyId = claimGatherer.getRequestingPartyId(oAuth2Request, authorizationApiToken, claimToken);
//Then
assertThat(requestingPartyId).isNull();
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class IdTokenClaimGathererTest method shouldGatherValidIdTokenClaimToken.
@Test
public void shouldGatherValidIdTokenClaimToken() {
//Given
AccessToken authorizationApiToken = mockAuthorizationApiToken();
JsonValue claimToken = mockIdTokenClaimToken("ISSUER");
setIdTokenAndOAuth2ProviderIssuers("ISSUER");
//When
String requestingPartyId = claimGatherer.getRequestingPartyId(oAuth2Request, authorizationApiToken, claimToken);
//Then
assertThat(requestingPartyId).isEqualTo("REQUESTING_PARTY_ID");
}
use of org.forgerock.oauth2.core.OAuth2Request in project OpenAM by OpenRock.
the class IdTokenClaimGathererTest method shouldNotGatherIdTokenClaimTokenWithIncorrectIssuer.
@Test
public void shouldNotGatherIdTokenClaimTokenWithIncorrectIssuer() {
//Given
AccessToken authorizationApiToken = mockAuthorizationApiToken();
JsonValue claimToken = mockIdTokenClaimToken("OTHER_ISSUER");
setIdTokenAndOAuth2ProviderIssuers("ISSUER");
//When
String requestingPartyId = claimGatherer.getRequestingPartyId(oAuth2Request, authorizationApiToken, claimToken);
//Then
assertThat(requestingPartyId).isNull();
}
Aggregations