Search in sources :

Example 81 with Privilege

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

the class JsonPolicyParserTest method shouldParseNotConditions.

@Test
public void shouldParseNotConditions() throws Exception {
    // Given
    // A NOT condition containing an OAuth2Scope condition
    String scope = "givenName";
    JsonValue content = buildJson(field("condition", object(field("type", "NOT"), field("condition", object(field("type", "OAuth2Scope"), field("requiredScopes", array(scope)))))));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getCondition()).isInstanceOf(NotCondition.class);
    NotCondition not = (NotCondition) result.getCondition();
    assertThat(not.getECondition()).isInstanceOf(OAuth2ScopeCondition.class);
    OAuth2ScopeCondition ip = (OAuth2ScopeCondition) not.getECondition();
    assertThat(ip.getRequiredScopes()).isEqualTo(Collections.singleton(scope));
}
Also used : OAuth2ScopeCondition(org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition) NotCondition(com.sun.identity.entitlement.NotCondition) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 82 with Privilege

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

the class JsonPolicyParserTest method shouldPrintActiveFlag.

@Test
public void shouldPrintActiveFlag() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    boolean active = true;
    policy.setActive(active);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("active").asBoolean()).isEqualTo(active);
}
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 83 with Privilege

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

the class JsonPolicyParserTest method shouldPrintCreatedBy.

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

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

the class JsonPolicyParserTest method shouldNotPrintPolicyAdvice.

@Test
public void shouldNotPrintPolicyAdvice() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setEntitlement(new Entitlement());
    policy.getEntitlement().setAdvices(Collections.singletonMap("one", CollectionUtils.asSet("two")));
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    // "Advice" should not appear on the policy entitlement
    assertThat(result.get("advice").asMapOfList(String.class)).isNullOrEmpty();
}
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 85 with Privilege

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

the class JsonPolicyParserTest method shouldParseComplexSubjects.

@Test
public void shouldParseComplexSubjects() throws Exception {
    // Given
    JsonValue content = buildJson(field("subject", object(field("type", "AND"), field("subjects", Arrays.asList(object(field("type", "AuthenticatedUsers")))))));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getSubject()).isInstanceOf(AndSubject.class);
    AndSubject and = (AndSubject) result.getSubject();
    assertThat(and.getESubjects()).hasSize(1);
    assertThat(and.getESubjects().iterator().next()).isInstanceOf(AuthenticatedUsers.class);
}
Also used : AndSubject(com.sun.identity.entitlement.AndSubject) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) 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