Search in sources :

Example 41 with BadRequestException

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

the class SitesResourceProvider method updateInstance.

@Override
public Promise<ResourceResponse, ResourceException> updateInstance(Context context, String id, UpdateRequest request) {
    JsonValue content = request.getContent();
    try {
        validWriteOperation(content, id);
    } catch (BadRequestException e) {
        return e.asPromise();
    }
    ResourceResponse site;
    SSOToken token;
    try {
        token = getSsoToken(context);
        site = getSite(token, id);
    } catch (SMSException | SSOException | ConfigurationException e) {
        debug.error("Could not read site {}", id, e);
        return new InternalServerErrorException("Could not read site").asPromise();
    } catch (NotFoundException e) {
        return e.asPromise();
    }
    try {
        if (!site.getRevision().equals(request.getRevision())) {
            return new PreconditionFailedException("Revision did not match").asPromise();
        }
        SiteConfiguration.setSitePrimaryURL(token, id, content.get("url").asString());
        SiteConfiguration.setSiteSecondaryURLs(token, id, content.get("secondaryURLs").asSet());
        return newResultPromise(getSite(token, id));
    } catch (SSOException | SMSException | ConfigurationException e) {
        debug.error("Could not update site {}", id, e);
        return new InternalServerErrorException("Could not update site").asPromise();
    } catch (NotFoundException e) {
        return new InternalServerErrorException("Could not read site after just updating it", e).asPromise();
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SMSException(com.sun.identity.sm.SMSException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) NotFoundException(org.forgerock.json.resource.NotFoundException) SSOException(com.iplanet.sso.SSOException) PreconditionFailedException(org.forgerock.json.resource.PreconditionFailedException)

Example 42 with BadRequestException

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

the class SmsCollectionProvider method createInstance.

/**
     * Creates a new child instance of config. The parent config referenced by the request path is found, and
     * new config is created using the provided name property.
     * {@inheritDoc}
     */
@Override
public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) {
    JsonValue content = request.getContent();
    final String realm = realmFor(context);
    try {
        Map<String, Set<String>> attrs = converter.fromJson(realm, content);
        ServiceConfigManager scm = getServiceConfigManager(context);
        ServiceConfig config = parentSubConfigFor(context, scm);
        String name = content.get("_id").asString();
        if (name == null) {
            name = request.getNewResourceId();
        } else if (request.getNewResourceId() != null && !name.equals(request.getNewResourceId())) {
            return new BadRequestException("name and URI's resource ID do not match").asPromise();
        }
        if (name == null) {
            return new BadRequestException("Invalid name").asPromise();
        }
        config.addSubConfig(name, lastSchemaNodeName(), 0, attrs);
        final ServiceConfig created = checkedInstanceSubConfig(context, name, config);
        return awaitCreation(context, name).then(new Function<Void, ResourceResponse, ResourceException>() {

            @Override
            public ResourceResponse apply(Void aVoid) {
                JsonValue result = getJsonValue(realm, created);
                return newResourceResponse(created.getName(), String.valueOf(result.hashCode()), result);
            }
        });
    } catch (ServiceAlreadyExistsException e) {
        debug.warning("::SmsCollectionProvider:: ServiceAlreadyExistsException on create", e);
        return new ConflictException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SMSException e) {
        debug.warning("::SmsCollectionProvider:: SMSException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (SSOException e) {
        debug.warning("::SmsCollectionProvider:: SSOException on create", e);
        return new InternalServerErrorException("Unable to create SMS config: " + e.getMessage()).asPromise();
    } catch (ResourceException e) {
        return e.asPromise();
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) ConflictException(org.forgerock.json.resource.ConflictException) SMSException(com.sun.identity.sm.SMSException) JsonValue(org.forgerock.json.JsonValue) SSOException(com.iplanet.sso.SSOException) ServiceAlreadyExistsException(com.sun.identity.sm.ServiceAlreadyExistsException) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ServiceConfig(com.sun.identity.sm.ServiceConfig) BadRequestException(org.forgerock.json.resource.BadRequestException) InternalServerErrorException(org.forgerock.json.resource.InternalServerErrorException) ResourceException(org.forgerock.json.resource.ResourceException) ServiceConfigManager(com.sun.identity.sm.ServiceConfigManager)

Example 43 with BadRequestException

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

the class SessionResource method actionCollection.

/**
     * Actions supported are:
     * <ul>
     * <li>{@link #LOGOUT_ACTION_ID}</li>
     * <li>{@link #VALIDATE_ACTION_ID}</li>
     * <li>{@link #IS_ACTIVE_ACTION_ID}</li>
     * <li>{@link #GET_MAX_TIME_ACTION_ID}</li>
     * <li>{@link #GET_IDLE_ACTION_ID}</li>
     * </ul>
     *
     * @param context {@inheritDoc}
     * @param request {@inheritDoc}
     */
public Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request) {
    final String cookieName = SystemProperties.get(Constants.AM_COOKIE_NAME, "iPlanetDirectoryPro");
    String tokenId = getTokenIdFromUrlParam(request);
    if (tokenId == null) {
        tokenId = getTokenIdFromHeader(context, cookieName);
    }
    if (tokenId == null) {
        tokenId = getTokenIdFromCookie(context, cookieName);
    }
    // code will have to be moved/changed.
    if (tokenId == null) {
        final BadRequestException e = new BadRequestException("iPlanetDirectoryCookie not set on request");
        LOGGER.message("SessionResource.handleNullSSOToken :: iPlanetDirectoryCookie not set on request", e);
        return e.asPromise();
    }
    return internalHandleAction(tokenId, context, request);
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException)

Example 44 with BadRequestException

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

the class RecordResource method actionStop.

/**
     * Stop action
     *
     * @return
     */
private Promise<ActionResponse, ResourceException> actionStop() {
    try {
        Record record = debugRecorder.stopRecording();
        if (record == null) {
            return new BadRequestException("No record or it's already stopped.").asPromise();
        } else {
            JsonObject result = JsonValueBuilder.jsonValue();
            result.put(STATUS_LABEL, false);
            result.put(RECORD_LABEL, record.exportJson().asMap());
            return newResultPromise(newActionResponse(result.build()));
        }
    } catch (RecordException e) {
        debug.message("Record can't be stopped.", e);
        return new BadRequestException("Record can't be stopped.", e).asPromise();
    }
}
Also used : BadRequestException(org.forgerock.json.resource.BadRequestException) JsonObject(org.forgerock.openam.utils.JsonObject)

Example 45 with BadRequestException

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

the class SoapSTSPublishServiceRequestHandler method handleQuery.

public Promise<QueryResponse, ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler) {
    QueryFilter<JsonPointer> queryFilter = request.getQueryFilter();
    if (queryFilter == null) {
        return new BadRequestException(getQueryUsageString()).asPromise();
    }
    String realm;
    try {
        realm = getRealmFromQueryFilter(queryFilter);
    } catch (STSPublishException e) {
        return e.asPromise();
    }
    try {
        if (!realmValidator.isRealm(realm)) {
            return new BadRequestException("The specified realm does not exist.").asPromise();
        }
        final List<SoapSTSInstanceConfig> publishedInstances = publisher.getPublishedInstances(realm);
        for (SoapSTSInstanceConfig instanceConfig : publishedInstances) {
            /*
                Although instanceConfig.toJson() will yield the JsonValue which the handleResource invocation requires,
                the SoapSTSInstanceConfig is a complicated nesting of JsonValue objects, which should be 'homogenized'
                into a json format prior to inclusion in the response.
                 */
            handler.handleResource(newResourceResponse(instanceConfig.getDeploymentSubPath(), getInstanceConfigEtag(instanceConfig), new JsonValue(mapStringToJson(instanceConfig.toJson().toString()))));
        }
        return newResultPromise(newQueryResponse());
    } catch (STSPublishException e) {
        logger.error("Exception caught obtaining soap sts instances for realm " + (realm != null ? realm : "null realm") + "; Exception: " + e);
        return e.asPromise();
    }
}
Also used : SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) STSPublishException(org.forgerock.openam.sts.STSPublishException) JsonValue(org.forgerock.json.JsonValue) BadRequestException(org.forgerock.json.resource.BadRequestException) JsonPointer(org.forgerock.json.JsonPointer)

Aggregations

BadRequestException (org.forgerock.json.resource.BadRequestException)82 JsonValue (org.forgerock.json.JsonValue)44 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)40 ResourceException (org.forgerock.json.resource.ResourceException)39 SSOException (com.iplanet.sso.SSOException)37 NotFoundException (org.forgerock.json.resource.NotFoundException)37 SMSException (com.sun.identity.sm.SMSException)31 ForbiddenException (org.forgerock.json.resource.ForbiddenException)26 ResourceResponse (org.forgerock.json.resource.ResourceResponse)25 IdRepoException (com.sun.identity.idm.IdRepoException)23 PermanentException (org.forgerock.json.resource.PermanentException)22 ConflictException (org.forgerock.json.resource.ConflictException)21 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)20 SSOToken (com.iplanet.sso.SSOToken)19 NotSupportedException (org.forgerock.json.resource.NotSupportedException)17 RealmContext (org.forgerock.openam.rest.RealmContext)17 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)16 DeleteFailedException (org.forgerock.openam.cts.exceptions.DeleteFailedException)16 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)14 MessagingException (javax.mail.MessagingException)13