Search in sources :

Example 16 with JsonObject

use of org.forgerock.openam.utils.JsonObject 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)

Aggregations

JsonObject (org.forgerock.openam.utils.JsonObject)16 SystemProperties (com.iplanet.am.util.SystemProperties)2 Properties (java.util.Properties)2 NotFoundException (org.forgerock.json.resource.NotFoundException)2 STSPublishException (org.forgerock.openam.sts.STSPublishException)2 JsonArray (org.forgerock.openam.utils.JsonArray)2 SSOToken (com.iplanet.sso.SSOToken)1 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)1 RedirectCallback (com.sun.identity.authentication.spi.RedirectCallback)1 Date (java.util.Date)1 Locale (java.util.Locale)1 JsonValue (org.forgerock.json.JsonValue)1 BadRequestException (org.forgerock.json.resource.BadRequestException)1 AuthenticationContext (org.forgerock.openam.core.rest.authn.core.AuthenticationContext)1 RestAuthErrorCodeException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthErrorCodeException)1 RestAuthException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthException)1 RestAuthResponseException (org.forgerock.openam.core.rest.authn.exceptions.RestAuthResponseException)1 RestSTSInstanceConfig (org.forgerock.openam.sts.rest.config.user.RestSTSInstanceConfig)1 SoapSTSInstanceConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig)1