Search in sources :

Example 1 with PolicyCondition

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

the class PolicyConditionUpgrader method migrateEnvironmentConditions.

private void migrateEnvironmentConditions(Privilege privilege, MigrationReport migrationReport) throws UpgradeException, EntitlementException {
    if (privilege.getCondition() == null) {
        return;
    }
    if (privilege.getCondition() instanceof LogicalCondition) {
        LogicalCondition logicalCondition = (LogicalCondition) privilege.getCondition();
        Set<EntitlementCondition> conditions = logicalCondition.getEConditions();
        Set<EntitlementCondition> migratedConditions = new HashSet<EntitlementCondition>();
        for (EntitlementCondition condition : conditions) {
            if (!(condition instanceof PolicyCondition)) {
                //This should never happen due to check in initialise
                throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
            }
            migratedConditions.add(migrateEnvironmentCondition((PolicyCondition) condition, migrationReport));
        }
        logicalCondition.setEConditions(migratedConditions);
    } else if (privilege.getCondition() instanceof PolicyCondition) {
        privilege.setCondition(migrateEnvironmentCondition((PolicyCondition) privilege.getCondition(), migrationReport));
    } else {
        //This should never happen due to check in initialise
        throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) LogicalCondition(com.sun.identity.entitlement.LogicalCondition) HashSet(java.util.HashSet)

Example 2 with PolicyCondition

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithNotEnvironmentCondition.

@Test
public void shouldMigratePolicyWithNotEnvironmentCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    NotCondition notCondition = mock(NotCondition.class);
    Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
    PolicyCondition condition = mock(PolicyCondition.class);
    notConditions.add(condition);
    EntitlementCondition migratedCondition = mock(EntitlementCondition.class);
    given(policy.getCondition()).willReturn(notCondition);
    given(notCondition.getEConditions()).willReturn(notConditions);
    given(condition.getClassName()).willReturn("CONDITION_CLASS_NAME");
    given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION_CLASS_NAME"), eq(condition), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<Set> conditionCaptor = ArgumentCaptor.forClass(Set.class);
    verify(notCondition).setEConditions(conditionCaptor.capture());
    assertThat(conditionCaptor.getValue()).hasSize(1).contains(migratedCondition);
    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) 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 3 with PolicyCondition

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

the class PolicyConditionUpgraderTest method isPolicyWithSingleSubjectAndEnvironmentConditionUpgradable.

@Test(dataProvider = "isPolicyWithSingleSubjectAndEnvironmentConditionUpgradableDataProvider")
public void isPolicyWithSingleSubjectAndEnvironmentConditionUpgradable(Class<? extends EntitlementSubject> sub, boolean subInMap, Class<? extends EntitlementCondition> con, boolean conInMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    EntitlementSubject subject = null;
    if (sub != null) {
        subject = mock(sub);
    }
    EntitlementCondition condition = null;
    if (con != null) {
        condition = mock(con);
    }
    given(policy.getSubject()).willReturn(subject);
    given(policy.getCondition()).willReturn(condition);
    if (subject instanceof PolicySubject) {
        given(((PolicySubject) subject).getClassName()).willReturn("SUBJECT_CLASS_NAME");
    }
    if (condition instanceof PolicyCondition) {
        given(((PolicyCondition) condition).getClassName()).willReturn("CONDITION_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsSubjectCondition("SUBJECT_CLASS_NAME")).willReturn(subInMap);
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION_CLASS_NAME")).willReturn(conInMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
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 4 with PolicyCondition

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

the class PolicyConditionUpgraderTest method isPolicyWithAndEnvironmentConditionUpgradable.

@Test(dataProvider = "isPolicyWithAndEnvironmentConditionUpgradableDataProvider")
public void isPolicyWithAndEnvironmentConditionUpgradable(Class<? extends EntitlementCondition> con1, boolean con1InMap, Class<? extends EntitlementCondition> con2, boolean con2InMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    AndCondition andCondition = mock(AndCondition.class);
    Set<EntitlementCondition> andConditions = new HashSet<EntitlementCondition>();
    EntitlementCondition condition1 = mock(con1);
    EntitlementCondition condition2 = mock(con2);
    andConditions.add(condition1);
    andConditions.add(condition2);
    given(policy.getCondition()).willReturn(andCondition);
    given(andCondition.getEConditions()).willReturn(andConditions);
    if (condition1 instanceof PolicyCondition) {
        given(((PolicyCondition) condition1).getClassName()).willReturn("CONDITION1_CLASS_NAME");
    }
    if (condition2 instanceof PolicyCondition) {
        given(((PolicyCondition) condition2).getClassName()).willReturn("CONDITION2_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION1_CLASS_NAME")).willReturn(con1InMap);
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION2_CLASS_NAME")).willReturn(con2InMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) 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 5 with PolicyCondition

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

the class PolicyConditionUpgraderTest method isPolicyWithOrEnvironmentConditionUpgradable.

@Test(dataProvider = "isPolicyWithOrEnvironmentConditionUpgradableDataProvider")
public void isPolicyWithOrEnvironmentConditionUpgradable(Class<? extends EntitlementCondition> con1, boolean con1InMap, Class<? extends EntitlementCondition> con2, boolean con2InMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    OrCondition orCondition = mock(OrCondition.class);
    Set<EntitlementCondition> orConditions = new HashSet<EntitlementCondition>();
    EntitlementCondition condition1 = mock(con1);
    EntitlementCondition condition2 = mock(con2);
    orConditions.add(condition1);
    orConditions.add(condition2);
    given(policy.getCondition()).willReturn(orCondition);
    given(orCondition.getEConditions()).willReturn(orConditions);
    if (condition1 instanceof PolicyCondition) {
        given(((PolicyCondition) condition1).getClassName()).willReturn("CONDITION1_CLASS_NAME");
    }
    if (condition2 instanceof PolicyCondition) {
        given(((PolicyCondition) condition2).getClassName()).willReturn("CONDITION2_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION1_CLASS_NAME")).willReturn(con1InMap);
    given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION2_CLASS_NAME")).willReturn(con2InMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) 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)

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