Search in sources :

Example 6 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition 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 7 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition 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 8 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition 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)

Example 9 with EntitlementCondition

use of com.sun.identity.entitlement.EntitlementCondition 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 10 with EntitlementCondition

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

the class EntitlementRegistryTest method shouldReturnCorrectConditionName.

@Test
public void shouldReturnCorrectConditionName() {
    // Given
    String name = "test";
    EntitlementCondition testCondition = new NumericAttributeCondition();
    testRegistry.registerConditionType(EntitlementCondition.class);
    testRegistry.registerConditionType(name, NumericAttributeCondition.class);
    // When
    String result = testRegistry.getConditionName(testCondition);
    // Then
    assertThat(result).isEqualTo(name);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) NumericAttributeCondition(com.sun.identity.entitlement.NumericAttributeCondition) Test(org.testng.annotations.Test)

Aggregations

EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)28 HashSet (java.util.HashSet)17 Test (org.testng.annotations.Test)14 Privilege (com.sun.identity.entitlement.Privilege)13 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)10 AndCondition (com.sun.identity.entitlement.AndCondition)9 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)9 OrCondition (com.sun.identity.entitlement.OrCondition)8 Entitlement (com.sun.identity.entitlement.Entitlement)7 HashMap (java.util.HashMap)6 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)5 OrSubject (com.sun.identity.entitlement.OrSubject)4 NotCondition (com.sun.identity.entitlement.NotCondition)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3 Condition (com.sun.identity.policy.interfaces.Condition)3 PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)3 IPrivilege (com.sun.identity.entitlement.IPrivilege)2 LogicalCondition (com.sun.identity.entitlement.LogicalCondition)2 NumericAttributeCondition (com.sun.identity.entitlement.NumericAttributeCondition)2