Search in sources :

Example 1 with OAuth2ScopeCondition

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));
}
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) Test(org.testng.annotations.Test)

Example 2 with OAuth2ScopeCondition

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));
}
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 3 with OAuth2ScopeCondition

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));
}
Also used : OAuth2ScopeCondition(org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition) NotCondition(com.sun.identity.entitlement.NotCondition) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 4 with OAuth2ScopeCondition

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));
}
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)4 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)4 JsonValue (org.forgerock.json.JsonValue)4 OAuth2ScopeCondition (org.forgerock.openam.entitlement.conditions.environment.OAuth2ScopeCondition)4 Test (org.testng.annotations.Test)4 AndCondition (com.sun.identity.entitlement.AndCondition)1 NotCondition (com.sun.identity.entitlement.NotCondition)1 OrCondition (com.sun.identity.entitlement.OrCondition)1