Search in sources :

Example 26 with AccessToken

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

the class OAuth2AuditAccessTokenContextProvider method getUserIdFromAccessTokenFromRequest.

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

Example 27 with AccessToken

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

the class OAuth2AuditAccessTokenContextProvider method getTrackingIdFromAccessTokenFromAuthorizationHeader.

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

Example 28 with AccessToken

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

the class AuthorizationRequestEndpoint method getAuthorisationApiToken.

protected AccessToken getAuthorisationApiToken() throws ServerException {
    Request req = getRequest();
    ChallengeResponse challengeResponse = req.getChallengeResponse();
    try {
        return oauth2TokenStore.readAccessToken(requestFactory.create(req), challengeResponse.getRawValue());
    } catch (InvalidGrantException e) {
        throw new ServerException("Unable to verify client identity.");
    } catch (NotFoundException e) {
        throw new ServerException(e.getMessage());
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Request(org.restlet.Request) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) InvalidGrantException(org.forgerock.oauth2.core.exceptions.InvalidGrantException) ChallengeResponse(org.restlet.data.ChallengeResponse)

Example 29 with AccessToken

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

the class ConnectClientRegistration method getClient.

/**
     * Handles GET requests to the OpenId Connect client registration endpoint for retrieving OpenId Connect client
     * registrations.
     *
     * @return The representation of the client registration details.
     * @throws OAuth2RestletException If an error occurs whilst retrieving the client registration.
     */
@Get
public Representation getClient() throws OAuth2RestletException {
    final OAuth2Request request = requestFactory.create(getRequest());
    final String clientId = request.getParameter(OAuth2Constants.OAuth2Client.CLIENT_ID);
    final String accessToken = getRequest().getChallengeResponse().getRawValue();
    try {
        final JsonValue registration = clientRegistrationService.getRegistration(clientId, accessToken, request);
        return jacksonRepresentationFactory.create(registration.asMap());
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) JsonValue(org.forgerock.json.JsonValue) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 30 with AccessToken

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

the class TokenEndpointResourceTest method testToken.

@Test
public void testToken() throws Exception {
    //Given
    Context context = new Context();
    Request request = new Request();
    Response response = new Response(request);
    tokenEndpointResource.init(context, request, response);
    doReturn(new AccessToken(null, OAUTH_ACCESS_TOKEN, null)).when(accessTokenService).requestAccessToken(any(OAuth2Request.class));
    //When
    tokenEndpointResource.token(new EmptyRepresentation());
    //Then
    verify(hook).afterTokenHandling(any(OAuth2Request.class), eq(request), eq(response));
}
Also used : Context(org.restlet.Context) Response(org.restlet.Response) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) EmptyRepresentation(org.restlet.representation.EmptyRepresentation) AccessToken(org.forgerock.oauth2.core.AccessToken) Request(org.restlet.Request) OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Test(org.testng.annotations.Test)

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