use of com.google.inject.Injector in project OpenAM by OpenRock.
the class RestSTSPublishServiceRequestHandler method handleUpdate.
/*
* A PUT to the url composed of the publish endpont + the sts instance id with a payload corresponding to a
* RestSTSInstanceId (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 rest 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.isInstancePersistedInSMS(stsId, realm);
} catch (STSPublishException e) {
logger.error("In RestSTSPublishServiceRequestHandler#handleUpdate, exception caught determining whether " + "instance persisted in SMS. Instance not updated. Exception: " + e, e);
return e.asPromise();
}
final boolean publishedToCrest = publisher.isInstanceExposedInCrest(stsId);
if (publishedToSMS) {
if (!publishedToCrest) {
/*
Entering this branch would seem to be an error condition. It could possibly happen in a site deployment,
where a rest sts instance is published to a different server than the current server, and the registered
ServiceListener was not called when the ldap replication created the service entry on the current server.
I will log a warning, and still publish the instance, just for robustness.
*/
logger.warn("The rest sts instance " + stsId + " in realm " + realm + " is present in the SMS, but " + "has not been hung off of the CREST router. This is an illegal state. The instance will be" + " republished.");
}
RestSTSInstanceConfig instanceConfig;
try {
instanceConfig = marshalInstanceConfigFromInvocation(request.getContent());
} catch (BadRequestException e) {
logger.error("In RestSTSPublishServiceRequestHandler#handleUpdate, exception caught marshalling " + "invocation state to RestSTSInstanceConfig. Instance not updated. The state: " + request.getContent() + "Exception: " + e, e);
return e.asPromise();
}
Injector instanceInjector;
try {
instanceInjector = createInjector(instanceConfig);
} catch (ResourceException e) {
logger.error("In RestSTSPublishServiceRequestHandler#handleUpdate, exception caught creating an " + "Injector using the RestSTSInstanceConfig. The instance: " + instanceConfig.toJson() + "; Exception: " + e, e);
return e.asPromise();
}
try {
publisher.updateInstanceInSMS(stsId, realm, instanceConfig, instanceInjector.getInstance(RestSTS.class));
return newResultPromise(newResourceResponse(instanceConfig.getDeploymentSubPath(), Integer.toString(instanceConfig.hashCode()), json(object(field(RESULT, SUCCESS)))));
} catch (STSPublishException e) {
logger.error("In RestSTSPublishServiceRequestHandler#handleUpdate, exception caught removing " + "rest 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();
}
} else {
//404 - realm and id not found in SMS
return new NotFoundException("No rest sts instance with id " + stsId + " in realm " + realm).asPromise();
}
}
use of com.google.inject.Injector in project OpenAM by OpenRock.
the class RestSTSPublishServiceRequestHandler method handleCreate.
/*
This method will be invoked by either a programmatic client, in which case a RestSTSInstanceConfig has emitted
properly-formatted json, or from the RestSecurityTokenServiceViewBean, in which case the configuration state is
in the sms-centric Map<String, Set<String>> format. This method needs to be able to handle both invocation types,
and marshal the invocation state in to a RestSTSInstanceConfig instance either way. It also needs to return an accurate
error message, so that in the case of RestSecurityTokenServiceViewBean invocation, the user can make appropriate
corrections to the configuration state.
*/
public Promise<ResourceResponse, ResourceException> handleCreate(Context context, CreateRequest request) {
final RestSTSInstanceConfig instanceConfig;
try {
instanceConfig = marshalInstanceConfigFromInvocation(request.getContent());
} catch (BadRequestException e) {
return e.asPromise();
}
if (!realmValidator.isRealm(instanceConfig.getDeploymentConfig().getRealm())) {
logger.warn("Publish of Rest STS instance " + instanceConfig.getDeploymentSubPath() + " to realm " + instanceConfig.getDeploymentConfig().getRealm() + " rejected because realm does not exist.");
return new NotFoundException("The specified realm does not exist.").asPromise();
}
Injector instanceInjector;
try {
instanceInjector = createInjector(instanceConfig);
} catch (ResourceException e) {
return e.asPromise();
}
return publishInstance(instanceConfig, instanceInjector);
}
use of com.google.inject.Injector in project OpenAM by OpenRock.
the class RestSTSPublishServiceListener method handleInstanceCreation.
private void handleInstanceCreation(String normalizedServiceComponent, String orgName, String serviceComponent) {
final String logIdentifier = "RestSTSPublishServiceListener#handleInstanceCreation";
if (StringUtils.isBlank(normalizedServiceComponent)) {
logger.warn("In RestSTSPublishServiceListener#handleInstanceCreation, the normalized name of the rest-sts service for " + "which the creation event was received is blank. The un-normalized name: " + serviceComponent + ". This happens " + "the first time a rest-sts instance is published in a newly-created realm, as the first step in this creation " + "is the addition of a new service configuration object for this subrealm, which also triggers the invocation " + "of this listener. If this message is appearing after the first creation of a rest-sts instance in a new realm, " + "then something is wrong.");
return;
}
if (!instancePublisher.isInstanceExposedInCrest(normalizedServiceComponent)) {
String realm = DNMapper.orgNameToRealmName(orgName);
RestSTSInstanceConfig createdInstance;
try {
createdInstance = restSTSInstanceConfigStore.getSTSInstanceConfig(normalizedServiceComponent, realm);
} catch (STSPublishException e) {
logger.error(logIdentifier + ":could not obtain newly created rest-sts instance " + serviceComponent + " from SMS. " + "This means this instance will not be hung off of the CREST router. Exception: " + e);
return;
}
Injector instanceInjector;
try {
instanceInjector = createInjector(createdInstance);
} catch (ResourceException e) {
logger.error(logIdentifier + ":could not create injector corresponding to newly created rest-sts " + "instance " + serviceComponent + ". The instanceConfig " + createdInstance.toJson() + "\nThis means this instance will not be hung off of the CREST router. Exception: " + e);
return;
}
try {
instancePublisher.publishInstance(createdInstance, instanceInjector.getInstance(RestSTS.class), REPUBLISH_INSTANCE);
logger.info(logIdentifier + ": Successfully hung rest-sts instance " + createdInstance.getDeploymentSubPath() + " published at another server in the site deployment off of CREST router.");
} catch (ResourceException e) {
logger.error(logIdentifier + ":could not create injector corresponding to newly created rest-sts " + "instance " + serviceComponent + ". The instanceConfig " + createdInstance.toJson() + "\nThis means this instance will not be hung off of the CREST router. Exception: " + e);
}
}
}
use of com.google.inject.Injector in project nhin-d by DirectProject.
the class SmtpAgentFactory method createAgent.
/**
* Creates an instance of an {@link SmtpAgent} using the configuration information stored at the configuration location. Optional
* SmptAgentConfig and security and trust providers can be passed to create specific types of these components.
* @param configLocation The URL of the configuration information. The URL may refer to any addressable resource.
* @param configProvider A provider used to create the SmtpAgentConfig component that parses and the configuration.
* @param agentProvider A provider used to create the security and trust agent component.
* @return An initialized instance of an SmtpAgent.
* @throws SmtpAgentException Thrown if an error occurs while creating the SmtpAgent.
*/
public static synchronized SmtpAgent createAgent(URL configLocation, Provider<SmtpAgentConfig> configProvider, Provider<NHINDAgent> agentProvider) throws SmtpAgentException {
SmtpAgent retVal = null;
try {
Injector agentInjector = buildAgentInjector(configLocation, configProvider, agentProvider);
retVal = agentInjector.getInstance(SmtpAgent.class);
} catch (SmtpAgentException e) {
// rethrow
throw e;
} catch (Exception t) {
// catch all
LOGGER.error("SmtpAgent creation failed: " + t.getMessage(), t);
throw new SmtpAgentException(SmtpAgentError.Unknown, "SmtpAgent creation failed: " + t.getMessage(), t);
} catch (Throwable t) {
// catch all
LOGGER.error("SmtpAgent creation failed: " + t.getMessage(), t);
throw new SmtpAgentException(SmtpAgentError.Unknown, "SmtpAgent creation failed: " + t.getMessage());
}
return retVal;
}
use of com.google.inject.Injector in project nhin-d by DirectProject.
the class AbstractNotificationAwareMailet method createTxServices.
/**
* Creates the Tx services
* @param initModules The initial Guice modules created by the init() method
*/
protected void createTxServices(final Collection<Module> initModules) {
Collection<Module> modules = initModules;
// now try to get the TxParser
// attempt to use the existing modules first
final boolean usingDefaultTxServiceMoudles = (modules == null);
if (modules == null) {
// create a default module for the TxService
modules = createDefaultTxServiceModules();
}
Injector txInjector = Guice.createInjector(modules);
try {
txParser = txInjector.getInstance(TxDetailParser.class);
txService = txInjector.getInstance(TxService.class);
} catch (Exception e) {
LOGGER.debug("First attempt to create message monitoring service failed.", e);
if (!usingDefaultTxServiceMoudles)
LOGGER.debug("Will attempt to create from default Tx service Guice module.");
else
///CLOVER:OFF
LOGGER.warn("Monitoring service already attempted to use the defualt Tx service Guice module. Monitoring will be disabled.");
///CLOVER:ON
}
// try again using the default Guice module
if ((txParser == null || txService == null) && !usingDefaultTxServiceMoudles) {
try {
// create a default module for the TxService
modules = createDefaultTxServiceModules();
txInjector = Guice.createInjector(modules);
if (txParser == null)
txParser = txInjector.getInstance(TxDetailParser.class);
if (txService == null)
txService = txInjector.getInstance(TxService.class);
}///CLOVER:OFF
catch (Exception e) {
LOGGER.warn("Failed to create message monitoring service. Monitoring will be disabled");
}
///CLOVER:ON
}
}
Aggregations