Search in sources :

Example 26 with SmtpAgentException

use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method addPolicyToMap.

public void addPolicyToMap(Map<String, Collection<PolicyExpression>> policyMap, String domainName, CertPolicyGroupReltn policyReltn) {
    // check to see if the domain is in the map
    Collection<PolicyExpression> policyExpressionCollection = policyMap.get(domainName);
    if (policyExpressionCollection == null) {
        policyExpressionCollection = new ArrayList<PolicyExpression>();
        policyMap.put(domainName, policyExpressionCollection);
    }
    final CertPolicy policy = policyReltn.getCertPolicy();
    final PolicyLexicon lexicon;
    if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.JAVA_SER))
        lexicon = PolicyLexicon.JAVA_SER;
    else if (policy.getLexicon().equals(org.nhind.config.PolicyLexicon.SIMPLE_TEXT_V1))
        lexicon = PolicyLexicon.SIMPLE_TEXT_V1;
    else
        lexicon = PolicyLexicon.XML;
    final InputStream inStr = new ByteArrayInputStream(policy.getPolicyData());
    try {
        // grab a parser and compile this policy
        final PolicyLexiconParser parser = PolicyLexiconParserFactory.getInstance(lexicon);
        policyExpressionCollection.add(parser.parse(inStr));
    } catch (PolicyParseException ex) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "Failed parse policy into policy expression: " + ex.getMessage(), ex);
    } finally {
        IOUtils.closeQuietly(inStr);
    }
}
Also used : PolicyLexicon(org.nhindirect.policy.PolicyLexicon) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) CertPolicy(org.nhind.config.CertPolicy) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PolicyLexiconParser(org.nhindirect.policy.PolicyLexiconParser) PolicyExpression(org.nhindirect.policy.PolicyExpression) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 27 with SmtpAgentException

use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method buildPublicCertStore.

/*
	 * Build the certificate resolver for public certificates
	 */
@SuppressWarnings("unchecked")
protected void buildPublicCertStore() {
    Provider<CertificateResolver> resolverProvider = null;
    Collection<Provider<CertificateResolver>> resolverProviders = new ArrayList<Provider<CertificateResolver>>();
    Setting setting = null;
    String storeTypes;
    try {
        setting = cfService.getSettingByName("PublicStoreType");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting public store type: " + e.getMessage(), e);
    }
    if (setting == null || setting.getValue() == null || setting.getValue().isEmpty())
        // default to DNS
        storeTypes = STORE_TYPE_DNS + "," + STORE_TYPE_PUBLIC_LDAP;
    else
        storeTypes = setting.getValue();
    /*
		 * KeyStore based resolver
		 */
    String[] types = storeTypes.split(",");
    for (String storeType : types) {
        if (storeType.equalsIgnoreCase(STORE_TYPE_KEYSTORE)) {
            Setting file;
            Setting pass;
            Setting privKeyPass;
            try {
                file = cfService.getSettingByName("PublicStoreFile");
                pass = cfService.getSettingByName("PublicStoreFilePass");
                privKeyPass = cfService.getSettingByName("PublicStorePrivKeyPass");
            } catch (Exception e) {
                throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting public store file settings: " + e.getMessage(), e);
            }
            resolverProvider = new KeyStoreCertificateStoreProvider((file == null) ? "PublicStoreKeyFile" : file.getValue(), (pass == null) ? "DefaultFilePass" : pass.getValue(), (privKeyPass == null) ? "DefaultKeyPass" : privKeyPass.getValue());
        } else /*
			 * DNS resolver
			 */
        if (storeType.equalsIgnoreCase(STORE_TYPE_DNS)) {
            resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DNSCertificateStore.DefaultDNSCachePolicy());
        } else /*
			 * Web Services
			 */
        if (storeType.equalsIgnoreCase(STORE_TYPE_WS)) {
            resolverProvider = new ConfigServiceCertificateStoreProvider(cfService, null, new ConfigServiceCertificateStore.DefaultConfigStoreCachePolicy(), this.storeProvider);
        } else /*
			 * Public LDAP resolver
			 */
        if (storeType.equalsIgnoreCase(STORE_TYPE_PUBLIC_LDAP)) {
            resolverProvider = new PublicLdapCertificateStoreProvider(null, new LDAPCertificateStore.DefaultLDAPCachePolicy());
        } else /*
			 * Default to DNS with a default cache policy
			 */
        {
            resolverProvider = new DNSCertStoreProvider(Collections.EMPTY_LIST, null, new DNSCertificateStore.DefaultDNSCachePolicy());
        }
        resolverProviders.add(resolverProvider);
    }
    publicCertModule = new PublicCertStoreModule(resolverProviders);
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) ConfigServiceCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceCertificateStoreProvider) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) Setting(org.nhind.config.Setting) PublicCertStoreModule(org.nhindirect.stagent.module.PublicCertStoreModule) ArrayList(java.util.ArrayList) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) DefaultSmtpAgentProvider(org.nhindirect.gateway.smtp.provider.DefaultSmtpAgentProvider) KeyStoreCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider) ConfigServiceCertificateStoreProvider(org.nhindirect.gateway.smtp.config.cert.impl.provider.ConfigServiceCertificateStoreProvider) MultiDomainTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider) UniformTrustAnchorResolverProvider(org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) PublicLdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.PublicLdapCertificateStoreProvider) DomainPolicyResolverProvider(org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider) LdapCertificateStoreProvider(org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider) Provider(com.google.inject.Provider) DNSCertificateStore(org.nhindirect.stagent.cert.impl.DNSCertificateStore) LDAPCertificateStore(org.nhindirect.stagent.cert.impl.LDAPCertificateStore) DNSCertStoreProvider(org.nhindirect.stagent.cert.impl.provider.DNSCertStoreProvider) CertificateResolver(org.nhindirect.stagent.cert.CertificateResolver)

