Search in sources :

Example 1 with OrSubject

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

the class PolicyConditionUpgraderTest method shouldMigratePolicyWithOrSubjectCondition.

@SuppressWarnings("unchecked")
@Test
public void shouldMigratePolicyWithOrSubjectCondition() throws EntitlementException, UpgradeException {
    //Given
    Privilege policy = mock(Privilege.class);
    OrSubject orSubject = mock(OrSubject.class);
    Set<EntitlementSubject> orSubjects = new HashSet<EntitlementSubject>();
    PolicySubject subject1 = mock(PolicySubject.class);
    PolicySubject subject2 = mock(PolicySubject.class);
    orSubjects.add(subject1);
    orSubjects.add(subject2);
    EntitlementSubject migratedSubject1 = mock(EntitlementSubject.class);
    EntitlementSubject migratedSubject2 = mock(EntitlementSubject.class);
    given(policy.getSubject()).willReturn(orSubject);
    given(orSubject.getESubjects()).willReturn(orSubjects);
    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(orSubject).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 : 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) OrSubject(com.sun.identity.entitlement.OrSubject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with OrSubject

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

the class PolicyConditionUpgraderTest method isPolicyWithOrSubjectConditionUpgradable.

@Test(dataProvider = "isPolicyWithOrSubjectConditionUpgradableDataProvider")
public void isPolicyWithOrSubjectConditionUpgradable(Class<? extends EntitlementSubject> sub1, boolean sub1InMap, Class<? extends EntitlementSubject> sub2, boolean sub2InMap, boolean expectedResult) {
    //Given
    Privilege policy = mock(Privilege.class);
    OrSubject orSubject = mock(OrSubject.class);
    Set<EntitlementSubject> orSubjects = new HashSet<EntitlementSubject>();
    EntitlementSubject subject1 = mock(sub1);
    EntitlementSubject subject2 = mock(sub2);
    orSubjects.add(subject1);
    orSubjects.add(subject2);
    given(policy.getSubject()).willReturn(orSubject);
    given(orSubject.getESubjects()).willReturn(orSubjects);
    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 : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) Privilege(com.sun.identity.entitlement.Privilege) OrSubject(com.sun.identity.entitlement.OrSubject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with OrSubject

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

the class PrivilegeUtils method toEntitlementSubject.

private static EntitlementSubject toEntitlementSubject(Policy policy) throws PolicyException {
    Set<String> subjectNames = policy.getSubjectNames();
    Set<EntitlementSubject> entitlementSubjects = new HashSet<EntitlementSubject>();
    if (subjectNames != null) {
        for (String subjectName : subjectNames) {
            Subject subject = policy.getSubject(subjectName);
            boolean exclusive = policy.isSubjectExclusive(subjectName);
            boolean dealtWith = false;
            if (!dealtWith) {
                EntitlementSubject sbj = mapGenericSubject(subjectName, subject, exclusive);
                if (sbj != null) {
                    entitlementSubjects.add(sbj);
                }
            }
        }
    }
    if (entitlementSubjects.isEmpty()) {
        return null;
    }
    return (entitlementSubjects.size() == 1) ? entitlementSubjects.iterator().next() : new OrSubject(entitlementSubjects);
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) Subject(com.sun.identity.policy.interfaces.Subject) OrSubject(com.sun.identity.entitlement.OrSubject) OrSubject(com.sun.identity.entitlement.OrSubject) HashSet(java.util.HashSet)

Example 4 with OrSubject

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

the class OpenSSOApplicationPrivilegeManager method toPrivilege.

/**
     * Creates two privileges here
     */
private Privilege[] toPrivilege(ApplicationPrivilege appPrivilege) throws EntitlementException {
    Privilege[] results = new Privilege[2];
    try {
        Privilege actualP = Privilege.getNewInstance();
        actualP.setName(appPrivilege.getName());
        actualP.setDescription(appPrivilege.getDescription());
        Set<String> res = createDelegationResources(appPrivilege);
        Entitlement entitlement = new Entitlement(APPL_NAME, res, getActionValues(appPrivilege.getActionValues()));
        actualP.setEntitlement(entitlement);
        Privilege ghostP = Privilege.getNewInstance();
        ghostP.setName(GHOST_PRIVILEGE_NAME_PREFIX + appPrivilege.getName());
        Set<String> ghostRes = new HashSet<String>();
        String currentOrgDN = DNMapper.orgNameToDN(realm);
        Object[] param = { currentOrgDN };
        ghostRes.add(MessageFormat.format(SUN_AM_REALM_RESOURCE, param));
        ghostRes.add(MessageFormat.format(SUN_IDREPO_RESOURCE, param));
        entitlement = new Entitlement(APPL_NAME, ghostRes, getActionValues(ApplicationPrivilege.PossibleAction.READ));
        ghostP.setEntitlement(entitlement);
        Set<SubjectImplementation> subjects = appPrivilege.getSubjects();
        Set<EntitlementSubject> eSubjects = new HashSet<EntitlementSubject>();
        for (SubjectImplementation i : subjects) {
            eSubjects.add((EntitlementSubject) i);
        }
        OrSubject orSubject = new OrSubject(eSubjects);
        actualP.setSubject(orSubject);
        actualP.setCondition(appPrivilege.getCondition());
        ghostP.setSubject(orSubject);
        ghostP.setCondition(appPrivilege.getCondition());
        Set<String> applIndexes = new HashSet<String>();
        applIndexes.addAll(appPrivilege.getApplicationNames());
        actualP.setApplicationIndexes(applIndexes);
        results[0] = actualP;
        results[1] = ghostP;
    } catch (UnsupportedEncodingException ex) {
        String[] params = {};
        throw new EntitlementException(324, params);
    }
    return results;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OrSubject(com.sun.identity.entitlement.OrSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) EntitlementException(com.sun.identity.entitlement.EntitlementException) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Example 5 with OrSubject

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

the class OpenSSOApplicationPrivilegeManager method toApplicationPrivilege.

private ApplicationPrivilege toApplicationPrivilege(Privilege p) throws EntitlementException {
    ApplicationPrivilege ap = new ApplicationPrivilege(p.getName());
    ap.setDescription(p.getDescription());
    ap.setCreatedBy(p.getCreatedBy());
    ap.setCreationDate(p.getCreationDate());
    ap.setLastModifiedBy(p.getLastModifiedBy());
    ap.setLastModifiedDate(p.getLastModifiedDate());
    Entitlement ent = p.getEntitlement();
    Set<String> resourceNames = ent.getResourceNames();
    Map<String, Set<String>> mapAppToRes = getApplicationPrivilegeResourceNames(resourceNames);
    ap.setApplicationResources(mapAppToRes);
    ap.setActionValues(getActionValues(ent.getActionValues()));
    Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
    if (p.getSubject() instanceof OrSubject) {
        OrSubject orSubject = (OrSubject) p.getSubject();
        for (EntitlementSubject es : orSubject.getESubjects()) {
            if (es instanceof SubjectImplementation) {
                subjects.add((SubjectImplementation) es);
            }
        }
    } else if (p.getSubject() instanceof SubjectImplementation) {
        subjects.add((SubjectImplementation) p.getSubject());
    }
    ap.setSubject(subjects);
    EntitlementCondition cond = p.getCondition();
    if (cond instanceof SimpleTimeCondition) {
        ap.setCondition(cond);
    }
    return ap;
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) HashSet(java.util.HashSet) Set(java.util.Set) SimpleTimeCondition(org.forgerock.openam.entitlement.conditions.environment.SimpleTimeCondition) OrSubject(com.sun.identity.entitlement.OrSubject) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) ApplicationPrivilege(com.sun.identity.entitlement.ApplicationPrivilege) SubjectImplementation(com.sun.identity.entitlement.SubjectImplementation) Entitlement(com.sun.identity.entitlement.Entitlement) HashSet(java.util.HashSet)

Aggregations

EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)7 OrSubject (com.sun.identity.entitlement.OrSubject)7 HashSet (java.util.HashSet)7 Privilege (com.sun.identity.entitlement.Privilege)5 Entitlement (com.sun.identity.entitlement.Entitlement)4 Test (org.testng.annotations.Test)4 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)3 AndCondition (com.sun.identity.entitlement.AndCondition)2 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)2 IPrivilege (com.sun.identity.entitlement.IPrivilege)2 ResourceAttribute (com.sun.identity.entitlement.ResourceAttribute)2 StaticAttributes (com.sun.identity.entitlement.StaticAttributes)2 SubjectImplementation (com.sun.identity.entitlement.SubjectImplementation)2 UserAttributes (com.sun.identity.entitlement.UserAttributes)2 UserSubject (com.sun.identity.entitlement.UserSubject)2 OpenSSOUserSubject (com.sun.identity.entitlement.opensso.OpenSSOUserSubject)2 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 IPv4Condition (org.forgerock.openam.entitlement.conditions.environment.IPv4Condition)2