use of org.apache.http.impl.client.BasicCookieStore in project zm-mailbox by Zimbra.
the class TestProvIDN method testBasicAuth.
@Test
public void testBasicAuth() throws Exception {
Names.IDNName domainName = new Names.IDNName(makeTestDomainName("basicAuthTest."));
Domain domain = createDomain(domainName.uName(), domainName.uName());
Names.IDNName acctName = new Names.IDNName("acct", domainName.uName());
Account acct = (Account) createTest(EntryType.ACCOUNT, NameType.UNAME, acctName);
BasicCookieStore initialState = new BasicCookieStore();
/*
Cookie authCookie = new Cookie(restURL.getURL().getHost(), "ZM_AUTH_TOKEN", mAuthToken, "/", null, false);
Cookie sessionCookie = new Cookie(restURL.getURL().getHost(), "JSESSIONID", mSessionId, "/zimbra", null, false);
initialState.addCookie(authCookie);
initialState.addCookie(sessionCookie);
*/
String guestName = acct.getUnicodeName();
String guestPassword = "test123";
Credentials loginCredentials = new UsernamePasswordCredentials(guestName, guestPassword);
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY, loginCredentials);
Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.BASIC, new BasicSchemeFactory(Consts.UTF_8)).build();
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setDefaultCookieStore(initialState);
clientBuilder.setDefaultCredentialsProvider(credsProvider);
clientBuilder.setDefaultAuthSchemeRegistry(authSchemeRegistry);
String url = UserServlet.getRestUrl(acct) + "/Calendar";
System.out.println("REST URL: " + url);
HttpRequestBase method = new HttpGet(url);
HttpClient client = clientBuilder.build();
try {
HttpResponse response = HttpClientUtil.executeMethod(client, method);
int respCode = response.getStatusLine().getStatusCode();
if (respCode != HttpStatus.SC_OK) {
System.out.println("failed, respCode=" + respCode);
} else {
boolean chunked = false;
boolean textContent = false;
/*
System.out.println("Headers:");
System.out.println("--------");
for (Header header : method.getRequestHeaders()) {
System.out.print(" " + header.toString());
}
System.out.println();
System.out.println("Body:");
System.out.println("-----");
String respBody = method.getResponseBodyAsString();
System.out.println(respBody);
*/
}
} finally {
// Release the connection.
method.releaseConnection();
}
}
use of org.apache.http.impl.client.BasicCookieStore in project ddf by codice.
the class HttpClientBuilder method get.
@Override
public final org.apache.http.impl.client.HttpClientBuilder get() {
final org.apache.http.impl.client.HttpClientBuilder httpClientBuilder = HttpClients.custom().setDefaultCookieStore(new BasicCookieStore()).setMaxConnTotal(128).setMaxConnPerRoute(32);
if (useTls()) {
String[] defaultProtocols = AccessController.doPrivileged((PrivilegedAction<String[]>) () -> commaSeparatedToArray(System.getProperty(HTTPS_PROTOCOLS)));
String[] defaultCipherSuites = AccessController.doPrivileged((PrivilegedAction<String[]>) () -> commaSeparatedToArray(System.getProperty(HTTPS_CIPHER_SUITES)));
httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(getSslContext(), defaultProtocols, defaultCipherSuites, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER));
}
if (isConfiguredForBasicAuth()) {
httpClientBuilder.setDefaultCredentialsProvider(getCredentialsProvider());
httpClientBuilder.addInterceptorFirst(new PreemptiveAuth(new BasicScheme()));
}
return httpClientBuilder;
}
use of org.apache.http.impl.client.BasicCookieStore in project ddf by codice.
the class LogoutMessageImpl method sendSamlLogoutRequest.
@Override
public String sendSamlLogoutRequest(LogoutWrapper request, String targetUri, boolean isSoap, @Nullable Cookie cookie) throws IOException, LogoutSecurityException {
XMLObject xmlObject = isSoap ? SamlProtocol.createSoapMessage((SignableSAMLObject) request.getMessage()) : (XMLObject) request;
Element requestElement = getElementFromSaml(new LogoutWrapperImpl(xmlObject));
String requestMessage = DOM2Writer.nodeToString(requestElement);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost post = new HttpPost(targetUri);
post.addHeader("Cache-Control", "no-cache, no-store");
post.addHeader("Pragma", "no-cache");
post.addHeader("SOAPAction", SAML_SOAP_ACTION);
post.addHeader("Content-Type", "application/soap+xml");
post.setEntity(new StringEntity(requestMessage, "utf-8"));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
BasicHttpContext context = new BasicHttpContext();
if (cookie != null) {
BasicClientCookie basicClientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
basicClientCookie.setDomain(cookie.getDomain());
basicClientCookie.setPath(cookie.getPath());
BasicCookieStore cookieStore = new BasicCookieStore();
cookieStore.addCookie(basicClientCookie);
context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
}
return httpClient.execute(post, responseHandler, context);
}
}
use of org.apache.http.impl.client.BasicCookieStore in project oxTrust by GluuFederation.
the class ShibbolethReloadService method getHttpClient.
private CloseableHttpClient getHttpClient() {
final CookieStore cookieStore = new BasicCookieStore();
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
final RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.DEFAULT).setExpectContinueEnabled(true).build();
return HttpClients.custom().setConnectionManager(connectionManager).setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credentialsProvider).setDefaultRequestConfig(defaultRequestConfig).build();
}
use of org.apache.http.impl.client.BasicCookieStore in project cxf by apache.
the class AsyncHTTPConduitFactory method setupNIOClient.
public synchronized void setupNIOClient(HTTPClientPolicy clientPolicy) throws IOReactorException {
if (client != null) {
return;
}
IOReactorConfig config = IOReactorConfig.custom().setIoThreadCount(ioThreadCount).setSelectInterval(selectInterval).setInterestOpQueued(interestOpQueued).setSoLinger(soLinger).setSoTimeout(soTimeout).setSoKeepAlive(soKeepalive).setTcpNoDelay(tcpNoDelay).build();
Registry<SchemeIOSessionStrategy> ioSessionFactoryRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create().register("http", NoopIOSessionStrategy.INSTANCE).register("https", SSLIOSessionStrategy.getSystemDefaultStrategy()).build();
ManagedNHttpClientConnectionFactory connectionFactory = new ManagedNHttpClientConnectionFactory();
DefaultConnectingIOReactor ioreactor = new DefaultConnectingIOReactor(config);
connectionManager = new PoolingNHttpClientConnectionManager(ioreactor, connectionFactory, ioSessionFactoryRegistry, DefaultSchemePortResolver.INSTANCE, SystemDefaultDnsResolver.INSTANCE, connectionTTL, TimeUnit.MILLISECONDS);
connectionManager.setDefaultMaxPerRoute(maxPerRoute);
connectionManager.setMaxTotal(maxConnections);
ConnectionConfig connectionConfig = ConnectionConfig.custom().setBufferSize(clientPolicy.getChunkLength() > 0 ? clientPolicy.getChunkLength() : 16332).build();
connectionManager.setDefaultConnectionConfig(connectionConfig);
RedirectStrategy redirectStrategy = new RedirectStrategy() {
public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return false;
}
public HttpUriRequest getRedirect(HttpRequest request, HttpResponse response, HttpContext context) throws ProtocolException {
return null;
}
};
HttpAsyncClientBuilder httpAsyncClientBuilder = HttpAsyncClients.custom().setConnectionManager(connectionManager).setRedirectStrategy(redirectStrategy).setDefaultCookieStore(new BasicCookieStore() {
private static final long serialVersionUID = 1L;
public void addCookie(Cookie cookie) {
}
});
adaptClientBuilder(httpAsyncClientBuilder);
client = httpAsyncClientBuilder.build();
// Start the client thread
client.start();
// Always start the idle checker thread to validate pending requests and
// use the ConnectionMaxIdle to close the idle connection
new CloseIdleConnectionThread(connectionManager, client).start();
}
Aggregations