Search in sources :

Example 16 with NotSupportedException

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

the class ServerInfoResource method readInstance.

/**
     * {@inheritDoc}
     */
public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) {
    final String realm = getRealm(context);
    debug.message("ServerInfoResource :: READ : in realm: " + realm);
    if (COOKIE_DOMAINS.equalsIgnoreCase(resourceId)) {
        return getCookieDomains();
    } else if (ALL_SERVER_INFO.equalsIgnoreCase(resourceId)) {
        return getAllServerInfo(context, realm);
    } else {
        // for now this is the only case coming in, so fail if otherwise
        final ResourceException e = new NotSupportedException("ResourceId not supported: " + resourceId);
        if (debug.errorEnabled()) {
            debug.error("ServerInfoResource :: READ : in realm: " + realm + ": Cannot receive information on requested resource: " + resourceId, e);
        }
        return e.asPromise();
    }
}
Also used : ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 17 with NotSupportedException

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

the class ResourceSetResource method actionCollection.

/**
     * "revokeAll" action supported, which will delete all a user's resource set UMA policies.
     *
     * @param context {@inheritDoc}
     * @param request {@inheritDoc}
     */
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    if ("revokeAll".equalsIgnoreCase(request.getAction())) {
        String realm = getRealm(context);
        String resourceOwnerId = getUserId(context);
        return resourceSetService.revokeAllPolicies(context, realm, resourceOwnerId).thenAsync(new AsyncFunction<Void, ActionResponse, ResourceException>() {

            @Override
            public Promise<ActionResponse, ResourceException> apply(Void value) throws ResourceException {
                return newResultPromise(newActionResponse(json(object())));
            }
        });
    } else {
        return new NotSupportedException("Action " + request.getAction() + " not supported").asPromise();
    }
}
Also used : Promises.newResultPromise(org.forgerock.util.promise.Promises.newResultPromise) Promise(org.forgerock.util.promise.Promise) ResourceException(org.forgerock.json.resource.ResourceException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) Responses.newActionResponse(org.forgerock.json.resource.Responses.newActionResponse) ActionResponse(org.forgerock.json.resource.ActionResponse)

Example 18 with NotSupportedException

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

the class IdentityResourceV1 method actionCollection.

/**
     * {@inheritDoc}
     */
@Override
public Promise<ActionResponse, ResourceException> actionCollection(final Context context, final ActionRequest request) {
    RealmContext realmContext = context.asContext(RealmContext.class);
    final String realm = realmContext.getResolvedRealm();
    RestSecurity restSecurity = restSecurityProvider.get(realm);
    final String action = request.getAction();
    if (action.equalsIgnoreCase("idFromSession")) {
        return idFromSession(context, request);
    } else if (action.equalsIgnoreCase("register")) {
        return createRegistrationEmail(context, request, realm, restSecurity);
    } else if (action.equalsIgnoreCase("confirm")) {
        return confirmationIdCheck(context, request, realm);
    } else if (action.equalsIgnoreCase("anonymousCreate")) {
        return anonymousCreate(context, request, realm, restSecurity);
    } else if (action.equalsIgnoreCase("forgotPassword")) {
        return generateNewPasswordEmail(context, request, realm, restSecurity);
    } else if (action.equalsIgnoreCase("forgotPasswordReset")) {
        return anonymousUpdate(context, request, realm);
    } else {
        // for now this is the only case coming in, so fail if otherwise
        return new NotSupportedException("Actions are not supported for resource instances").asPromise();
    }
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) RestSecurity(org.forgerock.openam.services.RestSecurity) NotSupportedException(org.forgerock.json.resource.NotSupportedException)

Example 19 with NotSupportedException

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

the class SmsRealmProvider method handleQuery.

