Search in sources :

Example 46 with NotFoundException

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

the class SitesResourceProvider method getSite.

protected ResourceResponse getSite(SSOToken token, String siteName) throws SMSException, SSOException, ConfigurationException, NotFoundException {
    if (!SiteConfiguration.isSiteExist(token, siteName)) {
        throw new NotFoundException();
    }
    JsonValue site = json(object(field("_id", siteName), field("id", SiteConfiguration.getSiteID(token, siteName)), field("url", SiteConfiguration.getSitePrimaryURL(token, siteName)), field("secondaryURLs", SiteConfiguration.getSiteSecondaryURLs(token, siteName)), field("servers", array())));
    JsonValue servers = site.get("servers");
    for (String server : SiteConfiguration.listServers(token, siteName)) {
        servers.add(object(field("id", ServerConfiguration.getServerID(token, server)), field("url", server)));
    }
    return newResourceResponse(siteName, String.valueOf(site.getObject().hashCode()), site);
}
Also used : JsonValue(org.forgerock.json.JsonValue) NotFoundException(org.forgerock.json.resource.NotFoundException)

Example 47 with NotFoundException

use of org.forgerock.json.resource.NotFoundException 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 48 with NotFoundException

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

the class RestSTSPublishServiceRequestHandler method handleRead.

public Promise<ResourceResponse, ResourceException> handleRead(Context context, ReadRequest request) {
    try {
        if (EMPTY_STRING.equals(request.getResourcePath())) {
            List<RestSTSInstanceConfig> publishedInstances = publisher.getPublishedInstances();
            JsonObject jsonObject = JsonValueBuilder.jsonValue();
            for (RestSTSInstanceConfig instanceConfig : publishedInstances) {
                jsonObject.put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString()));
            }
            /*
                Note that the revision etag is not set, as this is not a resource which should really be cached.
                If caching becomes necessary, a string composed of the hash codes of each of the RestSTSInstanceConfig
                instances could be used (or a hash of that string).
                 */
            return newResultPromise(newResourceResponse(PUBLISHED_INSTANCES, EMPTY_STRING, jsonObject.build()));
        } else {
            final String realm = getRealmFromResourceName(request.getResourcePath());
            if (!realmValidator.isRealm(realm)) {
                logger.warn("Read of rest STS instance state for instance " + request.getResourcePath() + " in realm " + realm + " rejected because realm does not exist");
                return new NotFoundException("The specified realm does not exist.").asPromise();
            }
            RestSTSInstanceConfig instanceConfig = publisher.getPublishedInstance(request.getResourcePath(), realm);
            return newResultPromise(newResourceResponse(instanceConfig.getDeploymentSubPath(), Integer.toString(instanceConfig.hashCode()), JsonValueBuilder.jsonValue().put(instanceConfig.getDeploymentSubPath(), mapStringToJson(instanceConfig.toJson().toString())).build()));
        }
    } catch (STSPublishException e) {
        String message = "Exception caught obtaining rest sts instance corresponding to id: " + request.getResourcePath() + "; Exception: " + e;
        logger.error(message, e);
        return e.asPromise();
    }
}
Also used : RestSTSInstanceConfig(org.forgerock.openam.sts.rest.config.user.RestSTSInstanceConfig) STSPublishException(org.forgerock.openam.sts.STSPublishException) JsonObject(org.forgerock.openam.utils.JsonObject) NotFoundException(org.forgerock.json.resource.NotFoundException)

Example 49 with NotFoundException

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

the class SoapSTSPublishServiceRequestHandler method handleUpdate.

/*
     * A PUT to the url composed of the publish endpont + the sts instance id with a payload corresponding to a
     * SoapSTSInstanceId (wrapped in invocation context information) will result in republishing the existing instance
     * (which is a delete followed by a create).
     */
