diff --git a/platform/email/platform-email-impl/pom.xml b/platform/email/platform-email-impl/pom.xml index d6f2f8ce18c5..57cb38e3d820 100644 --- a/platform/email/platform-email-impl/pom.xml +++ b/platform/email/platform-email-impl/pom.xml @@ -72,6 +72,17 @@ ddf.platform.util platform-util + + ddf.security.encryption + security-encryption-api + ${project.version} + + + org.mockito + mockito-core + ${mockito-core.version} + test + diff --git a/platform/email/platform-email-impl/src/main/java/org/codice/ddf/platform/email/impl/SmtpClientImpl.java b/platform/email/platform-email-impl/src/main/java/org/codice/ddf/platform/email/impl/SmtpClientImpl.java index 424ec1fab03c..a95072db5ca2 100644 --- a/platform/email/platform-email-impl/src/main/java/org/codice/ddf/platform/email/impl/SmtpClientImpl.java +++ b/platform/email/platform-email-impl/src/main/java/org/codice/ddf/platform/email/impl/SmtpClientImpl.java @@ -18,6 +18,7 @@ import static org.apache.commons.lang.Validate.notNull; import ddf.security.common.audit.SecurityLogger; +import ddf.security.encryption.EncryptionService; import java.util.Arrays; import java.util.Properties; import java.util.concurrent.ExecutorService; @@ -69,6 +70,8 @@ public class SmtpClientImpl implements SmtpClient { Executors.newFixedThreadPool( 1, StandardThreadFactoryBuilder.newThreadFactory("smtpClientImplThread")); + private final EncryptionService encryptionService; + private String hostName; private Integer portNumber; @@ -77,6 +80,10 @@ public class SmtpClientImpl implements SmtpClient { private String password; + public SmtpClientImpl(EncryptionService encryptionService) { + this.encryptionService = encryptionService; + } + /** * Set the username for the email server. * @@ -92,7 +99,7 @@ public void setUserName(@Nullable String userName) { * @param password the password for the email server */ public void setPassword(@Nullable String password) { - this.password = password; + this.password = encryptionService.decryptValue(password); } /** @param hostName must be non-empty */ diff --git a/platform/email/platform-email-impl/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/platform/email/platform-email-impl/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 452c29250345..1b95af9fa6cb 100644 --- a/platform/email/platform-email-impl/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/platform/email/platform-email-impl/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -18,7 +18,12 @@ xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + + + @@ -32,4 +37,4 @@ - \ No newline at end of file + diff --git a/platform/email/platform-email-impl/src/test/java/org/codice/ddf/platform/email/impl/SmtpClientImplITCaseTest.java b/platform/email/platform-email-impl/src/test/java/org/codice/ddf/platform/email/impl/SmtpClientImplITCaseTest.java index f23736a3f8dc..5a05502d6c3f 100644 --- a/platform/email/platform-email-impl/src/test/java/org/codice/ddf/platform/email/impl/SmtpClientImplITCaseTest.java +++ b/platform/email/platform-email-impl/src/test/java/org/codice/ddf/platform/email/impl/SmtpClientImplITCaseTest.java @@ -16,9 +16,14 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; +import static org.mockito.AdditionalAnswers.returnsFirstArg; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.dumbster.smtp.SimpleSmtpServer; import com.dumbster.smtp.SmtpMessage; +import ddf.security.encryption.EncryptionService; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -76,7 +81,7 @@ public void testSendWithAttachments() SimpleSmtpServer server = SimpleSmtpServer.start(port); - SmtpClientImpl emailService = new SmtpClientImpl(); + SmtpClientImpl emailService = new SmtpClientImpl(null); emailService.setHostName(HOSTNAME); emailService.setPortNumber(port); @@ -130,7 +135,7 @@ public void testSend() SimpleSmtpServer server = SimpleSmtpServer.start(port); - SmtpClientImpl emailService = new SmtpClientImpl(); + SmtpClientImpl emailService = new SmtpClientImpl(null); emailService.setHostName(HOSTNAME); emailService.setPortNumber(port); @@ -189,18 +194,20 @@ public void testWithUsernameEmptyPassword() throws UnknownHostException { @Test(expected = IllegalArgumentException.class) public void testWithNullHostname() { - SmtpClientImpl emailService = new SmtpClientImpl(); + SmtpClientImpl emailService = new SmtpClientImpl(null); emailService.createSession(); } @Test(expected = IllegalArgumentException.class) public void throwsIllegalArgumentExceptionWhenPortNumberIsLessThanOne() { - new SmtpClientImpl().setPortNumber(0); + new SmtpClientImpl(null).setPortNumber(0); } private void validateUsernamePassword(String username, String password) throws UnknownHostException { - SmtpClientImpl emailService = new SmtpClientImpl(); + EncryptionService mockEncryptionService = mock(EncryptionService.class); + when(mockEncryptionService.decryptValue(anyString())).then(returnsFirstArg()); + SmtpClientImpl emailService = new SmtpClientImpl(mockEncryptionService); emailService.setHostName("host.com"); emailService.setPortNumber(25);