Search in sources :

Example 81 with ServerException

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

the class OpenAMOAuth2UrisFactory method get.

@Override
public OAuth2Uris get(HttpServletRequest request, RealmInfo realmInfo) throws NotFoundException, ServerException {
    String absoluteRealm = realmInfo.getAbsoluteRealm();
    BaseURLProvider baseURLProvider = baseURLProviderFactory.get(absoluteRealm);
    String baseUrl;
    try {
        baseUrl = baseURLProvider.getRealmURL(request, "/oauth2", absoluteRealm);
    } catch (InvalidBaseUrlException e) {
        throw new ServerException("Configuration error");
    }
    return get(absoluteRealm, baseUrl);
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) InvalidBaseUrlException(org.forgerock.openam.services.baseurl.InvalidBaseUrlException) BaseURLProvider(org.forgerock.openam.services.baseurl.BaseURLProvider)

Example 82 with ServerException

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

the class OpenAMOAuth2ProviderSettings method getAllowedResponseTypes.

/**
     * {@inheritDoc}
     */
public Map<String, ResponseTypeHandler> getAllowedResponseTypes() throws UnsupportedResponseTypeException, ServerException {
    try {
        Set<String> responseTypeSet = getSetting(realm, OAuth2ProviderService.RESPONSE_TYPE_LIST);
        if (responseTypeSet == null || responseTypeSet.isEmpty()) {
            return Collections.emptyMap();
        }
        Map<String, ResponseTypeHandler> responseTypes = new HashMap<String, ResponseTypeHandler>();
        for (String responseType : responseTypeSet) {
            String[] parts = responseType.split("\\|");
            if (parts.length != 2) {
                logger.error("Response type wrong format for realm: " + realm);
                continue;
            }
            responseTypes.put(parts[0], wrap(parts[0], parts[1]));
        }
        return responseTypes;
    } catch (SMSException e) {
        logger.error(e.getMessage());
        throw new ServerException(e);
    } catch (SSOException e) {
        logger.error(e.getMessage());
        throw new ServerException(e);
    }
}
Also used : NoneResponseTypeHandler(org.forgerock.oauth2.core.NoneResponseTypeHandler) LegacyResponseTypeHandler(org.forgerock.openam.oauth2.legacy.LegacyResponseTypeHandler) ResponseTypeHandler(org.forgerock.oauth2.core.ResponseTypeHandler) ServerException(org.forgerock.oauth2.core.exceptions.ServerException) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException)

Example 83 with ServerException

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

the class OpenAMOAuth2ProviderSettings method getAcrMapping.

@Override
public Map<String, AuthenticationMethod> getAcrMapping() throws ServerException {
    try {
        final Map<String, String> map = getMapSetting(realm, OAuth2ProviderService.ACR_VALUE_MAPPING);
        final Map<String, AuthenticationMethod> methods = new HashMap<String, AuthenticationMethod>(map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            methods.put(entry.getKey(), new OpenAMAuthenticationMethod(entry.getValue(), AuthContext.IndexType.SERVICE));
        }
        return methods;
    } catch (SSOException e) {
        logger.message(e.getMessage());
        throw new ServerException(e);
    } catch (SMSException e) {
        logger.message(e.getMessage());
        throw new ServerException(e);
    }
}
Also used : ServerException(org.forgerock.oauth2.core.exceptions.ServerException) HashMap(java.util.HashMap) SMSException(com.sun.identity.sm.SMSException) SSOException(com.iplanet.sso.SSOException) AuthenticationMethod(org.forgerock.oauth2.core.AuthenticationMethod) Map(java.util.Map) HashMap(java.util.HashMap)

Example 84 with ServerException

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

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

the class OpenAMOAuth2ProviderSettings method validateRequestedClaims.

@Override
public String validateRequestedClaims(String requestedClaims) throws InvalidRequestException, ServerException {
    if (!getClaimsParameterSupported()) {
        return null;
    }
    if (StringUtils.isBlank(requestedClaims)) {
        return null;
    }
    final Set<String> claims = new HashSet<String>();
    try {
        JSONObject json = new JSONObject(requestedClaims);
        JSONObject userinfo = json.optJSONObject(OAuth2Constants.UserinfoEndpoint.USERINFO);
        JSONObject id_token = json.optJSONObject(OAuth2Constants.JWTTokenParams.ID_TOKEN);
        if (userinfo != null) {
            Iterator<String> it = userinfo.keys();
            while (it.hasNext()) {
                claims.add(it.next());
            }
        }
        if (id_token != null) {
            Iterator<String> it = id_token.keys();
            while (it.hasNext()) {
                claims.add(it.next());
            }
        }
    } catch (JSONException e) {
        throw new InvalidRequestException("Requested claims must be valid json.");
    }
    if (!getSupportedClaims().containsAll(claims)) {
        throw new InvalidRequestException("Requested claims must be allowed by the client's configuration");
    }
    return requestedClaims;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) InvalidRequestException(org.forgerock.oauth2.core.exceptions.InvalidRequestException) HashSet(java.util.HashSet)

Aggregations

ServerException (org.forgerock.oauth2.core.exceptions.ServerException)60 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)31 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)25 JsonValue (org.forgerock.json.JsonValue)18 NotFoundException (org.forgerock.oauth2.core.exceptions.NotFoundException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)18 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)14 HashMap (java.util.HashMap)13 AccessToken (org.forgerock.oauth2.core.AccessToken)13 HashSet (java.util.HashSet)12 InvalidGrantException (org.forgerock.oauth2.core.exceptions.InvalidGrantException)11 ResourceSetStore (org.forgerock.oauth2.resources.ResourceSetStore)11 SSOException (com.iplanet.sso.SSOException)9 Request (org.restlet.Request)9 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)8 Map (java.util.Map)7 OAuth2Uris (org.forgerock.oauth2.core.OAuth2Uris)7 JSONObject (org.json.JSONObject)7 SMSException (com.sun.identity.sm.SMSException)6 ResourceOwner (org.forgerock.oauth2.core.ResourceOwner)6