Search in sources :

Example 1 with AndSubject

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

the class PolicyConditionUpgraderTest method isPolicyWithAndSubjectConditionUpgradable.

@Test(dataProvider = "isPolicyWithAndSubjectConditionUpgradableDataProvider")
public void isPolicyWithAndSubjectConditionUpgradable(Class<? extends EntitlementSubject> sub1, boolean sub1InMap, Class<? extends EntitlementSubject> sub2, boolean sub2InMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    AndSubject andSubject = mock(AndSubject.class);
    Set<EntitlementSubject> andSubjects = new HashSet<EntitlementSubject>();
    EntitlementSubject subject1 = mock(sub1);
    EntitlementSubject subject2 = mock(sub2);
    andSubjects.add(subject1);
    andSubjects.add(subject2);
    given(policy.getSubject()).willReturn(andSubject);
    given(andSubject.getESubjects()).willReturn(andSubjects);
    if (subject1 instanceof PolicySubject) {
        given(((PolicySubject) subject1).getClassName()).willReturn("SUBJECT1_CLASS_NAME");
    }
    if (subject2 instanceof PolicySubject) {
        given(((PolicySubject) subject2).getClassName()).willReturn("SUBJECT2_CLASS_NAME");
    }
    given(conditionUpgradeMap.containsSubjectCondition("SUBJECT1_CLASS_NAME")).willReturn(sub1InMap);
    given(conditionUpgradeMap.containsSubjectCondition("SUBJECT2_CLASS_NAME")).willReturn(sub2InMap);
    //When
    boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
    //Then
    assertThat(upgradable).isEqualTo(expectedResult);
}
Also used : AndSubject(com.sun.identity.entitlement.AndSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with AndSubject

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

the class JsonPolicyParserTest method shouldParseComplexSubjects.

@Test
public void shouldParseComplexSubjects() throws Exception {
    // Given
    JsonValue content = buildJson(field("subject", object(field("type", "AND"), field("subjects", Arrays.asList(object(field("type", "AuthenticatedUsers")))))));
    // When
    Privilege result = parser.parsePolicy(POLICY_NAME, content);
    // Then
    assertThat(result.getSubject()).isInstanceOf(AndSubject.class);
    AndSubject and = (AndSubject) result.getSubject();
    assertThat(and.getESubjects()).hasSize(1);
    assertThat(and.getESubjects().iterator().next()).isInstanceOf(AuthenticatedUsers.class);
}
Also used : AndSubject(com.sun.identity.entitlement.AndSubject) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Test(org.testng.annotations.Test)

Example 3 with AndSubject

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithAndSubjectCondition.

@SuppressWarnings("unchecked")
@Test
public void shouldMigratePolicyWithAndSubjectCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    AndSubject andSubject = mock(AndSubject.class);
    Set<EntitlementSubject> andSubjects = new HashSet<EntitlementSubject>();
    PolicySubject subject1 = mock(PolicySubject.class);
    PolicySubject subject2 = mock(PolicySubject.class);
    andSubjects.add(subject1);
    andSubjects.add(subject2);
    EntitlementSubject migratedSubject1 = mock(EntitlementSubject.class);
    EntitlementSubject migratedSubject2 = mock(EntitlementSubject.class);
    given(policy.getSubject()).willReturn(andSubject);
    given(andSubject.getESubjects()).willReturn(andSubjects);
    given(subject1.getClassName()).willReturn("SUBJECT1_CLASS_NAME");
    given(subject2.getClassName()).willReturn("SUBJECT2_CLASS_NAME");
    given(conditionUpgradeMap.migrateSubjectCondition(eq("SUBJECT1_CLASS_NAME"), eq(subject1), Matchers.<MigrationReport>anyObject())).willReturn(migratedSubject1);
    given(conditionUpgradeMap.migrateSubjectCondition(eq("SUBJECT2_CLASS_NAME"), eq(subject2), Matchers.<MigrationReport>anyObject())).willReturn(migratedSubject2);
    //When
    conditionUpgrader.dryRunPolicyUpgrade(policy);
    //Then
    ArgumentCaptor<Set> subjectCaptor = ArgumentCaptor.forClass(Set.class);
    verify(andSubject).setESubjects(subjectCaptor.capture());
    assertThat(subjectCaptor.getValue()).hasSize(2).contains(migratedSubject1, migratedSubject2);
    verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
    verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Also used : AndSubject(com.sun.identity.entitlement.AndSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) HashSet(java.util.HashSet) Set(java.util.Set) Privilege(com.sun.identity.entitlement.Privilege) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

AndSubject (com.sun.identity.entitlement.AndSubject)3 Privilege (com.sun.identity.entitlement.Privilege)3 Test (org.testng.annotations.Test)3 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)2 HashSet (java.util.HashSet)2 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)1 Set (java.util.Set)1 JsonValue (org.forgerock.json.JsonValue)1