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());
}
}
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();
}
}
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();
}
}
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));
}
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());
}
Aggregations