Search in sources :

Example 76 with Privilege

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

the class JsonPolicyParserTest method shouldPrintPolicyName.

@Test
public void shouldPrintPolicyName() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    String name = "test name";
    policy.setName(name);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("name").asString()).isEqualTo(name);
}
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 77 with Privilege

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

the class JsonPolicyParserTest method shouldPrintSimpleSubjects.

@Test
public void shouldPrintSimpleSubjects() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setSubject(new AuthenticatedUsers());
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get(new JsonPointer("subject/type")).asString()).isEqualTo("AuthenticatedUsers");
}
Also used : AuthenticatedUsers(org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers) JsonValue(org.forgerock.json.JsonValue) JsonPointer(org.forgerock.json.JsonPointer) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 78 with Privilege

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

the class JsonPolicyParserTest method shouldAllowLegacyPolicyConditions.

@Test
public void shouldAllowLegacyPolicyConditions() throws Exception {
    // Given
    List<String> realm = Arrays.asList("REALM");
    JsonValue content = buildJson(field("condition", object(field("type", "Policy"), field("className", AuthenticateToRealmCondition.class.getName()), field("properties", object(field("AuthenticateToRealm", realm))))));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getCondition()).isInstanceOf(PolicyCondition.class);
    PolicyCondition condition = (PolicyCondition) result.getCondition();
    assertThat(condition.getClassName()).isEqualTo(AuthenticateToRealmCondition.class.getName());
    assertThat(condition.getProperties()).isEqualTo(Collections.singletonMap("AuthenticateToRealm", new HashSet<String>(realm)));
}
Also used : JsonValue(org.forgerock.json.JsonValue) AuthenticateToRealmCondition(com.sun.identity.policy.plugins.AuthenticateToRealmCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.testng.annotations.Test)

Example 79 with Privilege

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

the class JsonPolicyParserTest method shouldPrintPolicyResourceSet.

@Test
public void shouldPrintPolicyResourceSet() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    Set<String> included = CollectionUtils.asSet("one", "two", "three");
    Entitlement resources = new Entitlement();
    resources.setResourceNames(included);
    policy.setEntitlement(resources);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("resources").asList()).containsOnly(included.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Entitlement(com.sun.identity.entitlement.Entitlement) Test(org.testng.annotations.Test)

Example 80 with Privilege

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

the class JsonPolicyParserTest method shouldPrintPolicyActionValues.

@Test
public void shouldPrintPolicyActionValues() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setEntitlement(new Entitlement());
    Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
    actionValues.put("one", true);
    actionValues.put("two", false);
    policy.getEntitlement().setActionValues(actionValues);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("actionValues").asMap(Boolean.class)).isEqualTo(actionValues);
}
Also used : HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Entitlement(com.sun.identity.entitlement.Entitlement) 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