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