Search in sources :

Example 1 with ConfiguredUsernamePassword

use of com.adaptris.core.http.auth.ConfiguredUsernamePassword in project interlok by adaptris.

the class EmbeddedHttpConsumerTest method testBasicConsumeWorkflow_WithACL.

@Test
public void testBasicConsumeWorkflow_WithACL() throws Exception {
    EmbeddedJettyHelper helper = new EmbeddedJettyHelper();
    helper.startServer();
    MockMessageProducer mockProducer = new MockMessageProducer();
    EmbeddedConnection embedded = new EmbeddedConnection();
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    csh.setAuthenticator(new BasicAuthenticatorFactory());
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    securityConstraint.setPaths(Arrays.asList("/"));
    securityConstraint.setConstraintName(Constraint.__BASIC_AUTH);
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    embedded.setSecurityHandler(csh);
    Channel channel = JettyHelper.createChannel(embedded, JettyHelper.createConsumer(URL_TO_POST_TO), mockProducer);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
        msg.addMetadata(CONTENT_TYPE_METADATA_KEY, "text/xml");
        httpProducer.setAuthenticator(new ConfiguredUsernamePassword("user", "password"));
        httpProducer.setUrl(helper.createProduceDestination());
        start(httpProducer);
        AdaptrisMessage reply = httpProducer.request(msg);
        assertEquals("Reply Payloads", XML_PAYLOAD, reply.getContent());
        doAssertions(mockProducer);
    } finally {
        stop(httpProducer);
        stop(channel);
        helper.stopServer();
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) StaticMockMessageProducer(com.adaptris.core.stubs.StaticMockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Channel(com.adaptris.core.Channel) ConfiguredUsernamePassword(com.adaptris.core.http.auth.ConfiguredUsernamePassword) Test(org.junit.Test)

Example 2 with ConfiguredUsernamePassword

use of com.adaptris.core.http.auth.ConfiguredUsernamePassword in project interlok by adaptris.

the class HttpRequestServiceTest method buildAuthenticator.

protected static HttpAuthenticator buildAuthenticator(String username, String password) {
    ConfiguredUsernamePassword auth = new ConfiguredUsernamePassword();
    auth.setUsername(username);
    auth.setPassword(password);
    return auth;
}
Also used : ConfiguredUsernamePassword(com.adaptris.core.http.auth.ConfiguredUsernamePassword)

Aggregations

ConfiguredUsernamePassword (com.adaptris.core.http.auth.ConfiguredUsernamePassword)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 Channel (com.adaptris.core.Channel)1 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)1 StaticMockMessageProducer (com.adaptris.core.stubs.StaticMockMessageProducer)1 Test (org.junit.Test)1