Search in sources :

Example 31 with PrivilegeManager

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

Aggregations

PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)31 Privilege (com.sun.identity.entitlement.Privilege)17 EntitlementException (com.sun.identity.entitlement.EntitlementException)13 HashMap (java.util.HashMap)8 Subject (javax.security.auth.Subject)8 SSOToken (com.iplanet.sso.SSOToken)6 Entitlement (com.sun.identity.entitlement.Entitlement)6 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)6 AfterClass (org.testng.annotations.AfterClass)6 IPrivilege (com.sun.identity.entitlement.IPrivilege)5 RestException (com.sun.identity.rest.RestException)5 Produces (javax.ws.rs.Produces)5 AuthenticatedUsers (org.forgerock.openam.entitlement.conditions.subject.AuthenticatedUsers)5 JSONException (org.json.JSONException)5 ApplicationPrivilegeManager (com.sun.identity.entitlement.ApplicationPrivilegeManager)4 HashSet (java.util.HashSet)4 Cookie (javax.ws.rs.core.Cookie)4 BeforeClass (org.testng.annotations.BeforeClass)4 ApplicationPrivilege (com.sun.identity.entitlement.ApplicationPrivilege)3 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)3