Search in sources :

Example 86 with Privilege

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

the class JsonPolicyParserTest method shouldPrintResourceAttributes.

@Test
public void shouldPrintResourceAttributes() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    ResourceAttribute userAttrs = new UserAttributes();
    String userAttrName = "testUserAttribute";
    userAttrs.setPropertyName(userAttrName);
    StaticAttributes staticAttributes = new StaticAttributes();
    String staticAttrName = "testStaticAttribute";
    staticAttributes.setPropertyName(staticAttrName);
    Set<String> staticAttrValue = CollectionUtils.asSet("one", "two", "three");
    staticAttributes.setPropertyValues(staticAttrValue);
    policy.setResourceAttributes(new LinkedHashSet<ResourceAttribute>(Arrays.asList(userAttrs, staticAttributes)));
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("resourceAttributes").asList()).hasSize(2);
    assertThat(result.get(new JsonPointer("resourceAttributes/0/type")).asString()).isEqualTo("User");
    assertThat(result.get(new JsonPointer("resourceAttributes/0/propertyName")).asString()).isEqualTo(userAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/type")).asString()).isEqualTo("Static");
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyName")).asString()).isEqualTo(staticAttrName);
    assertThat(result.get(new JsonPointer("resourceAttributes/1/propertyValues")).asList(String.class)).containsOnly(staticAttrValue.toArray());
}
Also used : JsonValue(org.forgerock.json.JsonValue) StaticAttributes(com.sun.identity.entitlement.StaticAttributes) JsonPointer(org.forgerock.json.JsonPointer) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ResourceAttribute(com.sun.identity.entitlement.ResourceAttribute) UserAttributes(com.sun.identity.entitlement.UserAttributes) Test(org.testng.annotations.Test)

Example 87 with Privilege

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

the class JsonPolicyParserTest method shouldNotAllowSettingCreatedBy.

@Test
public void shouldNotAllowSettingCreatedBy() throws Exception {
    // Given
    JsonValue content = buildJson(field("createdBy", "Bobby Tables"));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getCreatedBy()).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 88 with Privilege

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

the class JsonPolicyParserTest method shouldPrintPolicyApplicationName.

@Test
public void shouldPrintPolicyApplicationName() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    policy.setEntitlement(new Entitlement());
    String applicationName = "testApp";
    policy.getEntitlement().setApplicationName(applicationName);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get("applicationName").asString()).isEqualTo(applicationName);
}
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 89 with Privilege

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

the class JsonPolicyParserTest method shouldParseResources.

@Test
public void shouldParseResources() throws Exception {
    // Given
    List<String> included = Arrays.asList("one", "two", "three");
    JsonValue content = json(object(field("resources", included)));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getEntitlement().getResourceNames()).containsOnly(included.toArray());
}
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 90 with Privilege

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

the class JsonPolicyParserTest method shouldParseNestedOrConditions.

@Test
public void shouldParseNestedOrConditions() throws Exception {
    // Given
    // An OR condition containing a single OAuth2Scope condition
    String scope = "givenName";
    JsonValue content = buildJson(field("condition", object(field("type", "OR"), 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(OrCondition.class);
    OrCondition or = (OrCondition) result.getCondition();
    assertThat(or.getEConditions()).hasSize(1);
    assertThat(or.getEConditions().iterator().next()).isInstanceOf(OAuth2ScopeCondition.class);
    OAuth2ScopeCondition oauth2Scope = (OAuth2ScopeCondition) or.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) OrCondition(com.sun.identity.entitlement.OrCondition) 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