Search in sources :

Example 56 with Cookie

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

the class PrivilegeRestTest method setup.

@BeforeClass
public void setup() throws Exception {
    PrivilegeManager pm = PrivilegeManager.getInstance("/", adminSubject);
    Privilege privilege = Privilege.getNewInstance();
    privilege.setName(PRIVILEGE_NAME);
    privilege.setDescription("desciption");
    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);
    String tokenId = adminToken.getTokenID().toString();
    hashedTokenId = Hash.hash(tokenId);
    tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + tokenId;
    String cookieValue = tokenId;
    if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
        cookieValue = URLEncoder.encode(tokenId, "UTF-8");
    }
    cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
    webClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/privilege");
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Cookie(javax.ws.rs.core.Cookie) 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) BeforeClass(org.testng.annotations.BeforeClass)

Example 57 with Cookie

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

the class RestNoSubjectHeaderTest method setup.

@BeforeClass
public void setup() throws Exception {
    String tokenId = adminToken.getTokenID().toString();
    hashedTokenId = Hash.hash(tokenId);
    String cookieValue = tokenId;
    if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
        cookieValue = URLEncoder.encode(tokenId, "UTF-8");
    }
    cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
    webClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/privilege");
}
Also used : Cookie(javax.ws.rs.core.Cookie) BeforeClass(org.testng.annotations.BeforeClass)

Example 58 with Cookie

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

the class RestPermissionTest method login.

private void login() throws Exception {
    SSOToken ssoToken = AuthUtils.authenticate(REALM, USER_NAME, USER_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);
}
Also used : Cookie(javax.ws.rs.core.Cookie) SSOToken(com.iplanet.sso.SSOToken)

Example 59 with Cookie

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

the class RestTest method setup.

@BeforeClass
public void setup() throws Exception {
    try {
        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);
        NumericAttributeCondition cond = new NumericAttributeCondition();
        cond.setAttributeName(ATTR_NAME);
        cond.setOperator(NumericAttributeCondition.Operator.EQUAL);
        cond.setValue(ATTR_VAL);
        privilege.setCondition(cond);
        pm.add(privilege);
        user = IdRepoUtils.createAgent(REALM, AGENT_NAME);
        SSOToken ssoToken = AuthUtils.authenticate(REALM, AGENT_NAME, AGENT_NAME);
        String userTokenId = ssoToken.getTokenID().toString();
        hashedUserTokenId = Hash.hash(userTokenId);
        userTokenIdHeader = 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);
        String serverURL = SystemProperties.getServerInstanceName();
        decisionClient = Client.create().resource(serverURL + "/ws/1/entitlement/decision");
        decisionsClient = Client.create().resource(serverURL + "/ws/1/entitlement/decisions");
        entitlementClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlement");
        entitlementsClient = Client.create().resource(serverURL + "/ws/1/entitlement/entitlements");
    } catch (Exception e) {
        UnittestLog.logError("RestTest.setup() failed:", e);
        throw e;
    }
}
Also used : Cookie(javax.ws.rs.core.Cookie) SSOToken(com.iplanet.sso.SSOToken) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) HashMap(java.util.HashMap) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Privilege(com.sun.identity.entitlement.Privilege) JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) Entitlement(com.sun.identity.entitlement.Entitlement) BeforeClass(org.testng.annotations.BeforeClass)

Example 60 with Cookie

use of javax.ws.rs.core.Cookie in project camel by apache.

the class BonitaAuthFilterAlreadyConnectedTest method setup.

@Before
public void setup() {
    Map<String, Cookie> resultCookies = new HashMap<>();
    resultCookies.put("JSESSIONID", new Cookie("JSESSIONID", "something"));
    Mockito.when(requestContext.getCookies()).thenReturn(resultCookies);
}
Also used : Cookie(javax.ws.rs.core.Cookie) HashMap(java.util.HashMap) Before(org.junit.Before)

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