Search in sources :

Example 6 with OAuth2Request

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);
}
Also used : RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) BDDMockito.anyString(org.mockito.BDDMockito.anyString) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 7 with OAuth2Request

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");
}
Also used : DeviceCode(org.forgerock.oauth2.core.DeviceCode) RestletOAuth2Request(org.forgerock.oauth2.restlet.RestletOAuth2Request) Test(org.testng.annotations.Test)

Example 8 with OAuth2Request

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();
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 9 with OAuth2Request

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");
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Example 10 with OAuth2Request

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();
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) Test(org.testng.annotations.Test)

Aggregations

OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)73 Test (org.testng.annotations.Test)45 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)32 Request (org.restlet.Request)31 AccessToken (org.forgerock.oauth2.core.AccessToken)27 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)27 JsonValue (org.forgerock.json.JsonValue)24 ChallengeResponse (org.restlet.data.ChallengeResponse)17 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)13 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)11 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)11 HashMap (java.util.HashMap)10 HashSet (java.util.HashSet)10 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)10 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)10 Response (org.restlet.Response)10 ClientRegistration (org.forgerock.oauth2.core.ClientRegistration)9 OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)9 DeviceCode (org.forgerock.oauth2.core.DeviceCode)8 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8