Search in sources :

Example 46 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)

Example 47 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 48 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 49 with Cookie

use of javax.ws.rs.core.Cookie in project simba-os by cegeka.

the class SimbaRoleService method addRoleToUser.

public void addRoleToUser(String ssoToken, SimbaRoleR simbaRole, SimbaUserR simbaUser) {
    checkRoleNotNull(simbaRole);
    checkUserNotNull(simbaUser);
    AddRoleToUsersR postEntity = new AddRoleToUsersR(simbaRole, simbaUser);
    ClientResponse clientResponse = getSimbaResource().path("role").path("addUsers").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).cookie(new Cookie(AuthenticationConstants.SIMBA_SSO_TOKEN, ssoToken)).post(ClientResponse.class, postEntity);
    handleError("addRole", simbaRole.getName(), simbaUser.getUserName(), clientResponse, logger);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Cookie(javax.ws.rs.core.Cookie) AddRoleToUsersR(org.simbasecurity.dwclient.gateway.representations.AddRoleToUsersR)

Aggregations

Cookie (javax.ws.rs.core.Cookie)49 Test (org.junit.Test)28 HashMap (java.util.HashMap)7 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)7 NewCookie (javax.ws.rs.core.NewCookie)6 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 BeforeClass (org.testng.annotations.BeforeClass)4 SSOToken (com.iplanet.sso.SSOToken)3 Form (javax.ws.rs.core.Form)3 AuthenticatedUsers (org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers)3 JSONEntitlement (com.sun.identity.entitlement.JSONEntitlement)2 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Consumes (javax.ws.rs.Consumes)2