Search in sources :

Example 56 with Privilege

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

the class OldPolicyConditionMigrationUpgradeStep method perform.

/**
     * Does the persisting of the upgraded policies.
     *
     * @throws UpgradeException If there is a problem saving the policies.
     */
@Override
public void perform() throws UpgradeException {
    for (Map.Entry<String, Set<Privilege>> entry : privilegesToUpgrade.entrySet()) {
        String realm = entry.getKey();
        //ensure reading apps cleanly
        ApplicationManager.clearCache(realm);
        PrivilegeManager privilegeManager = getPrivilegeManager(realm);
        for (Privilege privilege : entry.getValue()) {
            privilege.getEntitlement().clearCache();
            try {
                addResourceType(privilege, realm);
                privilegeManager.modify(privilege.getName(), privilege);
            } catch (EntitlementException e) {
                DEBUG.error("Failed to modify privilege!", e);
                throw new UpgradeException("Failed to modify privilege!", e);
            }
        }
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) Set(java.util.Set) HashSet(java.util.HashSet) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) HashMap(java.util.HashMap) Map(java.util.Map)

Example 57 with Privilege

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

the class OldPolicyConditionMigrationUpgradeStep method initialize.

/**
     * Checks what policies could be automatically upgraded and performs the upgrade without saving so that the
     * migrated policy can be validated to ensure the upgrade went well.
     *
     * @throws UpgradeException If a problem occurred checking the policies.
     */
@Override
public void initialize() throws UpgradeException {
    if (!isCurrentVersionLessThan(1200, true)) {
        return;
    }
    try {
        DEBUG.message("Initializing OldPolicyConditionMigrationStep");
        for (String realm : getRealmNames()) {
            if (!realm.startsWith("/")) {
                realm = "/" + realm;
            }
            PrivilegeManager privilegeManager = getPrivilegeManager(realm);
            List<Privilege> privileges;
            try {
                privileges = privilegeManager.findAllPolicies();
            } catch (EntitlementException e) {
                continue;
            }
            for (Privilege privilege : privileges) {
                if (conditionUpgrader.isPolicyUpgradable(privilege)) {
                    try {
                        MigrationReport report = conditionUpgrader.dryRunPolicyUpgrade(privilege);
                        addReport(realm, report);
                        addUpgradablePolicy(realm, privilege);
                    } catch (Exception e) {
                        addUnupgradablePolicy(realm, privilege);
                    }
                }
            }
        }
    } catch (UpgradeException e) {
        DEBUG.error("Error while trying to detect changes in entitlements", e);
        throw e;
    } catch (Exception ex) {
        DEBUG.error("Error while trying to detect changes in entitlements", ex);
        throw new UpgradeException(ex);
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Privilege(com.sun.identity.entitlement.Privilege) UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementException(com.sun.identity.entitlement.EntitlementException)

Example 58 with Privilege

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

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

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

Aggregations

Privilege (com.sun.identity.entitlement.Privilege)122 Test (org.testng.annotations.Test)76 JsonValue (org.forgerock.json.JsonValue)46 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)39 HashSet (java.util.HashSet)30 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)26 EntitlementException (com.sun.identity.entitlement.EntitlementException)23 IPrivilege (com.sun.identity.entitlement.IPrivilege)23 Entitlement (com.sun.identity.entitlement.Entitlement)19 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)18 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)17 HashMap (java.util.HashMap)15 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)13 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)11 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)10 Set (java.util.Set)9 SSOToken (com.iplanet.sso.SSOToken)8 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)8 Subject (javax.security.auth.Subject)8 ResourceResponse (org.forgerock.json.resource.ResourceResponse)8