use of org.nhindirect.common.audit.Auditor in project nhin-d by DirectProject.
the class MultiProviderAuditorTest method testAuditWithContext.
@Test
public void testAuditWithContext() {
Auditor auditor = new MultiProviderAuditor(Arrays.asList(new LoggingAuditor(), new NoOpAuditor()));
Collection<? extends AuditContext> ctx = Arrays.asList(new DefaultAuditContext("name", "value"));
auditor.audit(PRINCIPAL, UNIT_TEST_EVENT, ctx);
}
use of org.nhindirect.common.audit.Auditor in project nhin-d by DirectProject.
the class RDBMSAuditorProvider method createAuditor.
protected Auditor createAuditor() {
final String fileLoc = (springConfigLocation == null || springConfigLocation.isEmpty()) ? DEFAULT_APPLICATION_CONTEXT_FILE : springConfigLocation;
final ClassLoader loader = new AggregateClassLoader(Arrays.asList(Thread.currentThread().getContextClassLoader()), Arrays.asList(ClassLoader.getSystemClassLoader(), Thread.currentThread().getContextClassLoader(), RDBMSAuditorProvider.class.getClassLoader()));
try {
final ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(fileLoc) {
protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
super.initBeanDefinitionReader(reader);
reader.setBeanClassLoader(loader);
setClassLoader(loader);
}
};
return (Auditor) ctx.getBean("auditor");
} catch (Exception e) {
throw new IllegalStateException("Auditor could not be found in Spring configuration.", e);
}
}
use of org.nhindirect.common.audit.Auditor in project nhin-d by DirectProject.
the class NHINDSecurityAndTrustMailet method getAuditModule.
/**
* Gets a custom audit module if one if configured.
* @return A custom audit module. Null if a custom module is not configured.
*/
protected Module getAuditModule() {
Module retVal = null;
Provider<Auditor> provider = null;
final String providerClazz = GatewayConfiguration.getConfigurationParam(SecurityAndTrustMailetOptions.SMTP_AGENT_AUDITOR_PROVIDER, this, "");
final String auditoConfigLoc = GatewayConfiguration.getConfigurationParam(SecurityAndTrustMailetOptions.SMTP_AGENT_AUDITOR_CONFIG_LOC, this, "");
if (providerClazz != null && !providerClazz.isEmpty()) {
try {
// create an instance of the provider
@SuppressWarnings("unchecked") Class<Provider<Auditor>> clazz = (Class<Provider<Auditor>>) getClass().getClassLoader().loadClass(providerClazz);
if (auditoConfigLoc != null && !auditoConfigLoc.isEmpty()) {
try {
Constructor<Provider<Auditor>> constr = (Constructor<Provider<Auditor>>) clazz.getConstructor(String.class);
provider = constr.newInstance(auditoConfigLoc);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof IllegalStateException) {
LOGGER.warn("Could not create auditor from specified audito configuration file " + auditoConfigLoc, e);
return null;
} else
LOGGER.warn("Auditor configuration location " + auditoConfigLoc + " provided but not supported by Auditor provider:" + e.getMessage(), e);
} catch (Exception e) {
LOGGER.warn("Auditor configuration location " + auditoConfigLoc + " provided but not supported by Auditor provider:" + e.getMessage(), e);
}
}
if (provider == null)
provider = clazz.newInstance();
retVal = AuditorModule.create(provider);
} catch (Exception e) {
LOGGER.warn("Failed to load auditor provider class " + providerClazz + ": " + e.getMessage(), e);
}
}
return retVal;
}
Aggregations