Search in sources :

Example 26 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldPrintDescription.

@Test
public void shouldPrintDescription() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    String description = "a test description";
    policy.setDescription(description);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("description").asString()).isEqualTo(description);
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 27 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class JsonPolicyParserTest method shouldNotAllowSettingLastModifiedBy.

@Test
public void shouldNotAllowSettingLastModifiedBy() throws Exception {
    // Given
    JsonValue content = buildJson(field("lastModifiedBy", "Little Bobby"));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getLastModifiedBy()).isNull();
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 28 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PrivilegeRestTest method getAndPut.

@Test(dependsOnMethods = "search")
public void getAndPut() throws Exception {
    String result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).get(String.class);
    JSONObject jbody = parseResult(result);
    String jsonStr = jbody.getString(PrivilegeResource.RESULT);
    Privilege privilege = Privilege.getNewInstance(new JSONObject(jsonStr));
    privilege.setDescription("desciption1");
    Form form = new Form();
    form.add("privilege.json", privilege.toMinimalJSONObject());
    result = webClient.path(PRIVILEGE_NAME).queryParam("subject", hashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).put(String.class, form);
    //OK
    validateResult(result, 200, "OK");
}
Also used : JSONObject(org.json.JSONObject) Form(com.sun.jersey.api.representation.Form) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 29 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class MultipleResourceRestTest method setup.

@BeforeClass
public void setup() throws Exception {
    PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
    {
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME + "1");
        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);
    }
    {
        Privilege privilege = Privilege.getNewInstance();
        privilege.setName(PRIVILEGE_NAME + "2");
        Map<String, Boolean> actions = new HashMap<String, Boolean>();
        actions.put("GET", false);
        Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/index.html", 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);
    user = IdRepoUtils.createUser(REALM, "MultipleResourceRestTestUser");
    decisionsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/decisions");
    entitlementsClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/entitlements");
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Cookie(javax.ws.rs.core.Cookie) AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) JSONEntitlement(com.sun.identity.entitlement.JSONEntitlement) Entitlement(com.sun.identity.entitlement.Entitlement) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) BeforeClass(org.testng.annotations.BeforeClass)

Example 30 with Privilege

use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithNotEnvironmentCondition.

@Test
public void shouldMigratePolicyWithNotEnvironmentCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    NotCondition notCondition = mock(NotCondition.class);
    Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
    PolicyCondition condition = mock(PolicyCondition.class);
    notConditions.add(condition);
    EntitlementCondition migratedCondition = mock(EntitlementCondition.class);
    given(policy.getCondition()).willReturn(notCondition);
    given(notCondition.getEConditions()).willReturn(notConditions);
    given(condition.getClassName()).willReturn("CONDITION_CLASS_NAME");
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION_CLASS_NAME"), eq(condition), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<Set> conditionCaptor = ArgumentCaptor.forClass(Set.class);
    verify(notCondition).setEConditions(conditionCaptor.capture());
    assertThat(conditionCaptor.getValue()).hasSize(1).contains(migratedCondition);
    verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
    verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) NotCondition(com.sun.identity.entitlement.NotCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Privilege (com.sun.identity.entitlement.Privilege)122 Test (org.testng.annotations.Test)76 JsonValue (org.forgerock.json.JsonValue)46 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 HashSet (java.util.HashSet)30 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)26 EntitlementException (com.sun.identity.entitlement.EntitlementException)23 IPrivilege (com.sun.identity.entitlement.IPrivilege)23 Entitlement (com.sun.identity.entitlement.Entitlement)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)18 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)17 HashMap (java.util.HashMap)15 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)13 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)11 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)9 SSOToken (com.iplanet.sso.SSOToken)8 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)8 Subject (javax.security.auth.Subject)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)8