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);
}
}
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);
}
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));
}
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));
}
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());
}
Aggregations