Search in sources :

Example 16 with OAuth2Exception

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

the class UserInfoServiceImpl method getUserInfo.

/**
     * {@inheritDoc}
     */
public JsonValue getUserInfo(OAuth2Request request) throws OAuth2Exception {
    AccessTokenVerifier.TokenState headerToken = headerTokenVerifier.verify(request);
    AccessTokenVerifier.TokenState formToken = formTokenVerifier.verify(request);
    if (!headerToken.isValid() && !formToken.isValid()) {
        logger.debug("No access token provided for this request.");
        throw new InvalidTokenException();
    }
    if (headerToken.isValid() && formToken.isValid()) {
        logger.debug("Access token provided in both form and header.");
        throw new ServerException("Access Token cannot be provided in both form and header");
    }
    final String tokenId = headerToken.isValid() ? headerToken.getTokenId() : formToken.getTokenId();
    final AccessToken token = tokenStore.readAccessToken(request, tokenId);
    final OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
    return new JsonValue(providerSettings.getUserInfo(token, request).getValues());
}
Also used : InvalidTokenException(org.forgerock.oauth2.core.exceptions.InvalidTokenException) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) AccessToken(org.forgerock.oauth2.core.AccessToken) JsonValue(org.forgerock.json.JsonValue) OAuth2ProviderSettings(org.forgerock.oauth2.core.OAuth2ProviderSettings) AccessTokenVerifier(org.forgerock.oauth2.core.AccessTokenVerifier)

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