Search in sources :

Example 1 with Scope

use of org.forgerock.openam.oauth2.provider.Scope in project OpenAM by OpenRock.

the class CodeResponseType method createToken.

public CoreToken createToken(Token accessToken, Map<String, Object> data) throws NotFoundException {
    final Set<String> scope = (Set<String>) data.get(OAuth2Constants.CoreTokenParams.SCOPE);
    final OAuth2Request request = requestFactory.create(Request.getCurrent());
    final ResourceOwner resourceOwner = ownerAuthenticator.authenticate(request, true);
    final String clientId = (String) data.get(OAuth2Constants.CoreTokenParams.CLIENT_ID);
    final String redirectUri = (String) data.get(OAuth2Constants.CoreTokenParams.REDIRECT_URI);
    final String nonce = (String) data.get(OAuth2Constants.Custom.NONCE);
    final String codeChallenge = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE);
    final String codeChallengeMethod = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE_METHOD);
    try {
        final Map.Entry<String, Token> tokenEntry = handler.handle(null, scope, resourceOwner, clientId, redirectUri, nonce, request, codeChallenge, codeChallengeMethod);
        return new LegacyAuthorizationTokenAdapter((AuthorizationCode) tokenEntry.getValue());
    } catch (ServerException e) {
        throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(Request.getCurrent(), e.getMessage());
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Set(java.util.Set) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) LegacyAuthorizationTokenAdapter(org.forgerock.openam.oauth2.legacy.LegacyAuthorizationTokenAdapter) ResourceOwner(org.forgerock.oauth2.core.ResourceOwner) Token(org.forgerock.oauth2.core.Token) CoreToken(org.forgerock.openam.oauth2.legacy.CoreToken) Map(java.util.Map)

Example 2 with Scope

use of org.forgerock.openam.oauth2.provider.Scope in project OpenAM by OpenRock.

the class OpenAMOAuth2ProviderSettings method getScopeValidator.

private synchronized ScopeValidator getScopeValidator() throws ServerException {
    if (scopeValidator == null) {
        try {
            final String scopeValidatorClassName = getStringSettingValue(OAuth2ProviderService.SCOPE_PLUGIN_CLASS);
            if (isEmpty(scopeValidatorClassName)) {
                logger.message("Scope Validator class not set.");
                throw new ServerException("Scope Validator class not set.");
            }
            final Class<?> scopeValidatorClass = Class.forName(scopeValidatorClassName);
            if (Scope.class.isAssignableFrom(scopeValidatorClass)) {
                final Scope scopeClass = InjectorHolder.getInstance(scopeValidatorClass.asSubclass(Scope.class));
                return new LegacyScopeValidator(scopeClass);
            }
            scopeValidator = InjectorHolder.getInstance(scopeValidatorClass.asSubclass(ScopeValidator.class));
        } catch (ClassNotFoundException e) {
            logger.error(e.getMessage());
            throw new ServerException(e);
        }
    }
    return scopeValidator;
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) Utils.joinScope(org.forgerock.oauth2.core.Utils.joinScope) Scope(org.forgerock.openam.oauth2.provider.Scope)

Example 3 with Scope

use of org.forgerock.openam.oauth2.provider.Scope in project OpenAM by OpenRock.

the class TokenResponseType method createToken.

public CoreToken createToken(Token accessToken, Map<String, Object> data) throws NotFoundException {
    final String tokenType = (String) data.get(OAuth2Constants.CoreTokenParams.TOKEN_TYPE);
    final Set<String> scope = (Set<String>) data.get(OAuth2Constants.CoreTokenParams.SCOPE);
    final OAuth2Request request = requestFactory.create(Request.getCurrent());
    final ResourceOwner resourceOwner = ownerAuthenticator.authenticate(request, true);
    final String clientId = (String) data.get(OAuth2Constants.CoreTokenParams.CLIENT_ID);
    final String redirectUri = (String) data.get(OAuth2Constants.CoreTokenParams.REDIRECT_URI);
    final String codeChallenge = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE);
    final String codeChallengeMethod = (String) data.get(OAuth2Constants.Custom.CODE_CHALLENGE_METHOD);
    try {
        final Map.Entry<String, Token> tokenEntry = handler.handle(tokenType, scope, resourceOwner, clientId, redirectUri, null, requestFactory.create(Request.getCurrent()), codeChallenge, codeChallengeMethod);
        return new LegacyAccessTokenAdapter((AccessToken) tokenEntry.getValue());
    } catch (ServerException e) {
        throw OAuthProblemException.OAuthError.SERVER_ERROR.handle(Request.getCurrent(), e.getMessage());
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) Set(java.util.Set) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) LegacyAccessTokenAdapter(org.forgerock.openam.oauth2.legacy.LegacyAccessTokenAdapter) ResourceOwner(org.forgerock.oauth2.core.ResourceOwner) Token(org.forgerock.oauth2.core.Token) CoreToken(org.forgerock.openam.oauth2.legacy.CoreToken) AccessToken(org.forgerock.oauth2.core.AccessToken) Map(java.util.Map)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)3 Map (java.util.Map)2 Set (java.util.Set)2 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)2 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)2 Token (org.forgerock.oauth2.core.Token)2 CoreToken (org.forgerock.openam.oauth2.legacy.CoreToken)2 AccessToken (org.forgerock.oauth2.core.AccessToken)1 Utils.joinScope (org.forgerock.oauth2.core.Utils.joinScope)1 LegacyAccessTokenAdapter (org.forgerock.openam.oauth2.legacy.LegacyAccessTokenAdapter)1 LegacyAuthorizationTokenAdapter (org.forgerock.openam.oauth2.legacy.LegacyAuthorizationTokenAdapter)1 Scope (org.forgerock.openam.oauth2.provider.Scope)1