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());
}
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();
}
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);
}
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());
}
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));
}
Aggregations