@Override
public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    if (!"true".equals(request.getQueryFilter().toString())) {
        return new NotSupportedException("Query not supported: " + request.getQueryFilter()).asPromise();
    }
    if (request.getPagedResultsCookie() != null || request.getPagedResultsOffset() > 0 || request.getPageSize() > 0) {
        return new NotSupportedException("Query paging not currently supported").asPromise();
    }
    final String principalName = PrincipalRestUtils.getPrincipalNameFromServerContext(context);
    try {
        final SessionID sessionID = new SessionID(getUserSsoToken(context).getTokenID().toString());
        final String realmPath = coreWrapper.convertOrgNameToRealmName(sessionCache.getSession(sessionID).getClientDomain());
        final OrganizationConfigManager ocm = new OrganizationConfigManager(getUserSsoToken(context), realmPath);
        //Return realm query is being performed on
        handler.handleResource(getResource(getJsonValue(realmPath)));
        for (final Object subRealmRelativePath : ocm.getSubOrganizationNames("*", true)) {
            String realmName;
            if (realmPath.endsWith("/")) {
                realmName = realmPath + subRealmRelativePath;
            } else {
                realmName = realmPath + "/" + subRealmRelativePath;
            }
            handler.handleResource(getResource(getJsonValue(realmName)));
        }
        debug.message("RealmResource :: QUERY : performed by {}", principalName);
        return newResultPromise(newQueryResponse());
    } catch (SSOException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
        return new ForbiddenException().asPromise();
    } catch (SessionException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed : " + ex);
        return new InternalServerErrorException().asPromise();
    } catch (SMSException ex) {
        debug.error("RealmResource :: QUERY by " + principalName + " failed :" + ex);
        switch(ex.getExceptionCode()) {
            case STATUS_NO_PERMISSION:
                // This exception will be thrown if permission to read realms from SMS has not been delegated
                return new ForbiddenException().asPromise();
            default:
                return new InternalServerErrorException().asPromise();
        }
    }
}
Also used : ForbiddenException(org.forgerock.json.resource.ForbiddenException) SMSException(com.sun.identity.sm.SMSException) OrganizationConfigManager(com.sun.identity.sm.OrganizationConfigManager) SessionException(com.iplanet.dpro.session.SessionException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) SSOException(com.iplanet.sso.SSOException) NotSupportedException(org.forgerock.json.resource.NotSupportedException) SessionID(com.iplanet.dpro.session.SessionID)

Example 20 with NotSupportedException

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

the class SmsServerPropertiesResource method actionInstance.

@Override
public Promise<ActionResponse, ResourceException> actionInstance(Context serverContext, ActionRequest actionRequest) {
    if (actionRequest.getAction().equals("schema")) {
        Map<String, String> uriVariables = getUriTemplateVariables(serverContext);
        final String serverName = uriVariables.get("serverName").toLowerCase();
        if (serverName == null) {
            return new BadRequestException("Server name not specified.").asPromise();
        }
        try {
            ServiceConfigManager scm = getServiceConfigManager(serverContext);
            ServiceConfig serverConfigs = getServerConfigs(scm);
            if (!serverConfigs.getSubConfigNames().contains(serverName)) {
                return new BadRequestException("Unknown server: " + serverName).asPromise();
            }
        } catch (SSOException | SMSException e) {
            logger.error("Error getting server config", e);
        }
        final String tabName = getTabName(uriVariables);
        if (tabName == null) {
            return new BadRequestException("Tab name not specified.").asPromise();
        }
        JsonValue schema;
        final JsonPointer tabPointer = new JsonPointer("_schema/properties/" + tabName);
        if (DIRECTORY_CONFIGURATION_TAB_NAME.equalsIgnoreCase(tabName)) {
            schema = directoryConfigSchema;
        } else if (serverName.equals(SERVER_DEFAULT_NAME)) {
            schema = defaultSchema.get(tabPointer);
        } else {
            schema = nonDefaultSchema.get(tabPointer);
        }
        if (schema == null) {
            return new BadRequestException("Unknown tab: " + tabName).asPromise();
        }
        return newResultPromise(newActionResponse(schema));
    } else {
        return new NotSupportedException("Action not supported: " + actionRequest.getAction()).asPromise();
    }
}
Also used : ServiceConfig(com.sun.identity.sm.ServiceConfig) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) SSOException(com.iplanet.sso.SSOException) JsonPointer(org.forgerock.json.JsonPointer) NotSupportedException(org.forgerock.json.resource.NotSupportedException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

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