Search in sources :

Example 96 with BasicCookieStore

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();
    }
}
Also used : BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 97 with BasicCookieStore

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();
    }
}
Also used : BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) Header(org.apache.http.Header) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 98 with BasicCookieStore

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);
}
Also used : BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Example 99 with BasicCookieStore

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);
    }
}
Also used : CookieStore(org.apache.http.client.CookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpClient(org.apache.http.client.HttpClient) URL(java.net.URL)

Example 100 with BasicCookieStore

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);
    }
}
Also used : CookieStore(org.apache.http.client.CookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) BasicCookieStore(org.apache.http.impl.client.BasicCookieStore) HttpClient(org.apache.http.client.HttpClient) URL(java.net.URL)

Aggregations

BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)138 HttpResponse (org.apache.http.HttpResponse)54 HttpGet (org.apache.http.client.methods.HttpGet)51 Test (org.junit.Test)44 BasicClientCookie (org.apache.http.impl.cookie.BasicClientCookie)40 RequestConfig (org.apache.http.client.config.RequestConfig)36 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)36 CookieStore (org.apache.http.client.CookieStore)26 Header (org.apache.http.Header)25 HttpClient (org.apache.http.client.HttpClient)25 IOException (java.io.IOException)23 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)22 Cookie (org.apache.http.cookie.Cookie)19 HttpPost (org.apache.http.client.methods.HttpPost)15 CredentialsProvider (org.apache.http.client.CredentialsProvider)14 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)14 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)14 BasicHttpContext (org.apache.http.protocol.BasicHttpContext)13 URI (java.net.URI)12 HttpEntity (org.apache.http.HttpEntity)12