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();
}
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()));
}
}
}
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);
}
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());
}
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"));
}
Aggregations