Search in sources :

Example 6 with PolicyCondition

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithOrEnvironmentCondition.

@SuppressWarnings("unchecked")
@Test
public void shouldMigratePolicyWithOrEnvironmentCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    OrCondition orCondition = mock(OrCondition.class);
    Set<EntitlementCondition> orConditions = new HashSet<EntitlementCondition>();
    PolicyCondition condition1 = mock(PolicyCondition.class);
    PolicyCondition condition2 = mock(PolicyCondition.class);
    orConditions.add(condition1);
    orConditions.add(condition2);
    EntitlementCondition migratedCondition1 = mock(EntitlementCondition.class);
    EntitlementCondition migratedCondition2 = mock(EntitlementCondition.class);
    given(policy.getCondition()).willReturn(orCondition);
    given(orCondition.getEConditions()).willReturn(orConditions);
    given(condition1.getClassName()).willReturn("CONDITION1_CLASS_NAME");
    given(condition2.getClassName()).willReturn("CONDITION2_CLASS_NAME");
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION1_CLASS_NAME"), eq(condition1), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition1);
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION2_CLASS_NAME"), eq(condition2), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition2);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<Set> conditionsCaptor = ArgumentCaptor.forClass(Set.class);
    verify(orCondition).setEConditions(conditionsCaptor.capture());
    assertThat(conditionsCaptor.getValue()).hasSize(2).contains(migratedCondition1, migratedCondition2);
    verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
    verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) OrCondition(com.sun.identity.entitlement.OrCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 7 with PolicyCondition

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithSingleSubjectAndEnvironmentCondition.

@Test
public void shouldMigratePolicyWithSingleSubjectAndEnvironmentCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    PolicySubject subject = mock(PolicySubject.class);
    PolicyCondition condition = mock(PolicyCondition.class);
    EntitlementSubject migratedSubject = mock(EntitlementSubject.class);
    EntitlementCondition migratedCondition = mock(EntitlementCondition.class);
    given(policy.getSubject()).willReturn(subject);
    given(policy.getCondition()).willReturn(condition);
    given(subject.getClassName()).willReturn("SUBJECT_CLASS_NAME");
    given(condition.getClassName()).willReturn("CONDITION_CLASS_NAME");
    given(conditionUpgradeMap.migrateSubjectCondition(eq("SUBJECT_CLASS_NAME"), eq(subject), Matchers.<MigrationReport>anyObject())).willReturn(migratedSubject);
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION_CLASS_NAME"), eq(condition), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<EntitlementSubject> subjectCaptor = ArgumentCaptor.forClass(EntitlementSubject.class);
    verify(policy).setSubject(subjectCaptor.capture());
    assertThat(subjectCaptor.getValue()).isEqualTo(migratedSubject);
    ArgumentCaptor<EntitlementCondition> conditionCaptor = ArgumentCaptor.forClass(EntitlementCondition.class);
    verify(policy).setCondition(conditionCaptor.capture());
    assertThat(conditionCaptor.getValue()).isEqualTo(migratedCondition);
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 8 with PolicyCondition

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithAndEnvironmentCondition.

@SuppressWarnings("unchecked")
@Test
public void shouldMigratePolicyWithAndEnvironmentCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    AndCondition andCondition = mock(AndCondition.class);
    Set<EntitlementCondition> andConditions = new HashSet<EntitlementCondition>();
    PolicyCondition condition1 = mock(PolicyCondition.class);
    PolicyCondition condition2 = mock(PolicyCondition.class);
    andConditions.add(condition1);
    andConditions.add(condition2);
    EntitlementCondition migratedCondition1 = mock(EntitlementCondition.class);
    EntitlementCondition migratedCondition2 = mock(EntitlementCondition.class);
    given(policy.getCondition()).willReturn(andCondition);
    given(andCondition.getEConditions()).willReturn(andConditions);
    given(condition1.getClassName()).willReturn("CONDITION1_CLASS_NAME");
    given(condition2.getClassName()).willReturn("CONDITION2_CLASS_NAME");
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION1_CLASS_NAME"), eq(condition1), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition1);
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION2_CLASS_NAME"), eq(condition2), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition2);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<Set> conditionCaptor = ArgumentCaptor.forClass(Set.class);
    verify(andCondition).setEConditions(conditionCaptor.capture());
    assertThat(conditionCaptor.getValue()).hasSize(2).contains(migratedCondition1, migratedCondition2);
    verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
    verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) Privilege(com.sun.identity.entitlement.Privilege) AndCondition(com.sun.identity.entitlement.AndCondition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with PolicyCondition

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

the class PolicyConditionUpgraderTest method isPolicyWithNotEnvironmentConditionUpgradable.

@Test(dataProvider = "isPolicyWithNotEnvironmentConditionUpgradableDataProvider")
public void isPolicyWithNotEnvironmentConditionUpgradable(Class<? extends EntitlementCondition> condition, boolean conditionInMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    NotCondition notCondition = mock(NotCondition.class);
    Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
    EntitlementCondition con = mock(condition);
    notConditions.add(con);
    given(policy.getCondition()).willReturn(notCondition);
    given(notCondition.getEConditions()).willReturn(notConditions);
    if (con instanceof PolicyCondition) {
        given(((PolicyCondition) con).getClassName()).willReturn("CONDITION_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION_CLASS_NAME")).willReturn(conditionInMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) NotCondition(com.sun.identity.entitlement.NotCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with PolicyCondition

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

the class JsonPolicyParserTest method shouldPrintComplexConditions.

@Test
public void shouldPrintComplexConditions() throws Exception {
    // Given
    Privilege policy = new StubPrivilege();
    AndCondition and = new AndCondition();
    Set<EntitlementCondition> subConditions = new LinkedHashSet<EntitlementCondition>();
    Map<String, Set<String>> props = new HashMap<String, Set<String>>();
    props.put("AuthenticateToRealm", Collections.singleton("REALM"));
    PolicyCondition policyCondition = new PolicyCondition("test", AuthenticateToRealmCondition.class.getName(), props);
    NotCondition not = new NotCondition(policyCondition);
    subConditions.add(not);
    and.setEConditions(subConditions);
    policy.setCondition(and);
    // When
    JsonValue result = parser.printPolicy(policy);
    // Then
    assertThat(result.get(new JsonPointer("condition/type")).asString()).isEqualTo("AND");
    assertThat(result.get(new JsonPointer("condition/conditions/0/type")).asString()).isEqualTo("NOT");
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/type")).asString()).isEqualTo("Policy");
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/className")).asString()).isEqualTo(AuthenticateToRealmCondition.class.getName());
    assertThat(result.get(new JsonPointer("condition/conditions/0/condition/properties")).asMapOfList(String.class)).includes(entry("AuthenticateToRealm", Arrays.asList("REALM")));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) NotCondition(com.sun.identity.entitlement.NotCondition) HashMap(java.util.HashMap) JsonValue(org.forgerock.json.JsonValue) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) JsonPointer(org.forgerock.json.JsonPointer) AndCondition(com.sun.identity.entitlement.AndCondition) AuthenticateToRealmCondition(com.sun.identity.policy.plugins.AuthenticateToRealmCondition) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Aggregations

PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)11 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)10 Privilege (com.sun.identity.entitlement.Privilege)10 Test (org.testng.annotations.Test)10 HashSet (java.util.HashSet)9 Set (java.util.Set)4 AndCondition (com.sun.identity.entitlement.AndCondition)3 NotCondition (com.sun.identity.entitlement.NotCondition)3 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 OrCondition (com.sun.identity.entitlement.OrCondition)2 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)2 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)2 AuthenticateToRealmCondition (com.sun.identity.policy.plugins.AuthenticateToRealmCondition)2 LinkedHashSet (java.util.LinkedHashSet)2 JsonValue (org.forgerock.json.JsonValue)2 LogicalCondition (com.sun.identity.entitlement.LogicalCondition)1 HashMap (java.util.HashMap)1 JsonPointer (org.forgerock.json.JsonPointer)1 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)1