Search in sources :

Example 11 with SoapSTSInstanceConfig

use of org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig in project OpenAM by OpenRock.

the class PublishServiceConsumerImpl method parseResponse.

/*
    The response is created in SoapSTSPublishServiceRequestHandler#handleQuery.
     */
private Set<SoapSTSInstanceConfig> parseResponse(String response) throws STSPublishException {
    Set<SoapSTSInstanceConfig> instanceConfigs = new HashSet<>();
    JsonValue json;
    try {
        json = JsonValueBuilder.toJsonValue(response);
    } catch (JsonException e) {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, e.getMessage(), e);
    }
    JsonValue queryResult = json.get(RESULT);
    if (queryResult.isCollection()) {
        int size = queryResult.asCollection().size();
        for (int ndx = 0; ndx < size; ndx++) {
            final SoapSTSInstanceConfig soapSTSInstanceConfig = SoapSTSInstanceConfig.fromJson(queryResult.get(ndx));
            /*
                check for duplicates: duplicates cannot really be present because the combination of realm and deployment
                uri constitutes the identity of the soap-sts instance, and duplicate entries will result in LDAP errors
                when the instance is persisted in the SMS, but paranoia pays...
                 */
            if (!instanceConfigs.add(soapSTSInstanceConfig)) {
                logger.error("The set of published soap-sts instances contains a duplicate!! The duplicate instance: " + queryResult.get(ndx));
            }
        }
        return instanceConfigs;
    } else {
        throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Unexpected state: the query result is not " + "a collection. The query result: " + queryResult.toString());
    }
}
Also used : JsonException(org.forgerock.json.JsonException) SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) JsonValue(org.forgerock.json.JsonValue) STSPublishException(org.forgerock.openam.sts.STSPublishException) HashSet(java.util.HashSet)

Example 12 with SoapSTSInstanceConfig

use of org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig 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 13 with SoapSTSInstanceConfig

use of org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig 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 14 with SoapSTSInstanceConfig

use of org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig in project OpenAM by OpenRock.

the class SoapSTSInstancePublisherImplTest method testUpdate.

@SuppressWarnings("unchecked")
@Test
public void testUpdate() throws ResourceException, UnsupportedEncodingException {
    SoapSTSInstanceConfig instanceConfig = createInstanceConfig("instanceOne", "http://host.com:8080/am");
    Set<SoapSTSInstanceConfig> initialSet = Sets.newHashSet(instanceConfig);
    when(mockPublishServiceConsumer.getPublishedInstances()).thenReturn(initialSet);
    when(mockLifecycleManager.exposeSTSInstanceAsWebService(any(Map.class), any(SecurityTokenServiceProvider.class), any(SoapSTSInstanceConfig.class))).thenReturn(mockServer);
    instancePublisher.run();
    verify(mockLifecycleManager, times(1)).exposeSTSInstanceAsWebService(any(Map.class), any(SecurityTokenServiceProvider.class), any(SoapSTSInstanceConfig.class));
    SoapSTSInstanceConfig updatedConfig = createInstanceConfig("instanceOne", "http://host.com:8080/am2");
    when(mockPublishServiceConsumer.getPublishedInstances()).thenReturn(Sets.newHashSet(updatedConfig));
    instancePublisher.run();
    verify(mockLifecycleManager, times(2)).exposeSTSInstanceAsWebService(any(Map.class), any(SecurityTokenServiceProvider.class), any(SoapSTSInstanceConfig.class));
    verify(mockLifecycleManager, times(1)).destroySTSInstance(any(Server.class));
}
Also used : SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) Server(org.apache.cxf.endpoint.Server) SecurityTokenServiceProvider(org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 15 with SoapSTSInstanceConfig

use of org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig in project OpenAM by OpenRock.

the class TokenDelegationHandlersProviderTest method testNoDelegationSupported.

@Test
public void testNoDelegationSupported() throws UnsupportedEncodingException {
    Logger mockLogger = mock(Logger.class);
    ThreadLocalAMTokenCache mockTokenCache = mock(ThreadLocalAMTokenCache.class);
    SoapSTSInstanceConfig instanceConfig = createInstanceConfig(!DELEGATION_VALIDATORS_SPECIFIED, !CUSTOM_DELEGATION_HANDLER);
    assertTrue(new TokenDelegationHandlersProvider(instanceConfig, mockTokenCache, mockLogger).get().isEmpty());
}
Also used : SoapSTSInstanceConfig(org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig) ThreadLocalAMTokenCache(org.forgerock.openam.sts.token.ThreadLocalAMTokenCache) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Aggregations

SoapSTSInstanceConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSInstanceConfig)15 Test (org.testng.annotations.Test)8 HashMap (java.util.HashMap)5 STSPublishException (org.forgerock.openam.sts.STSPublishException)4 AuthTargetMapping (org.forgerock.openam.sts.config.user.AuthTargetMapping)3 SAML2Config (org.forgerock.openam.sts.config.user.SAML2Config)3 SoapDeploymentConfig (org.forgerock.openam.sts.soap.config.user.SoapDeploymentConfig)3 SoapSTSKeystoreConfig (org.forgerock.openam.sts.soap.config.user.SoapSTSKeystoreConfig)3 ThreadLocalAMTokenCache (org.forgerock.openam.sts.token.ThreadLocalAMTokenCache)3 Logger (org.slf4j.Logger)3 BeforeTest (org.testng.annotations.BeforeTest)3 Map (java.util.Map)2 Server (org.apache.cxf.endpoint.Server)2 SecurityTokenServiceProvider (org.apache.cxf.ws.security.sts.provider.SecurityTokenServiceProvider)2 JsonValue (org.forgerock.json.JsonValue)2 BadRequestException (org.forgerock.json.resource.BadRequestException)2 NotFoundException (org.forgerock.json.resource.NotFoundException)2 HashSet (java.util.HashSet)1 JsonException (org.forgerock.json.JsonException)1 JsonPointer (org.forgerock.json.JsonPointer)1