Search in sources :

Example 51 with Cookie

use of javax.ws.rs.core.Cookie in project keywhiz by square.

the class UserAuthFactoryTest method noSessionCookie.

@Test(expected = NotAuthorizedException.class)
public void noSessionCookie() throws Exception {
    cookies.put("not-session", new Cookie("not-session", "value"));
    factory.provide(request);
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 52 with Cookie

use of javax.ws.rs.core.Cookie in project keywhiz by square.

the class UserAuthFactoryTest method successfulAuth.

@Test
public void successfulAuth() throws Exception {
    User user = User.named("username");
    Cookie sessionCookie = new Cookie("session", "valid-session");
    cookies.put(sessionCookie.getName(), sessionCookie);
    when(cookieAuthenticator.authenticate(sessionCookie)).thenReturn(Optional.of(user));
    assertThat(factory.provide(request)).isEqualTo(user);
}
Also used : Cookie(javax.ws.rs.core.Cookie) User(keywhiz.auth.User) Test(org.junit.Test)

Example 53 with Cookie

use of javax.ws.rs.core.Cookie in project keywhiz by square.

the class UserAuthFactoryTest method invalidSessionCookie.

@Test(expected = NotAuthorizedException.class)
public void invalidSessionCookie() throws Exception {
    Cookie badSessionCookie = new Cookie("session", "bad-value");
    cookies.put(badSessionCookie.getName(), badSessionCookie);
    when(cookieAuthenticator.authenticate(badSessionCookie)).thenReturn(Optional.empty());
    factory.provide(request);
}
Also used : Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 54 with Cookie

use of javax.ws.rs.core.Cookie in project OpenAM by OpenRock.

the class ListenerRestTest method setup.

@BeforeClass
public void setup() throws Exception {
    try {
        agent = IdRepoUtils.createAgent(REALM, AGENT_NAME);
        SSOToken ssoToken = AuthUtils.authenticate(REALM, AGENT_NAME, AGENT_NAME);
        String userTokenId = ssoToken.getTokenID().toString();
        hashedTokenId = Hash.hash(userTokenId);
        tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + userTokenId;
        String cookieValue = userTokenId;
        if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
            cookieValue = URLEncoder.encode(userTokenId, "UTF-8");
        }
        cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
        PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME);
        Map<String, Boolean> actions = new HashMap<String, Boolean>();
        actions.put("GET", true);
        Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
        privilege.setEntitlement(entitlement);
        EntitlementSubject sbj = new AuthenticatedUsers();
        privilege.setSubject(sbj);
        pm.add(privilege);
        listenerClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/listener");
        ENC_NOTIFICATION_URL = ESAPI.encoder().encodeForURL(NOTIFICATION_URL);
    } catch (Exception e) {
        UnittestLog.logError("ListenerRestTest.setup() failed:", e);
        throw e;
    }
}
Also used : Cookie(javax.ws.rs.core.Cookie) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) SSOToken(com.iplanet.sso.SSOToken) HashMap(java.util.HashMap) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) Entitlement(com.sun.identity.entitlement.Entitlement) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EncodingException(org.owasp.esapi.errors.EncodingException) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BeforeClass(org.testng.annotations.BeforeClass)

Example 55 with Cookie

use of javax.ws.rs.core.Cookie in project OpenAM by OpenRock.

the class ListenerRestTest method getListener.

private String getListener(String url) throws UnsupportedEncodingException, EncodingException {
    String adminTokenId = adminToken.getTokenID().toString();
    String adminHashedTokenId = Hash.hash(adminTokenId);
    String adminTokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + adminTokenId;
    String cookieValue = adminTokenId;
    if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
        cookieValue = URLEncoder.encode(adminTokenId, "UTF-8");
    }
    cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
    String encodedURL = ESAPI.encoder().encodeForURL(url);
    String result = listenerClient.path(encodedURL).queryParam("subject", adminHashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, adminTokenIdHeader).cookie(cookie).get(String.class);
    return result;
}
Also used : Cookie(javax.ws.rs.core.Cookie)

Aggregations

Cookie (javax.ws.rs.core.Cookie)80 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)18 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 NewCookie (javax.ws.rs.core.NewCookie)7 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)7 Map (java.util.Map)5 Message (org.apache.cxf.message.Message)5 Entitlement (com.sun.identity.entitlement.Entitlement)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)4 Privilege (com.sun.identity.entitlement.Privilege)4 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 HttpHeaders (javax.ws.rs.core.HttpHeaders)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 BeforeClass (org.testng.annotations.BeforeClass)4 SSOToken (com.iplanet.sso.SSOToken)3