Example usage for org.openqa.selenium Cookie Cookie

List of usage examples for org.openqa.selenium Cookie Cookie

Introduction

In this page you can find the example usage for org.openqa.selenium Cookie Cookie.

Prototype

public Cookie(String name, String value, String domain, String path, Date expiry, boolean isSecure,
        boolean isHttpOnly) 

Source Link

Document

Creates a cookie.

Usage

From source file:com.cognifide.qa.bb.cookies.domain.CookieData.java

License:Apache License

/**
 * @return adapter to {@link org.openqa.selenium.Cookie}
 *//*from www. j  a v a 2 s. c om*/
public Cookie convertToSeleniumCookie() {
    return new Cookie(name, value, domain, path, expiry, secure, httpOnly);
}

From source file:org.keycloak.testsuite.admin.ImpersonationTest.java

License:Apache License

private Cookie impersonate(Keycloak adminClient, String admin, String adminRealm) {
    Client httpClient = javax.ws.rs.client.ClientBuilder.newClient();

    try (Response response = httpClient.target(OAuthClient.AUTH_SERVER_ROOT).path("admin").path("realms")
            .path("test").path("users/" + impersonatedUserId + "/impersonation").request()
            .header(HttpHeaders.AUTHORIZATION, "Bearer " + adminClient.tokenManager().getAccessTokenString())
            .post(null)) {//  www .  j  ava2  s  . c o  m

        Map data = response.readEntity(Map.class);

        Assert.assertNotNull(data);
        Assert.assertNotNull(data.get("redirect"));

        events.expect(EventType.IMPERSONATE).session(AssertEvents.isUUID()).user(impersonatedUserId)
                .detail(Details.IMPERSONATOR, admin).detail(Details.IMPERSONATOR_REALM, adminRealm)
                .client((String) null).assertEvent();

        // Fetch user session notes
        final String userId = impersonatedUserId;
        final UserSessionNotesHolder notesHolder = testingClient.server("test").fetch(session -> {
            final RealmModel realm = session.realms().getRealmByName("test");
            final UserModel user = session.users().getUserById(userId, realm);
            final UserSessionModel userSession = session.sessions().getUserSessions(realm, user).get(0);
            return new UserSessionNotesHolder(userSession.getNotes());
        }, UserSessionNotesHolder.class);

        // Check impersonation details
        final Map<String, String> notes = notesHolder.getNotes();
        Assert.assertNotNull(notes.get(ImpersonationSessionNote.IMPERSONATOR_ID.toString()));
        Assert.assertEquals(admin, notes.get(ImpersonationSessionNote.IMPERSONATOR_USERNAME.toString()));

        NewCookie cookie = response.getCookies().get(AuthenticationManager.KEYCLOAK_IDENTITY_COOKIE);
        Assert.assertNotNull(cookie);

        return new Cookie(cookie.getName(), cookie.getValue(), cookie.getDomain(), cookie.getPath(),
                cookie.getExpiry(), cookie.isSecure(), cookie.isHttpOnly());
    }
}