Search in sources :

Example 1 with SMTPServer

use of org.subethamail.smtp.server.SMTPServer in project vertx-examples by vert-x3.

the class LocalSmtpServer method startWithAuth.

public static void startWithAuth(int port) {
    SMTPServer server = new SMTPServer(new SimpleMessageListenerAdapter(new MyMessageListener()));
    server.setPort(port);
    UsernamePasswordValidator validator = (s, s1) -> {
        if (!"username".equalsIgnoreCase(s) || !"password".equalsIgnoreCase(s1)) {
            throw new LoginFailedException();
        }
    };
    server.setAuthenticationHandlerFactory(new PlainAuthenticationHandlerFactory(validator));
    server.start();
}
Also used : PlainAuthenticationHandlerFactory(org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory) UsernamePasswordValidator(org.subethamail.smtp.auth.UsernamePasswordValidator) LoginFailedException(org.subethamail.smtp.auth.LoginFailedException) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) UsernamePasswordValidator(org.subethamail.smtp.auth.UsernamePasswordValidator) PlainAuthenticationHandlerFactory(org.subethamail.smtp.auth.PlainAuthenticationHandlerFactory) LoginFailedException(org.subethamail.smtp.auth.LoginFailedException) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter)

Example 2 with SMTPServer

use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.

the class SmtpServerFactoryImpl method create.

@Override
public SmtpServer create() {
    SimpleMessageListenerAdapter simpleMessageListenerAdapter = new SimpleMessageListenerAdapter(emailPersister);
    SMTPServer smtpServer = new SMTPServer(simpleMessageListenerAdapter);
    configurator.configure(smtpServer);
    return new SmtpServerImpl(smtpServer);
}
Also used : SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) SMTPServer(org.subethamail.smtp.server.SMTPServer)

Example 3 with SMTPServer

use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.

the class SmtpServerConfiguratorTest method shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull.

@Test
public void shouldSkipConfigurationOfAuthenticationWhenUsernameIsNull() {
    final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
    when(authentication.getUsername()).thenReturn(null);
    when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
    final SMTPServer smtpServer = mock(SMTPServer.class);
    sut.configure(smtpServer);
    verify(smtpServer, never()).setAuthenticationHandlerFactory(any(AuthenticationHandlerFactory.class));
    verify(logger).error(startsWith("Username"));
}
Also used : SMTPServer(org.subethamail.smtp.server.SMTPServer) FakeSmtpConfigurationProperties(de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties) AuthenticationHandlerFactory(org.subethamail.smtp.AuthenticationHandlerFactory) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) Test(org.junit.Test)

Example 4 with SMTPServer

use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.

the class SmtpServerConfiguratorTest method shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull.

@Test
public void shouldSkipConfigurationOfAuthenticationWhenPasswordIsNull() {
    final String username = "username";
    final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
    when(authentication.getUsername()).thenReturn(username);
    when(authentication.getPassword()).thenReturn(null);
    when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
    final SMTPServer smtpServer = mock(SMTPServer.class);
    sut.configure(smtpServer);
    verify(smtpServer, never()).setAuthenticationHandlerFactory(any(AuthenticationHandlerFactory.class));
    verify(logger).error(startsWith("Password"));
}
Also used : SMTPServer(org.subethamail.smtp.server.SMTPServer) FakeSmtpConfigurationProperties(de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties) AuthenticationHandlerFactory(org.subethamail.smtp.AuthenticationHandlerFactory) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) Test(org.junit.Test)

Example 5 with SMTPServer

use of org.subethamail.smtp.server.SMTPServer in project fake-smtp-server by gessnerfl.

the class SmtpServerConfiguratorTest method shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly.

@Test
public void shouldConfigureAuthenticationWhenAuthenticationIsConfiguredProperly() {
    final String username = "username";
    final String password = "password";
    final FakeSmtpConfigurationProperties.Authentication authentication = mock(FakeSmtpConfigurationProperties.Authentication.class);
    when(authentication.getUsername()).thenReturn(username);
    when(authentication.getPassword()).thenReturn(password);
    when(fakeSmtpConfigurationProperties.getAuthentication()).thenReturn(authentication);
    final SMTPServer smtpServer = mock(SMTPServer.class);
    sut.configure(smtpServer);
    ArgumentCaptor<AuthenticationHandlerFactory> argumentCaptor = ArgumentCaptor.forClass(AuthenticationHandlerFactory.class);
    verify(smtpServer).setAuthenticationHandlerFactory(argumentCaptor.capture());
    AuthenticationHandlerFactory authenticationHandlerFactory = argumentCaptor.getValue();
    assertNotNull(authenticationHandlerFactory);
    assertThat(authenticationHandlerFactory, instanceOf(EasyAuthenticationHandlerFactory.class));
    EasyAuthenticationHandlerFactory easyAuthenticationHandlerFactory = (EasyAuthenticationHandlerFactory) authenticationHandlerFactory;
    assertSame(basicUsernamePasswordValidator, easyAuthenticationHandlerFactory.getValidator());
}
Also used : EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) SMTPServer(org.subethamail.smtp.server.SMTPServer) FakeSmtpConfigurationProperties(de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties) AuthenticationHandlerFactory(org.subethamail.smtp.AuthenticationHandlerFactory) EasyAuthenticationHandlerFactory(org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory) Test(org.junit.Test)

Aggregations

SMTPServer (org.subethamail.smtp.server.SMTPServer)13 Test (org.junit.Test)8 AuthenticationHandlerFactory (org.subethamail.smtp.AuthenticationHandlerFactory)6 EasyAuthenticationHandlerFactory (org.subethamail.smtp.auth.EasyAuthenticationHandlerFactory)6 FakeSmtpConfigurationProperties (de.gessnerfl.fakesmtp.config.FakeSmtpConfigurationProperties)5 SimpleMessageListenerAdapter (org.subethamail.smtp.helper.SimpleMessageListenerAdapter)4 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 HashMap (java.util.HashMap)1 SSLContext (javax.net.ssl.SSLContext)1 SSLSocket (javax.net.ssl.SSLSocket)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 ComponentLog (org.apache.nifi.logging.ComponentLog)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1 SmtpConsumer (org.apache.nifi.processors.email.smtp.SmtpConsumer)1 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)1 SSLContextService (org.apache.nifi.ssl.SSLContextService)1 MotechEvent (org.motechproject.event.MotechEvent)1