use of org.apache.http.client.CookieStore in project nanohttpd by NanoHttpd.
the class CookieIntegrationTest method testCookieSentBackToClient.
@Test
public void testCookieSentBackToClient() throws Exception {
this.testServer.cookiesToSend.add(new Cookie("name", "value", 30));
HttpGet httpget = new HttpGet("http://localhost:8192/");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
this.httpclient.execute(httpget, responseHandler);
CookieStore cookies = this.httpclient.getCookieStore();
assertEquals(1, cookies.getCookies().size());
assertEquals("name", cookies.getCookies().get(0).getName());
assertEquals("value", cookies.getCookies().get(0).getValue());
}
use of org.apache.http.client.CookieStore in project undertow by undertow-io.
the class ServletSessionTestCase method testSessionConfigNoCookies.
@Test
public void testSessionConfigNoCookies() throws IOException {
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new CookieStore() {
@Override
public void addCookie(Cookie cookie) {
}
@Override
public List<Cookie> getCookies() {
return Collections.EMPTY_LIST;
}
@Override
public boolean clearExpired(Date date) {
return false;
}
@Override
public void clear() {
}
});
try {
HttpResponse result = client.execute(new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa/b;foo=bar"));
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
String response = HttpClientUtils.readResponse(result);
Assert.assertEquals("1", response);
String url = result.getHeaders("url")[0].getValue();
result = client.execute(new HttpGet(url));
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
url = result.getHeaders("url")[0].getValue();
Assert.assertEquals("2", response);
result = client.execute(new HttpGet(url));
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
response = HttpClientUtils.readResponse(result);
Assert.assertEquals("3", response);
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.client.CookieStore in project wildfly by wildfly.
the class SSOTestBase method executeFormAuthSSOTimeoutTest.
/**
* Test single sign-on across two web apps using form based auth.
*
* Test that after session timeout SSO is destroyed.
*
* @throws Exception
*/
public static void executeFormAuthSSOTimeoutTest(URL serverA, URL serverB, Logger log) throws Exception {
URL warA1 = new URL(serverA, "/war1/");
URL warB2 = new URL(serverB, "/war2/");
// Start by accessing the secured index.html of war1
CookieStore store = new BasicCookieStore();
HttpClient httpclient = TestHttpClientUtils.promiscuousCookieHttpClientBuilder().setDefaultCookieStore(store).disableRedirectHandling().build();
try {
checkAccessDenied(httpclient, warA1 + "index.html");
log.debug("Saw JSESSIONID=" + getSessionIdValueFromState(store));
// Submit the login form
executeFormLogin(httpclient, warA1);
String ssoID = processSSOCookie(store, serverA.toString(), serverB.toString());
log.debug("Saw JSESSIONIDSSO=" + ssoID);
// After login I should still have access + set session timeout to 5 seconds
checkAccessAllowed(httpclient, warA1 + "set_session_timeout.jsp");
// Also access to war2 should be granted + set session timeout to 5 seconds
checkAccessAllowed(httpclient, warB2 + "set_session_timeout.jsp");
// wait 5 seconds session timeout + 1 seconds reserve
Thread.sleep((5 + 1) * 1000);
// After timeout I should be not able to access the app
checkAccessDenied(httpclient, warA1 + "index.html");
checkAccessDenied(httpclient, warB2 + "index.html");
} finally {
HttpClientUtils.closeQuietly(httpclient);
}
}
use of org.apache.http.client.CookieStore in project wildfly by wildfly.
the class SSOTestBase method executeNoAuthSingleSignOnTest.
public static void executeNoAuthSingleSignOnTest(URL serverA, URL serverB, Logger log) throws Exception {
URL warA1 = new URL(serverA, "/war1/");
URL warB2 = new URL(serverB + "/war2/");
URL warB6 = new URL(serverB + "/war6/");
// Start by accessing the secured index.html of war1
CookieStore store = new BasicCookieStore();
HttpClient httpclient = TestHttpClientUtils.promiscuousCookieHttpClientBuilder().setDefaultCookieStore(store).build();
try {
checkAccessDenied(httpclient, warA1 + "index.html");
log.debug("Saw JSESSIONID=" + getSessionIdValueFromState(store));
// Submit the login form
executeFormLogin(httpclient, warA1);
String ssoID = processSSOCookie(store, serverA.toString(), serverB.toString());
log.debug("Saw JSESSIONIDSSO=" + ssoID);
// Now try getting the war2 index using the JSESSIONIDSSO cookie
log.debug("Prepare /war2/index.html get");
checkAccessAllowed(httpclient, warB2 + "index.html");
// Access a secured servlet that calls a secured ejb in war2 to test
// propagation of the SSO identity to the ejb container.
checkAccessAllowed(httpclient, warB2 + "EJBServlet");
// Do the same test on war6 to test SSO auth replication with no auth
// configured war
checkAccessAllowed(httpclient, warB6 + "index.html");
checkAccessAllowed(httpclient, warB2 + "EJBServlet");
} finally {
HttpClientUtils.closeQuietly(httpclient);
}
}
use of org.apache.http.client.CookieStore in project XobotOS by xamarin.
the class ResponseProcessCookies method process.
public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
if (response == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
// Obtain cookie store
CookieStore cookieStore = (CookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
if (cookieStore == null) {
this.log.info("Cookie store not available in HTTP context");
return;
}
// Obtain actual CookieSpec instance
CookieSpec cookieSpec = (CookieSpec) context.getAttribute(ClientContext.COOKIE_SPEC);
if (cookieSpec == null) {
this.log.info("CookieSpec not available in HTTP context");
return;
}
// Obtain actual CookieOrigin instance
CookieOrigin cookieOrigin = (CookieOrigin) context.getAttribute(ClientContext.COOKIE_ORIGIN);
if (cookieOrigin == null) {
this.log.info("CookieOrigin not available in HTTP context");
return;
}
HeaderIterator it = response.headerIterator(SM.SET_COOKIE);
processCookies(it, cookieSpec, cookieOrigin, cookieStore);
// see if the cookie spec supports cookie versioning.
if (cookieSpec.getVersion() > 0) {
// process set-cookie2 headers.
// Cookie2 will replace equivalent Cookie instances
it = response.headerIterator(SM.SET_COOKIE2);
processCookies(it, cookieSpec, cookieOrigin, cookieStore);
}
}
Aggregations