Example 28 with SmtpAgentException

use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method buildMessageSettings.

protected void buildMessageSettings(String type) {
    Setting folderSettings;
    try {
        folderSettings = cfService.getSettingByName(type + "MessageSaveFolder");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting " + type + " message settings: " + e.getMessage(), e);
    }
    String saveFolder = (folderSettings == null) ? null : folderSettings.getValue();
    MessageProcessingSettings settings = null;
    if (type.equalsIgnoreCase(MESSAGE_SETTING_RAW))
        settings = rawSettings = new RawMessageSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_INCOMING))
        settings = incomingSettings = new ProcessIncomingSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_OUTGOING))
        settings = outgoingSettings = new ProcessOutgoingSettings();
    else if (type.equalsIgnoreCase(MESSAGE_SETTING_BAD))
        settings = badSettings = new ProcessBadMessageSettings();
    if (saveFolder != null && settings != null)
        settings.setSaveMessageFolder(new File(saveFolder));
}
Also used : ProcessOutgoingSettings(org.nhindirect.gateway.smtp.ProcessOutgoingSettings) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) ProcessBadMessageSettings(org.nhindirect.gateway.smtp.ProcessBadMessageSettings) Setting(org.nhind.config.Setting) MessageProcessingSettings(org.nhindirect.gateway.smtp.MessageProcessingSettings) ProcessIncomingSettings(org.nhindirect.gateway.smtp.ProcessIncomingSettings) RawMessageSettings(org.nhindirect.gateway.smtp.RawMessageSettings) File(java.io.File) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 29 with SmtpAgentException

use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildAgentInjector.

/*
	 * Initializes all of the modules needed to build an agent using this configuration
	 * This is implemented using a simple DOM document loaded from a know XML schema
	 * Later versions may use POJOs build from XML (JAXB) or other configuration methods
	 */
private Injector buildAgentInjector() {
    // simple node iteration
    Node docNode = doc.getFirstChild().getFirstChild();
    do {
        /*
			 * Domain information
			 */
        if (docNode.getNodeName().equalsIgnoreCase("domains")) {
            buildDomains(docNode);
        } else /*
			 * public cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("publiccertstore")) {
            buildPublicCertStore(docNode);
            publicCertModule = new PublicCertStoreModule(resolverProviders);
        } else /*
			 * public cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("publiccertstores")) {
            buildPublicCertStores(docNode);
            publicCertModule = new PublicCertStoreModule(resolverProviders);
        } else /*
			 * private cert store
			 */
        if (docNode.getNodeName().equalsIgnoreCase("privatecertstore")) {
            buildPrivateCertStore(docNode);
        } else /*
			 * Raw messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("rawmessagesettings")) {
            buildRawMessageSettings(docNode);
        } else /*
			 * Incoming messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("incomingmessagessettings")) {
            buildIncomingMessageSettings(docNode);
        } else /*
			 * Outgoing messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("outgoingmessagessettings")) {
            buildOutgoingMessageSettings(docNode);
        } else /*
			 * Bad messages
			 */
        if (docNode.getNodeName().equalsIgnoreCase("badmessagessettings")) {
            buildBadMessageSettings(docNode);
        } else /*
			 * MDN settings
			 */
        if (docNode.getNodeName().equalsIgnoreCase("mdnsettings")) {
            buildMDNSettings(docNode);
        }
        docNode = docNode.getNextSibling();
    } while (docNode != null);
    if (domains == null)
        throw new SmtpAgentException(SmtpAgentError.MissingDomains);
    SmtpAgentSettings settings = new SmtpAgentSettings(domainPostmasters, rawSettings, outgoingSettings, incomingSettings, badSettings, notificationProducer);
    if (smtpAgentProvider == null)
        smtpAgentProvider = new DefaultSmtpAgentProvider(settings);
    AgentModule agentModule;
    if (agentProvider == null)
        agentModule = AgentModule.create(domains, publicCertModule, privateCertModule, certAnchorModule);
    else
        agentModule = AgentModule.create(agentProvider);
    return Guice.createInjector(agentModule, SmtpAgentModule.create(smtpAgentProvider));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) SmtpAgentModule(org.nhindirect.gateway.smtp.module.SmtpAgentModule) AgentModule(org.nhindirect.stagent.module.AgentModule) Node(org.w3c.dom.Node) PublicCertStoreModule(org.nhindirect.stagent.module.PublicCertStoreModule) DefaultSmtpAgentProvider(org.nhindirect.gateway.smtp.provider.DefaultSmtpAgentProvider) SmtpAgentSettings(org.nhindirect.gateway.smtp.SmtpAgentSettings)

