Search in sources :

Example 16 with STSPublishException

use of org.forgerock.openam.sts.STSPublishException 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 17 with STSPublishException

use of org.forgerock.openam.sts.STSPublishException 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)

Example 18 with STSPublishException

use of org.forgerock.openam.sts.STSPublishException 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 19 with STSPublishException

use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.

the class SoapSTSInstancePublisherImpl method publishInstance.

private void publishInstance(SoapSTSInstanceConfig instanceConfig) throws STSPublishException {
    Injector injector;
    try {
        injector = SoapSTSInjectorHolder.getInstance(Key.get(Injector.class)).createChildInjector(new SoapSTSInstanceModule(instanceConfig));
        final Server server = soapSTSInstanceLifecycleManager.exposeSTSInstanceAsWebService(injector.getInstance(Key.get(new TypeLiteral<Map<String, Object>>() {
        }, Names.named(AMSTSConstants.STS_WEB_SERVICE_PROPERTIES))), injector.getInstance(SecurityTokenServiceProvider.class), instanceConfig);
        publishedAndExposedInstances.put(instanceConfig.getDeploymentSubPath(), new ConfigAndServerHolder(instanceConfig, server));
        //TODO: add the sts element, or whatever is exposed in web.xml to the log message?
        logger.info("The following soap-sts instance has been successfully exposed at " + instanceConfig.getDeploymentSubPath() + ":\n" + instanceConfig);
    } catch (Exception e) {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Could not create injector corresponding to the " + "to-be-published instance " + instanceConfig.getDeploymentSubPath() + "; The exception: " + e, e);
    }
}
Also used : SoapSTSInstanceModule(org.forgerock.openam.sts.soap.config.SoapSTSInstanceModule) Server(org.apache.cxf.endpoint.Server) Injector(com.google.inject.Injector) STSPublishException(org.forgerock.openam.sts.STSPublishException) SecurityTokenServiceProvider(org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider) HashMap(java.util.HashMap) Map(java.util.Map) ResourceException(org.forgerock.json.resource.ResourceException) STSPublishException(org.forgerock.openam.sts.STSPublishException)

Aggregations

STSPublishException (org.forgerock.openam.sts.STSPublishException)19 ResourceException (org.forgerock.json.resource.ResourceException)6 Injector (com.google.inject.Injector)5 RestSTSInstanceConfig (org.forgerock.openam.sts.rest.config.user.RestSTSInstanceConfig)5 SMSException (com.sun.identity.sm.SMSException)4 HashSet (java.util.HashSet)4 NotFoundException (org.forgerock.json.resource.NotFoundException)4 RestSTS (org.forgerock.openam.sts.rest.RestSTS)4 SoapSTSInstanceConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig)4 SSOException (com.iplanet.sso.SSOException)3 ServiceConfig (com.sun.identity.sm.ServiceConfig)3 BadRequestException (org.forgerock.json.resource.BadRequestException)3 ServiceConfigManager (com.sun.identity.sm.ServiceConfigManager)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 JsonValue (org.forgerock.json.JsonValue)2 JsonObject (org.forgerock.openam.utils.JsonObject)2 OrganizationConfigManager (com.sun.identity.sm.OrganizationConfigManager)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1