Search in sources :

Example 11 with OAuth2Exception

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

the class ValidationServerResource method validate.

/**
     * Handles GET requests to the OAuth2 tokeninfo endpoint for retrieving information about the provided token.
     *
     * @return The body to be sent in the response to the user agent.
     * @throws OAuth2RestletException
     */
@Get
public Representation validate() throws OAuth2RestletException {
    logger.trace("In Validator resource");
    final OAuth2Request request = requestFactory.create(getRequest());
    try {
        final JsonValue tokenInfo = tokenInfoService.getTokenInfo(request);
        // Sets the no-store Cache-Control header
        getResponse().getCacheDirectives().add(CacheDirective.noCache());
        getResponse().getCacheDirectives().add(CacheDirective.noStore());
        return jacksonRepresentationFactory.create(tokenInfo.asMap());
    } catch (OAuth2Exception e) {
        throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) JsonValue(org.forgerock.json.JsonValue) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 12 with OAuth2Exception

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

the class OpenIDConnectConfiguration method getConfiguration.

/**
     * Handles GET requests to the OpenId Connect .well-known endpoint for retrieving the OpenId Connect provider
     * configuration.
     *
     * @return The representation of the OpenId Connect provider configuration.
     * @throws OAuth2RestletException If an error occurs whilst retrieving the OpenId Connect provider configuration.
     */
@Get
public Representation getConfiguration() throws OAuth2RestletException {
    try {
        final OAuth2Request request = requestFactory.create(getRequest());
        final JsonValue configuration = providerConfiguration.getConfiguration(request);
        return new JsonRepresentation(configuration.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) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 13 with OAuth2Exception

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

the class OpenIDConnectDiscovery method discovery.

/**
     * Handles GET requests to the OpenId Connect discovery endpoint.
     *
     * @return The representation of the OpenId Connect discovery.
     * @throws OAuth2RestletException If an error occurs whilst performing the discovery.
     */
@Get
public Representation discovery() throws OAuth2RestletException {
    final OAuth2Request request = requestFactory.create(getRequest());
    final String resource = request.getParameter("resource");
    final String rel = request.getParameter("rel");
    final String realm = request.getParameter("realm");
    try {
        final String deploymentUrl = baseUrlProviderFactory.get(realm).getRootURL(ServletUtils.getRequest(getRequest()));
        final Map<String, Object> response = providerDiscovery.discover(resource, rel, deploymentUrl, request);
        return new JsonRepresentation(response);
    } 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) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) Get(org.restlet.resource.Get)

Example 14 with OAuth2Exception

use of org.forgerock.oauth2.core.exceptions.OAuth2Exception 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 15 with OAuth2Exception

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

the class OpenIDTokenIssuer method issueToken.

/**
     * Issues an OpenId Connect token, using the details of the access token.
     *
     * @param accessToken The access token requested by the OAuth2 request.
     * @param request The OAuth2 request.
     * @return A {@code Map.Entry} of the token name with the Token instance.
     * @throws ServerException If any internal server error occurs.
     * @throws InvalidClientException If either the request does not contain the client's id or the client fails to be
     *          authenticated.
     * @throws NotFoundException If the realm does not have an OAuth 2.0 provider service.
     */
public Map.Entry<String, String> issueToken(AccessToken accessToken, OAuth2Request request) throws ServerException, InvalidClientException, NotFoundException {
    final Set<String> scope = accessToken.getScope();
    if (scope != null && scope.contains(OAuth2Constants.Params.OPENID)) {
        final ResourceOwner resourceOwner;
        try {
            request.setSession(accessToken.getSessionId());
            resourceOwner = resourceOwnerSessionValidator.validate(request);
            final String nonce = accessToken.getNonce();
            final OpenIdConnectToken openIdToken = tokenStore.createOpenIDToken(resourceOwner, accessToken.getClientId(), accessToken.getClientId(), nonce, getOps(accessToken, request), request);
            final SignedJwt signedJwt = openIdToken.sign();
            return new AbstractMap.SimpleEntry<String, String>(OAuth2Constants.JWTTokenParams.ID_TOKEN, signedJwt.build());
        } catch (SignatureException e) {
            logger.error("Unable to sign JWT", e);
            throw new ServerException("Cant sign JWT");
        } catch (OAuth2Exception e) {
            logger.error("User must be authenticated to issue ID tokens.", e);
            throw new ServerException("User must be authenticated to issue ID tokens.");
        }
    }
    return null;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) ResourceOwner(org.forgerock.oauth2.core.ResourceOwner) SignedJwt(org.forgerock.json.jose.jws.SignedJwt) SignatureException(java.security.SignatureException) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception)

Aggregations

OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)14 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)10 JsonValue (org.forgerock.json.JsonValue)6 Get (org.restlet.resource.Get)6 OAuth2RestletException (org.forgerock.oauth2.restlet.OAuth2RestletException)5 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)4 Post (org.restlet.resource.Post)4 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)3 RedirectUriMismatchException (org.forgerock.oauth2.core.exceptions.RedirectUriMismatchException)3 ResourceOwnerAuthenticationRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerAuthenticationRequired)3 ServerException (org.forgerock.oauth2.core.exceptions.ServerException)3 HashMap (java.util.HashMap)2 AuthorizationToken (org.forgerock.oauth2.core.AuthorizationToken)2 DeviceCode (org.forgerock.oauth2.core.DeviceCode)2 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)2 ResourceOwnerConsentRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerConsentRequired)2 Request (org.restlet.Request)2 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)2 Representation (org.restlet.representation.Representation)2 SignatureException (java.security.SignatureException)1