Search in sources :

Example 21 with Privilege

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

the class JsonPolicyParserTest method shouldParseApplicationNameAlongsideResource.

@Test
public void shouldParseApplicationNameAlongsideResource() throws Exception {
    // Given
    String applicationName = "a test application";
    JsonValue content = buildJson(null);
    content.put("applicationName", applicationName);
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getEntitlement().getApplicationName()).isEqualTo(applicationName);
}
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 22 with Privilege

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

the class JsonPolicyParserTest method shouldParseNestedAndConditions.

@Test
public void shouldParseNestedAndConditions() throws Exception {
    // Given
    // An AND condition containing a single OAuth2Scope condition
    String scope = "givenName";
    JsonValue content = buildJson(field("condition", object(field("type", "AND"), field("conditions", Collections.singletonList(object(field("type", "OAuth2Scope"), field("requiredScopes", array(scope))))))));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getCondition()).isInstanceOf(AndCondition.class);
    AndCondition and = (AndCondition) result.getCondition();
    assertThat(and.getEConditions()).hasSize(1);
    assertThat(and.getEConditions().iterator().next()).isInstanceOf(OAuth2ScopeCondition.class);
    OAuth2ScopeCondition oauth2Scope = (OAuth2ScopeCondition) and.getEConditions().iterator().next();
    assertThat(oauth2Scope.getRequiredScopes()).isEqualTo(Collections.singleton(scope));
}
Also used : OAuth2ScopeCondition(org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) AndCondition(com.sun.identity.entitlement.AndCondition) Test(org.testng.annotations.Test)

Example 23 with Privilege

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

the class JsonPolicyParserTest method shouldPrintLastModifiedBy.

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

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

the class JsonPolicyParserTest method shouldParsePolicyActiveFlag.

@Test
public void shouldParsePolicyActiveFlag() throws Exception {
    // Given
    JsonValue content = buildJson(field("active", true));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.isActive()).isTrue();
}
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 25 with Privilege

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

the class JsonPolicyParserTest method shouldIgnoreEntitlementAttributes.

@Test
public void shouldIgnoreEntitlementAttributes() throws Exception {
    // Given
    Map<String, List<String>> attributes = Collections.singletonMap("test", Arrays.asList("one", "two"));
    JsonValue content = buildJson(field("attributes", attributes));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getEntitlement().getAttributes()).isNullOrEmpty();
}
Also used : JsonValue(org.forgerock.json.JsonValue) List(java.util.List) 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