use of org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldCorrectlyParseConditionTypes.
@Test
public void shouldCorrectlyParseConditionTypes() throws Exception {
// Given
String scope = "givenName";
JsonValue content = buildJson(field("condition", object(field("type", "OAuth2Scope"), field("requiredScopes", array(scope)))));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getCondition()).isInstanceOf(OAuth2ScopeCondition.class);
assertThat(((OAuth2ScopeCondition) result.getCondition()).getRequiredScopes()).isEqualTo(Collections.singleton(scope));
}
use of org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition 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));
}
use of org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition 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 org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition 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