Example 30 with SmtpAgentException

use of org.nhindirect.gateway.smtp.SmtpAgentException in project nhin-d by DirectProject.

the class NHINDSecurityAndTrustMailet_service_Test method testService_ProcessThrowsSmtpAgentException_AssertExceptionAndGhostState.

public void testService_ProcessThrowsSmtpAgentException_AssertExceptionAndGhostState() throws Exception {
    final MimeMessage mimeMsg = EntitySerializer.Default.deserialize(TestUtils.readMessageResource("PlainOutgoingMessage.txt"));
    final SmtpAgent mockAgent = mock(SmtpAgent.class);
    final Mail mockMail = mock(MockMail.class, CALLS_REAL_METHODS);
    when(mockMail.getRecipients()).thenReturn(null);
    when(mockMail.getSender()).thenReturn(new MailAddress("me@cerner.com"));
    doThrow(new SmtpAgentException(SmtpAgentError.Unknown, "Just Passing Through")).when(mockAgent).processMessage((MimeMessage) any(), (NHINDAddressCollection) any(), (NHINDAddress) any());
    mockMail.setMessage(mimeMsg);
    NHINDSecurityAndTrustMailet mailet = new NHINDSecurityAndTrustMailet();
    mailet.agent = mockAgent;
    boolean exceptionOccured = false;
    try {
        mailet.service(mockMail);
    } catch (SmtpAgentException e) {
        assertEquals(SmtpAgentError.Unknown, e.getError());
        assertEquals("Just Passing Through", e.getMessage());
        exceptionOccured = true;
    }
    assertFalse(exceptionOccured);
    assertEquals(Mail.GHOST, mockMail.getState());
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) Mail(org.apache.mailet.Mail) MailAddress(org.apache.mailet.MailAddress) MimeMessage(javax.mail.internet.MimeMessage) SmtpAgent(org.nhindirect.gateway.smtp.SmtpAgent)

Aggregations

SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)31 PolicyParseException (org.nhindirect.policy.PolicyParseException)20 AddressException (javax.mail.internet.AddressException)19 IOException (java.io.IOException)10 CertificateException (java.security.cert.CertificateException)10 Collection (java.util.Collection)8 ArrayList (java.util.ArrayList)7 Setting (org.nhind.config.Setting)7 Setting (org.nhindirect.config.model.Setting)7 LDAPCertificateStore (org.nhindirect.stagent.cert.impl.LDAPCertificateStore)7 X509Certificate (java.security.cert.X509Certificate)6 HashMap (java.util.HashMap)6 CertificateResolver (org.nhindirect.stagent.cert.CertificateResolver)5 KeyStoreCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.KeyStoreCertificateStoreProvider)5 LdapCertificateStoreProvider (org.nhindirect.stagent.cert.impl.provider.LdapCertificateStoreProvider)5 MultiDomainTrustAnchorResolverProvider (org.nhindirect.stagent.trust.provider.MultiDomainTrustAnchorResolverProvider)5 UniformTrustAnchorResolverProvider (org.nhindirect.stagent.trust.provider.UniformTrustAnchorResolverProvider)5 DomainPolicyResolverProvider (org.nhindirect.stagent.policy.impl.provider.DomainPolicyResolverProvider)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InternetAddress (javax.mail.internet.InternetAddress)3