Search in sources :

Example 11 with BasicAuthentication

use of org.eclipse.jetty.client.util.BasicAuthentication in project jersey by jersey.

the class AuthTest method testAuthDelete.

@Test
public void testAuthDelete() {
    ClientConfig config = new ClientConfig();
    config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
    config.connectorProvider(new JettyConnectorProvider());
    Client client = ClientBuilder.newClient(config);
    Response response = client.target(getBaseUri()).path(PATH).request().delete();
    assertEquals(response.getStatus(), 204);
    client.close();
}
Also used : Response(javax.ws.rs.core.Response) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 12 with BasicAuthentication

use of org.eclipse.jetty.client.util.BasicAuthentication in project camel by apache.

the class SalesforceComponentVerifier method configureHttpProxy.

private void configureHttpProxy(SalesforceHttpClient httpClient, Map<String, Object> parameters) throws NoSuchOptionException, URISyntaxException {
    Optional<String> httpProxyHost = getOption(parameters, "httpProxyHost", String.class);
    Optional<Integer> httpProxyPort = getOption(parameters, "httpProxyPort", Integer.class);
    Optional<String> httpProxyUsername = getOption(parameters, "httpProxyUsername", String.class);
    Optional<String> httpProxyPassword = getOption(parameters, "httpProxyPassword", String.class);
    if (httpProxyHost.isPresent() && httpProxyPort.isPresent()) {
        Origin.Address address = new Origin.Address(httpProxyHost.get(), httpProxyPort.get());
        Boolean isHttpProxySocks4 = getOption(parameters, "isHttpProxySocks4", Boolean.class, () -> false);
        Boolean isHttpProxySecure = getOption(parameters, "isHttpProxySecure", Boolean.class, () -> true);
        if (isHttpProxySocks4) {
            httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(address, isHttpProxySecure));
        } else {
            httpClient.getProxyConfiguration().getProxies().add(new HttpProxy(address, isHttpProxySecure));
        }
    }
    if (httpProxyUsername.isPresent() && httpProxyPassword.isPresent()) {
        Boolean httpProxyUseDigestAuth = getOption(parameters, "httpProxyUseDigestAuth", Boolean.class, () -> false);
        String httpProxyAuthUri = getMandatoryOption(parameters, "httpProxyAuthUri", String.class);
        String httpProxyRealm = getMandatoryOption(parameters, "httpProxyRealm", String.class);
        if (httpProxyUseDigestAuth) {
            httpClient.getAuthenticationStore().addAuthentication(new DigestAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
        } else {
            httpClient.getAuthenticationStore().addAuthentication(new BasicAuthentication(new URI(httpProxyAuthUri), httpProxyRealm, httpProxyUsername.get(), httpProxyPassword.get()));
        }
    }
}
Also used : Origin(org.eclipse.jetty.client.Origin) DigestAuthentication(org.eclipse.jetty.client.util.DigestAuthentication) URI(java.net.URI) HttpProxy(org.eclipse.jetty.client.HttpProxy) Socks4Proxy(org.eclipse.jetty.client.Socks4Proxy) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication)

Example 13 with BasicAuthentication

use of org.eclipse.jetty.client.util.BasicAuthentication in project jetty.project by eclipse.

the class HttpClientAuthenticationTest method test_BasicAuthentication_ThenRedirect.

@Test
public void test_BasicAuthentication_ThenRedirect() throws Exception {
    startBasic(new AbstractHandler() {

        private final AtomicInteger requests = new AtomicInteger();

        @Override
        public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            if (requests.incrementAndGet() == 1)
                response.sendRedirect(URIUtil.newURI(scheme, request.getServerName(), request.getServerPort(), request.getRequestURI(), null));
        }
    });
    URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
    client.getAuthenticationStore().addAuthentication(new BasicAuthentication(uri, realm, "basic", "basic"));
    final CountDownLatch requests = new CountDownLatch(3);
    Request.Listener.Adapter requestListener = new Request.Listener.Adapter() {

        @Override
        public void onSuccess(Request request) {
            requests.countDown();
        }
    };
    client.getRequestListeners().add(requestListener);
    ContentResponse response = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure").timeout(5, TimeUnit.SECONDS).send();
    Assert.assertNotNull(response);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertTrue(requests.await(5, TimeUnit.SECONDS));
    client.getRequestListeners().remove(requestListener);
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) Test(org.junit.Test)

Example 14 with BasicAuthentication

use of org.eclipse.jetty.client.util.BasicAuthentication in project jetty.project by eclipse.

the class HttpClientAuthenticationTest method test_BasicAuthentication_WithWrongPassword.

@Test
public void test_BasicAuthentication_WithWrongPassword() throws Exception {
    startBasic(new EmptyServerHandler());
    AuthenticationStore authenticationStore = client.getAuthenticationStore();
    URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
    BasicAuthentication authentication = new BasicAuthentication(uri, realm, "basic", "wrong");
    authenticationStore.addAuthentication(authentication);
    Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/secure");
    ContentResponse response = request.timeout(5, TimeUnit.SECONDS).send();
    Assert.assertNotNull(response);
    Assert.assertEquals(401, response.getStatus());
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Request(org.eclipse.jetty.client.api.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) URI(java.net.URI) AuthenticationStore(org.eclipse.jetty.client.api.AuthenticationStore) Test(org.junit.Test)

Example 15 with BasicAuthentication

use of org.eclipse.jetty.client.util.BasicAuthentication in project jetty.project by eclipse.

the class HttpClientAuthenticationTest method test_BasicAuthentication.

@Test
public void test_BasicAuthentication() throws Exception {
    startBasic(new EmptyServerHandler());
    URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
    test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic"));
}
Also used : BasicAuthentication(org.eclipse.jetty.client.util.BasicAuthentication) URI(java.net.URI) Test(org.junit.Test)

Aggregations

BasicAuthentication (org.eclipse.jetty.client.util.BasicAuthentication)23 URI (java.net.URI)17 Test (org.junit.Test)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)9 Request (org.eclipse.jetty.client.api.Request)9 IOException (java.io.IOException)8 ServletException (javax.servlet.ServletException)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AuthenticationStore (org.eclipse.jetty.client.api.AuthenticationStore)6 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 DigestAuthentication (org.eclipse.jetty.client.util.DigestAuthentication)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpClient (org.eclipse.jetty.client.HttpClient)4 HttpProxy (org.eclipse.jetty.client.HttpProxy)4 Authentication (org.eclipse.jetty.client.api.Authentication)4 Client (javax.ws.rs.client.Client)3 Response (javax.ws.rs.core.Response)3 Origin (org.eclipse.jetty.client.Origin)3