Search in sources :

Example 21 with AccessToken

use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.

the class IdTokenClaimGathererTest method mockAuthorizationApiToken.

private AccessToken mockAuthorizationApiToken() {
    AccessToken authorizationApiToken = mock(AccessToken.class);
    given(authorizationApiToken.getClientId()).willReturn("CLIENT_ID");
    return authorizationApiToken;
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken)

Example 22 with AccessToken

use of org.forgerock.oauth2.core.AccessToken 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 23 with AccessToken

use of org.forgerock.oauth2.core.AccessToken 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)

Example 24 with AccessToken

use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.

the class TokenInfoServiceImpl method getTokenInfo.

/**
     * {@inheritDoc}
     */
public JsonValue getTokenInfo(OAuth2Request request) throws InvalidTokenException, InvalidRequestException, ExpiredTokenException, ServerException, BadRequestException, InvalidGrantException, NotFoundException {
    final AccessTokenVerifier.TokenState headerToken = headerTokenVerifier.verify(request);
    final AccessTokenVerifier.TokenState queryToken = queryTokenVerifier.verify(request);
    final Map<String, Object> response = new HashMap<String, Object>();
    if (!headerToken.isValid() && !queryToken.isValid()) {
        logger.error("Access Token not valid");
        throw new InvalidRequestException("Access Token not valid");
    } else if (headerToken.isValid() && queryToken.isValid()) {
        logger.error("Access Token provided in both query and header in request");
        throw new InvalidRequestException("Access Token cannot be provided in both query and header");
    } else {
        final AccessToken accessToken = request.getToken(AccessToken.class);
        logger.trace("In Validator resource - got token = " + accessToken);
        final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
        final Map<String, Object> scopeEvaluation = providerSettings.evaluateScope(accessToken);
        response.putAll(accessToken.getTokenInfo());
        response.putAll(scopeEvaluation);
        return new JsonValue(response);
    }
}
Also used : HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) HashMap(java.util.HashMap) Map(java.util.Map) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier)

Example 25 with AccessToken

use of org.forgerock.oauth2.core.AccessToken in project OpenAM by OpenRock.

the class OAuth2AuditAccessTokenContextProvider method getTrackingIdFromAccessTokenFromRequest.

private String getTrackingIdFromAccessTokenFromRequest(Request request) {
    String trackingId = null;
    AccessToken accessToken = retrieveAccessTokenFromRequest(request);
    if (accessToken != null) {
        trackingId = getTrackingIdFromToken(accessToken);
    }
    return trackingId;
}
Also used : AccessToken(org.forgerock.oauth2.core.AccessToken)

Aggregations

AccessToken (org.forgerock.oauth2.core.AccessToken)37 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)22 Test (org.testng.annotations.Test)17 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)14 JsonValue (org.forgerock.json.JsonValue)13 Request (org.restlet.Request)12 ChallengeResponse (org.restlet.data.ChallengeResponse)10 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)9 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)7 AccessTokenVerifier (org.forgerock.oauth2.core.AccessTokenVerifier)6 Response (org.restlet.Response)6 Map (java.util.Map)5 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)5 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)5 UnauthorizedClientException (org.forgerock.oauth2.core.exceptions.UnauthorizedClientException)5 BeforeMethod (org.testng.annotations.BeforeMethod)5 HashMap (java.util.HashMap)4 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)4 InvalidTokenException (org.forgerock.oauth2.core.exceptions.InvalidTokenException)4 JSONObject (org.json.JSONObject)4