Search in sources :

Example 6 with Auditor

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);
}
Also used : LoggingAuditor(org.nhindirect.common.audit.impl.LoggingAuditor) Auditor(org.nhindirect.common.audit.Auditor) MultiProviderAuditor(org.nhindirect.common.audit.impl.MultiProviderAuditor) NoOpAuditor(org.nhindirect.common.audit.impl.NoOpAuditor) DefaultAuditContext(org.nhindirect.common.audit.DefaultAuditContext) MultiProviderAuditor(org.nhindirect.common.audit.impl.MultiProviderAuditor) NoOpAuditor(org.nhindirect.common.audit.impl.NoOpAuditor) LoggingAuditor(org.nhindirect.common.audit.impl.LoggingAuditor) Test(org.junit.Test)

Example 7 with Auditor

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);
    }
}
Also used : Auditor(org.nhindirect.common.audit.Auditor) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)

Example 8 with Auditor

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;
}
Also used : Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessagingException(javax.mail.MessagingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) MalformedURLException(java.net.MalformedURLException) ServiceException(org.nhindirect.common.rest.exceptions.ServiceException) RejectedRecipientDSNCreatorProvider(org.nhindirect.gateway.smtp.dsn.provider.RejectedRecipientDSNCreatorProvider) URLAccessedConfigProvider(org.nhindirect.gateway.smtp.provider.URLAccessedConfigProvider) SecureURLAccessedConfigProvider(org.nhindirect.gateway.smtp.provider.SecureURLAccessedConfigProvider) OpenServiceSecurityManagerProvider(org.nhindirect.common.rest.provider.OpenServiceSecurityManagerProvider) WSSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.WSSmtpAgentConfigProvider) XMLSmtpAgentConfigProvider(org.nhindirect.gateway.smtp.provider.XMLSmtpAgentConfigProvider) MailetAwareProvider(org.nhindirect.gateway.smtp.provider.MailetAwareProvider) KeyStoreProtectionConfigProvider(org.nhindirect.gateway.smtp.provider.KeyStoreProtectionConfigProvider) Provider(com.google.inject.Provider) Auditor(org.nhindirect.common.audit.Auditor) Module(com.google.inject.Module) AuditorModule(org.nhindirect.gateway.smtp.module.AuditorModule)

Aggregations

Auditor (org.nhindirect.common.audit.Auditor)8 Test (org.junit.Test)6 LoggingAuditor (org.nhindirect.common.audit.impl.LoggingAuditor)6 MultiProviderAuditor (org.nhindirect.common.audit.impl.MultiProviderAuditor)6 NoOpAuditor (org.nhindirect.common.audit.impl.NoOpAuditor)6 Module (com.google.inject.Module)1 Provider (com.google.inject.Provider)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 MessagingException (javax.mail.MessagingException)1 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)1 ServiceException (org.nhindirect.common.rest.exceptions.ServiceException)1 OpenServiceSecurityManagerProvider (org.nhindirect.common.rest.provider.OpenServiceSecurityManagerProvider)1 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)1 RejectedRecipientDSNCreatorProvider (org.nhindirect.gateway.smtp.dsn.provider.RejectedRecipientDSNCreatorProvider)1 AuditorModule (org.nhindirect.gateway.smtp.module.AuditorModule)1 KeyStoreProtectionConfigProvider (org.nhindirect.gateway.smtp.provider.KeyStoreProtectionConfigProvider)1 MailetAwareProvider (org.nhindirect.gateway.smtp.provider.MailetAwareProvider)1 SecureURLAccessedConfigProvider (org.nhindirect.gateway.smtp.provider.SecureURLAccessedConfigProvider)1