Search in sources :

Example 1 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class PendingRequestResource method queryCollection.

@Override
public Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (request.getQueryFilter() == null) {
        return new NotSupportedException("Only query filter is supported.").asPromise();
    }
    try {
        List<ResourceResponse> values = new ArrayList<>();
        // Filter items based on query filter.
        for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
            if (request.getQueryFilter().accept(QUERY_VISITOR, pendingRequest.asJson())) {
                values.add(newResourceResponse(pendingRequest.getId(), null, pendingRequest.asJson()));
            }
        }
        // Sort and Page for presentation
        QueryResponsePresentation.enableDeprecatedRemainingQueryResponse(request);
        return QueryResponsePresentation.perform(handler, request, values);
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ArrayList(java.util.ArrayList) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 2 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class PendingRequestResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    try {
        if (APPROVE_ACTION_ID.equalsIgnoreCase(request.getAction())) {
            List<Promise<Void, ResourceException>> promises = new ArrayList<>();
            JsonValue content = request.getContent();
            for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
                promises.add(service.approvePendingRequest(context, pendingRequest.getId(), content.get(pendingRequest.getId()), ServerContextUtils.getRealm(context)));
            }
            return handlePendingRequestApproval(promises);
        } else if (DENY_ACTION_ID.equalsIgnoreCase(request.getAction())) {
            for (UmaPendingRequest pendingRequest : queryResourceOwnerPendingRequests(context)) {
                service.denyPendingRequest(pendingRequest.getId(), ServerContextUtils.getRealm(context));
            }
            return newResultPromise(newActionResponse((json(object()))));
        } else {
            return new NotSupportedException("Action, " + request.getAction() + ", is not supported.").asPromise();
        }
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : Promise(org.forgerock.util.promise.Promise) ArrayList(java.util.ArrayList) JsonValue(org.forgerock.json.JsonValue) UmaPendingRequest(org.forgerock.openam.sm.datalayer.impl.uma.UmaPendingRequest) ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 3 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class UmaEnabledFilter method enabled.

private Promise<Void, ResourceException> enabled(Context serverContext) {
    try {
        String realm = RealmContext.getRealm(serverContext);
        UmaProviderSettings settings = umaProviderSettingsFactory.get(realm);
        if (settings.isEnabled()) {
            return newResultPromise(null);
        }
    } catch (NotFoundException ignore) {
    }
    return new NotSupportedException("UMA is not currently supported in this realm").asPromise();
}
Also used : UmaProviderSettings(org.forgerock.openam.uma.UmaProviderSettings) NotFoundException(org.forgerock.oauth2.core.exceptions.NotFoundException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 4 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class PolicyResource method actionCollection.

/**
     * {@inheritDoc}
     */
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest actionRequest) {
    final String actionString = actionRequest.getAction();
    final PolicyAction action = PolicyAction.getAction(actionString);
    if (!PolicyAction.isEvaluateAction(action)) {
        final String errorMsg = "Action '" + actionString + "' not implemented for this resource";
        final NotSupportedException nsE = new NotSupportedException(errorMsg);
        DEBUG.error(errorMsg, nsE);
        return nsE.asPromise();
    }
    try {
        if (DEBUG.messageEnabled()) {
            DEBUG.message("Rendering policy request for action " + actionString);
        }
        final PolicyRequest request = requestFactory.buildRequest(action, context, actionRequest);
        final PolicyEvaluator evaluator = factory.getEvaluator(request.getRestSubject(), request.getApplication());
        if (DEBUG.messageEnabled()) {
            final StringBuilder builder = new StringBuilder();
            builder.append("Evaluating policy request for action ");
            builder.append(actionString);
            builder.append(" under realm ");
            builder.append(request.getRealm());
            builder.append(" within the application context ");
            builder.append(request.getApplication());
            DEBUG.message(builder.toString());
        }
        final List<Entitlement> entitlements = evaluator.routePolicyRequest(request);
        return newResultPromise(newActionResponse(policyParser.printEntitlements(entitlements)));
    } catch (final EntitlementException eE) {
        DEBUG.error("Error evaluating policy request", eE);
        return resourceErrorHandler.handleError(context, actionRequest, eE).asPromise();
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) Entitlement(com.sun.identity.entitlement.Entitlement) PolicyRequest(org.forgerock.openam.entitlement.rest.model.json.PolicyRequest)

Example 5 with NotSupportedException

use of org.forgerock.json.resource.NotSupportedException in project OpenAM by OpenRock.

the class ScriptResource method actionCollection.

@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    if ("validate".equals(request.getAction())) {
        try {
            JsonValue json = request.getContent();
            SupportedScriptingLanguage language = getLanguageFromString(json.get(SCRIPT_LANGUAGE).asString());
            String script = json.get(SCRIPT_TEXT).asString();
            if (script == null) {
                throw new ScriptException(MISSING_SCRIPT);
            }
            List<ScriptError> scriptErrorList = scriptValidator.validateScript(new ScriptObject(EMPTY, decodeScript(script), language, null));
            if (scriptErrorList.isEmpty()) {
                return newResultPromise(newActionResponse(json(object(field("success", true)))));
            }
            Set<Object> errors = new HashSet<>();
            for (ScriptError error : scriptErrorList) {
                errors.add(object(field("line", error.getLineNumber()), field("column", error.getColumnNumber()), field("message", error.getMessage())));
            }
            return newResultPromise(newActionResponse(json(object(field("success", false), field("errors", errors)))));
        } catch (ScriptException se) {
            return exceptionMappingHandler.handleError(context, request, se).asPromise();
        }
    } else {
        return new NotSupportedException().asPromise();
    }
}
Also used : ScriptException(org.forgerock.openam.scripting.ScriptException) ScriptObject(org.forgerock.openam.scripting.ScriptObject) ScriptError(org.forgerock.openam.scripting.ScriptError) JsonValue(org.forgerock.json.JsonValue) ScriptObject(org.forgerock.openam.scripting.ScriptObject) SupportedScriptingLanguage(org.forgerock.openam.scripting.SupportedScriptingLanguage) NotSupportedException(org.forgerock.json.resource.NotSupportedException) HashSet(java.util.HashSet)

Aggregations

NotSupportedException (org.forgerock.json.resource.NotSupportedException)21 JsonValue (org.forgerock.json.JsonValue)11 SSOException (com.iplanet.sso.SSOException)8 SMSException (com.sun.identity.sm.SMSException)8 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)8 ResourceException (org.forgerock.json.resource.ResourceException)7 BadRequestException (org.forgerock.json.resource.BadRequestException)5 RealmContext (org.forgerock.openam.rest.RealmContext)4 IdRepoException (com.sun.identity.idm.IdRepoException)3 ArrayList (java.util.ArrayList)3 ForbiddenException (org.forgerock.json.resource.ForbiddenException)3 SSOToken (com.iplanet.sso.SSOToken)2 AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)2 AMConfigurationException (com.sun.identity.authentication.config.AMConfigurationException)2 ServiceConfig (com.sun.identity.sm.ServiceConfig)2 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)2 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)2 ServiceSchemaManager (com.sun.identity.sm.ServiceSchemaManager)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 MessagingException (javax.mail.MessagingException)2