Search in sources :

Example 1 with ConfigurableSecurityHandler

use of com.adaptris.core.http.jetty.ConfigurableSecurityHandler in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithUsernamePassword.

@Test
public void testProduce_WithUsernamePassword() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    HttpAuthenticator auth = getAuthenticator(getName(), getName());
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        waitForMessages(mockProducer, 1);
        assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) NullConnection(com.adaptris.core.NullConnection) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 2 with ConfigurableSecurityHandler

use of com.adaptris.core.http.jetty.ConfigurableSecurityHandler in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithUsernamePassword_BadCredentials.

@Test
public void testProduce_WithUsernamePassword_BadCredentials() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    HttpAuthenticator auth = getAuthenticator(getName(), getName());
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        fail();
    } catch (ProduceException expected) {
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) ProduceException(com.adaptris.core.ProduceException) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) NullConnection(com.adaptris.core.NullConnection) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 3 with ConfigurableSecurityHandler

use of com.adaptris.core.http.jetty.ConfigurableSecurityHandler in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithDynamicUsernamePassword.

@Test
public void testProduce_WithDynamicUsernamePassword() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    String password = Password.encode(getName(), Password.PORTABLE_PASSWORD);
    HttpAuthenticator auth = new DynamicBasicAuthorizationHeader(getName(), password);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        waitForMessages(mockProducer, 1);
        assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) NullConnection(com.adaptris.core.NullConnection) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 4 with ConfigurableSecurityHandler

use of com.adaptris.core.http.jetty.ConfigurableSecurityHandler in project interlok by adaptris.

the class HttpRequestServiceTest method testProduce_WithUsernamePassword.

@Test
public void testProduce_WithUsernamePassword() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    HttpAuthenticator auth = buildAuthenticator(getName(), getName());
    HttpRequestService service = new HttpRequestService(HttpHelper.createProduceDestination(channel)).withAuthenticator(auth).withMethod("POST");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
    try {
        start(channel);
        execute(service, msg);
        waitForMessages(mockProducer, 1);
        assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
    } finally {
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) Test(org.junit.Test) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest)

Example 5 with ConfigurableSecurityHandler

use of com.adaptris.core.http.jetty.ConfigurableSecurityHandler in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithMetadataUsernamePassword.

@Test
public void testProduce_WithMetadataUsernamePassword() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    MetadataUsernamePassword auth = new MetadataUsernamePassword();
    auth.setUsernameMetadataKey("user-key");
    auth.setPasswordMetadataKey("pass-key");
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        msg.addMetadata("user-key", getName());
        msg.addMetadata("pass-key", getName());
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        waitForMessages(mockProducer, 1);
        assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) MetadataUsernamePassword(com.adaptris.core.http.auth.MetadataUsernamePassword) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) NullConnection(com.adaptris.core.NullConnection) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 Channel (com.adaptris.core.Channel)5 ConfigurableSecurityHandler (com.adaptris.core.http.jetty.ConfigurableSecurityHandler)5 HashLoginServiceFactory (com.adaptris.core.http.jetty.HashLoginServiceFactory)5 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)5 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)5 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)5 JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)5 SecurityConstraint (com.adaptris.core.http.jetty.SecurityConstraint)5 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)5 Test (org.junit.Test)5 NullConnection (com.adaptris.core.NullConnection)4 HttpAuthenticator (com.adaptris.core.http.auth.HttpAuthenticator)4 ProduceException (com.adaptris.core.ProduceException)1 MetadataUsernamePassword (com.adaptris.core.http.auth.MetadataUsernamePassword)1