Search in sources :

Example 1 with LogicalCondition

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

the class PolicyConditionUpgrader method migrateEnvironmentConditions.

private void migrateEnvironmentConditions(Privilege privilege, MigrationReport migrationReport) throws UpgradeException, EntitlementException {
    if (privilege.getCondition() == null) {
        return;
    }
    if (privilege.getCondition() instanceof LogicalCondition) {
        LogicalCondition logicalCondition = (LogicalCondition) privilege.getCondition();
        Set<EntitlementCondition> conditions = logicalCondition.getEConditions();
        Set<EntitlementCondition> migratedConditions = new HashSet<EntitlementCondition>();
        for (EntitlementCondition condition : conditions) {
            if (!(condition instanceof PolicyCondition)) {
                //This should never happen due to check in initialise
                throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
            }
            migratedConditions.add(migrateEnvironmentCondition((PolicyCondition) condition, migrationReport));
        }
        logicalCondition.setEConditions(migratedConditions);
    } else if (privilege.getCondition() instanceof PolicyCondition) {
        privilege.setCondition(migrateEnvironmentCondition((PolicyCondition) privilege.getCondition(), migrationReport));
    } else {
        //This should never happen due to check in initialise
        throw new UpgradeException("Cannot upgrade a environment condition that is not of PolicyCondition type!");
    }
}
Also used : UpgradeException(org.forgerock.openam.upgrade.UpgradeException) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) PolicyCondition(com.sun.identity.entitlement.opensso.PolicyCondition) LogicalCondition(com.sun.identity.entitlement.LogicalCondition) HashSet(java.util.HashSet)

Example 2 with LogicalCondition

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

the class PolicyConditionUpgrader method isEnvironmentConditionUpgradable.

private boolean isEnvironmentConditionUpgradable(EntitlementCondition condition) {
    if (condition == null) {
        return true;
    }
    if (condition instanceof LogicalCondition) {
        LogicalCondition logicalCondition = (LogicalCondition) condition;
        boolean upgradable = true;
        for (EntitlementCondition c : logicalCondition.getEConditions()) {
            upgradable &= isUpgradablePolicyCondition(c);
        }
        return upgradable;
    }
    return isUpgradablePolicyCondition(condition);
}
Also used : EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) LogicalCondition(com.sun.identity.entitlement.LogicalCondition)

Aggregations

EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)2 LogicalCondition (com.sun.identity.entitlement.LogicalCondition)2 PolicyCondition (com.sun.identity.entitlement.opensso.PolicyCondition)1 HashSet (java.util.HashSet)1 UpgradeException (org.forgerock.openam.upgrade.UpgradeException)1