public Promise<ResourceResponse, ResourceException> handleUpdate(Context context, UpdateRequest request) {
    String stsId = request.getResourcePath();
    String realm = getRealmFromResourceName(request.getResourcePath());
    if (!realmValidator.isRealm(realm)) {
        logger.warn("Update of soap STS instance state for instance " + stsId + " in realm " + realm + " rejected because realm does not exist");
        return new NotFoundException("The specified realm does not exist.").asPromise();
    }
    /*
        Insure that the instance is published before performing an update.
         */
    final boolean publishedToSMS;
    try {
        publishedToSMS = (publisher.getPublishedInstance(stsId, realm) != null);
    } catch (STSPublishException e) {
        logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught determining whether " + "instance persisted in SMS. Instance not updated. Exception: " + e, e);
        return e.asPromise();
    }
    if (publishedToSMS) {
        SoapSTSInstanceConfig instanceConfig;
        try {
            instanceConfig = marshalInstanceConfigFromInvocation(request.getContent());
        } catch (BadRequestException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught marshalling " + "invocation state to SoapSTSInstanceConfig. Instance not updated. The state: " + request.getContent() + "Exception: " + e, e);
            return e.asPromise();
        }
        try {
            publisher.removeInstance(stsId, realm);
        } catch (STSPublishException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught removing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, and has not been updated. The instance config: " + instanceConfig + "; Exception: " + e, e);
            return e.asPromise();
        }
        try {
            ResourceResponse response = publishInstance(instanceConfig);
            logger.info("Soap STS instance " + instanceConfig.getDeploymentSubPath() + " updated to state " + instanceConfig.toJson());
            return newResultPromise(response);
        } catch (ResourceException e) {
            logger.error("In SoapSTSPublishServiceRequestHandler#handleUpdate, exception caught publishing " + "soap sts instance " + instanceConfig.getDeploymentSubPath() + ". This means instance is" + "in indeterminate state, having been removed, but not successfully published with updated " + "state. The instance config: " + instanceConfig + "; Exception: " + e, e);
            return e.asPromise();
        }
    } else {
        //404 - realm and id not found in SMS
        return new NotFoundException("No soap sts instance with id " + stsId + " in realm " + realm).asPromise();
    }
}
Also used : SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) STSPublishException(org.forgerock.openam.sts.STSPublishException) NotFoundException(org.forgerock.json.resource.NotFoundException) BadRequestException(org.forgerock.json.resource.BadRequestException) ResourceException(org.forgerock.json.resource.ResourceException)

Example 50 with NotFoundException

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

the class UmaPolicyServiceImpl method internalReadPolicy.

/**
     * {@inheritDoc}
     */
private Promise<UmaPolicy, ResourceException> internalReadPolicy(final Context context, final String resourceSetId) {
    String resourceOwnerUid = getResourceOwnerUid(context);
    QueryRequest request = Requests.newQueryRequest("").setQueryFilter(QueryFilter.and(QueryFilter.equalTo(new JsonPointer("resourceTypeUuid"), resourceSetId), QueryFilter.equalTo(new JsonPointer("createdBy"), resourceOwnerUid)));
    return policyResourceDelegate.queryPolicies(context, request).thenAsync(new AsyncFunction<Pair<QueryResponse, List<ResourceResponse>>, UmaPolicy, ResourceException>() {

        @Override
        public Promise<UmaPolicy, ResourceException> apply(Pair<QueryResponse, List<ResourceResponse>> value) {
            try {
                if (value.getSecond().isEmpty()) {
                    return new NotFoundException("UMA Policy not found, " + resourceSetId).asPromise();
                } else {
                    ResourceSetDescription resourceSet = getResourceSet(getRealm(context), resourceSetId);
                    UmaPolicy umaPolicy = UmaPolicy.fromUnderlyingPolicies(resourceSet, value.getSecond());
                    return newResultPromise(umaPolicy);
                }
            } catch (ResourceException e) {
                return e.asPromise();
            }
        }
    });
}
Also used : QueryRequest(org.forgerock.json.resource.QueryRequest) NotFoundException(org.forgerock.json.resource.NotFoundException) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) Promise(org.forgerock.util.promise.Promise) ResourceResponse(org.forgerock.json.resource.ResourceResponse) Responses.newQueryResponse(org.forgerock.json.resource.Responses.newQueryResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) List(java.util.List) ArrayList(java.util.ArrayList) UmaPolicy(org.forgerock.openam.uma.UmaPolicy) Pair(org.forgerock.util.Pair)

Aggregations

NotFoundException (org.forgerock.json.resource.NotFoundException)69 ResourceException (org.forgerock.json.resource.ResourceException)43 SSOException (com.iplanet.sso.SSOException)42 JsonValue (org.forgerock.json.JsonValue)39 InternalServerErrorException (org.forgerock.json.resource.InternalServerErrorException)39 BadRequestException (org.forgerock.json.resource.BadRequestException)38 SMSException (com.sun.identity.sm.SMSException)34 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 ForbiddenException (org.forgerock.json.resource.ForbiddenException)26 IdRepoException (com.sun.identity.idm.IdRepoException)24 PermanentException (org.forgerock.json.resource.PermanentException)24 ConflictException (org.forgerock.json.resource.ConflictException)22 ServiceNotFoundException (com.sun.identity.sm.ServiceNotFoundException)21 NotSupportedException (org.forgerock.json.resource.NotSupportedException)18 CoreTokenException (org.forgerock.openam.cts.exceptions.CoreTokenException)17 IdentityDetails (com.sun.identity.idsvcs.IdentityDetails)16 RealmContext (org.forgerock.openam.rest.RealmContext)16 SSOToken (com.iplanet.sso.SSOToken)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 MessagingException (javax.mail.MessagingException)14