use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.
the class STSInstanceConfigStoreBase method getAllRealmNames.
private Set<String> getAllRealmNames() throws STSPublishException {
Set<String> realmNames = new HashSet<>();
/*
The OrganizationConfigManager#SubOrganizationNames only returns realms under the root realm. The root
realm needs to be added separately
*/
realmNames.add(AMSTSConstants.ROOT_REALM);
try {
Set<String> subRealms = getSubrealms(realmNames);
while (!subRealms.isEmpty()) {
realmNames.addAll(subRealms);
subRealms = getSubrealms(subRealms);
}
return realmNames;
} catch (SMSException e) {
throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Could not obtain list of realms from the OrganizationConfigManager. " + "This means list of previously-published " + restOrSoap() + " sts instances cannot be returned. " + "Exception: " + e);
}
}
use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.
the class PublishServiceConsumerImpl method getPublishedInstances.
@Override
public Set<SoapSTSInstanceConfig> getPublishedInstances() throws ResourceException {
String sessionId = null;
HttpURLConnectionWrapper.ConnectionResult connectionResult;
try {
sessionId = soapSTSAccessTokenProvider.getAccessToken();
Map<String, String> headerMap = new HashMap<>();
headerMap.put(AMSTSConstants.CONTENT_TYPE, AMSTSConstants.APPLICATION_JSON);
headerMap.put(AMSTSConstants.CREST_VERSION_HEADER_KEY, soapSTSPublishServiceVersion);
headerMap.put(AMSTSConstants.COOKIE, createAMSessionCookie(sessionId));
connectionResult = httpURLConnectionWrapperFactory.httpURLConnectionWrapper(buildPublishServiceUrl()).setRequestHeaders(headerMap).setRequestMethod(AMSTSConstants.GET).makeInvocation();
} catch (IOException e) {
throw new STSPublishException(org.forgerock.json.resource.ResourceException.INTERNAL_ERROR, "Exception caught invoking obtaining published soap sts instance state from publish service: " + e, e);
} finally {
if (sessionId != null) {
soapSTSAccessTokenProvider.invalidateAccessToken(sessionId);
}
}
final int responseCode = connectionResult.getStatusCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
return parseResponse(connectionResult.getResult());
} else {
throw new STSPublishException(responseCode, "Returning empty list from PublishServiceConsumerImpl#getPublishedInstances - non 200 " + "response from sts-publish service: " + connectionResult.getResult());
}
}
use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.
the class SoapSTSInstanceLifecycleManagerImpl method exposeSTSInstanceAsWebService.
@Override
public Server exposeSTSInstanceAsWebService(Map<String, Object> webServiceProperties, SecurityTokenServiceProvider securityTokenServiceProvider, SoapSTSInstanceConfig stsInstanceConfig) throws STSPublishException {
try {
JaxWsServerFactoryBean serverFactoryBean = new JaxWsServerFactoryBean();
/*
The serverFactoryBean#setBus invocation is crucial. The cxf.Bus class is ultimately the entity with which newly published web-services are
registered. The STSBroker#loadBus method previously called BusFactory.setDefaultBus with the bus instance corresponding
to the STSBroker, the CXFNonSpringServlet subclass which is specified in web.xml as the entry point for all incoming
web-service invocations, and thus the entity with which all published web-service instances must be registered.
Without the line below, web-services instances can happily be published, but unless they are associated with the
STSBroker's cxf bus, the routing functionality in the CXFNonSpringServlet will not know of this published web-service,
resulting in a 404 on any invocation.
Note that the parameter to BusFactory.getDefaultBus is set to false, as BusFactory.setDefaultBus was called in
STSBroker#loadBus, the CXFNonSpringServlet subclass, specified in web.xml, which is the entry point for all
web-service invocations. Note that the STSBroker#loadBus method is called as part of the servlet intialization
(it is a load-on-startup servlet), and prior to the initiation of the publish-service polling which will ultimately
result in the invocation of this method. So the BusFactory.getDefaultBus method should always return the Bus
instance set in the STSBroker class - thus the createIfNecessary parameter is always set to false.
*/
final boolean createIfNecessary = false;
serverFactoryBean.setBus(BusFactory.getDefaultBus(createIfNecessary));
serverFactoryBean.setWsdlLocation(stsInstanceConfig.getDeploymentConfig().getWsdlLocation());
serverFactoryBean.setAddress(normalizeDeploymentSubPath(stsInstanceConfig.getDeploymentSubPath()));
serverFactoryBean.setServiceBean(securityTokenServiceProvider);
serverFactoryBean.setServiceName(stsInstanceConfig.getDeploymentConfig().getService());
serverFactoryBean.setEndpointName(stsInstanceConfig.getDeploymentConfig().getPort());
//TODO: get clear on implications of this line.
serverFactoryBean.setBindingId(SOAPBinding.SOAP12HTTP_BINDING);
serverFactoryBean.setProperties(webServiceProperties);
return serverFactoryBean.create();
} catch (RuntimeException e) {
/*
The CXF runtime was written at the time when checked-exceptions were passe' - thus RuntimeException subclasses
are thrown. Catch Exception because the compiler won't tell me which exceptions are thrown.
*/
throw new STSPublishException(ResourceException.INTERNAL_ERROR, e.getMessage(), e);
}
}
use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.
the class SoapSTSInstancePublisherImpl method removeDeletedInstance.
private void removeDeletedInstance(ConfigAndServerHolder configAndServerHolder) throws STSPublishException {
try {
soapSTSInstanceLifecycleManager.destroySTSInstance(configAndServerHolder.server);
} catch (STSPublishException e) {
/*
Yes, we are catching and re-throwing a STSPublishException because the SoapSTSInstanceLifecycleManager does not
have the state to create a specific-enough exception.
*/
throw new STSPublishException(ResourceException.INTERNAL_ERROR, "Could not remove soap sts instance: " + configAndServerHolder.soapSTSInstanceConfig.getDeploymentSubPath() + "; Exception: " + e, e);
}
final String instanceId = configAndServerHolder.soapSTSInstanceConfig.getDeploymentSubPath();
publishedAndExposedInstances.remove(instanceId);
logger.info("Destroyed soap-sts instance " + instanceId);
}
use of org.forgerock.openam.sts.STSPublishException in project OpenAM by OpenRock.
the class RestSTSSetupListener method setupComplete.
/**
* Republish any existing rest-sts instances obtained from the SMS, and register a ServiceListener to respond when
* new rest-sts instances are written to the SMS.
*/
@Override
public void setupComplete() {
new Thread(new Runnable() {
public void run() {
Logger logger = null;
try {
logger = STSPublishInjectorHolder.getInstance(Key.get(Logger.class));
RestSTSInstancePublisher publisher = STSPublishInjectorHolder.getInstance(Key.get(RestSTSInstancePublisher.class));
/*
Don't register the ServiceListener until after the SMS-resident rest-sts instances have been re-published
upon startup. The ServiceListener is only there to bring the rest-sts-instance CREST router in congruence
with the state of the SMS in site deployments.
*/
publisher.republishExistingInstances();
publisher.registerServiceListener();
} catch (STSPublishException e) {
if (logger != null) {
logger.error("Exception caught republishing existing Rest STS instances: ", e);
} else {
System.out.println("Exception caught republishing existing Rest STS instances: " + e);
}
}
}
}).start();
}
Aggregations