use of org.apache.http.impl.client.BasicCookieStore in project light-session-4j by networknt.
the class HazelCastSessionSingleTest method testGet.
@Test
public void testGet() throws Exception {
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new BasicCookieStore());
try {
HttpGet get = new HttpGet("http://localhost:8080/get");
HttpResponse result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
Header[] header = result.getHeaders(COUNT);
Assertions.assertEquals("0", header[0].getValue());
get = new HttpGet("http://localhost:8080/get");
result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assertions.assertEquals("1", header[0].getValue());
get = new HttpGet("http://localhost:8080/get");
result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assertions.assertEquals("2", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.impl.client.BasicCookieStore in project light-session-4j by networknt.
the class HazelcastSessionMultipleTest method testGet.
@Test
public void testGet() throws Exception {
TestHttpClient client = new TestHttpClient();
client.setCookieStore(new BasicCookieStore());
try {
HttpGet get = new HttpGet("http://localhost:8081/get");
HttpResponse result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
Header[] header = result.getHeaders(COUNT);
Assertions.assertEquals("0", header[0].getValue());
get = new HttpGet("http://localhost:8082/get");
result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assertions.assertEquals("1", header[0].getValue());
get = new HttpGet("http://localhost:8081/get");
result = client.execute(get);
Assertions.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
header = result.getHeaders(COUNT);
Assertions.assertEquals("2", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
}
}
use of org.apache.http.impl.client.BasicCookieStore in project instagram4j by brunocvcunha.
the class Instagram4j method setup.
/**
* Setup some variables
*/
public void setup() {
log.info("Setup...");
if (StringUtils.isEmpty(this.username)) {
throw new IllegalArgumentException("Username is mandatory.");
}
if (StringUtils.isEmpty(this.password)) {
throw new IllegalArgumentException("Password is mandatory.");
}
this.deviceId = InstagramHashUtil.generateDeviceId(this.username, this.password);
if (StringUtils.isEmpty(this.uuid)) {
this.uuid = InstagramGenericUtil.generateUuid(true);
}
if (StringUtils.isEmpty(this.advertisingId)) {
this.advertisingId = InstagramGenericUtil.generateUuid(true);
}
if (this.cookieStore == null) {
this.cookieStore = new BasicCookieStore();
}
log.info("Device ID is: " + this.deviceId + ", random id: " + this.uuid);
this.client = new DefaultHttpClient();
this.client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
this.client.setCookieStore(this.cookieStore);
}
use of org.apache.http.impl.client.BasicCookieStore 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 Jakarta Enterprise Beans in war2 to test
// propagation of the SSO identity to the Jakarta Enterprise Beans 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.impl.client.BasicCookieStore 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);
}
}
Aggregations