Search in sources :

Example 6 with Condition

use of com.sun.identity.policy.interfaces.Condition in project OpenAM by OpenRock.

the class PrivilegePolicyMapping method createIPCondition.

private Condition createIPCondition(PolicyManager pm) throws PolicyException {
    ConditionTypeManager mgr = pm.getConditionTypeManager();
    Condition cond = mgr.getCondition("IPCondition");
    cond.setProperties(ipConditionEnvMap);
    return cond;
}
Also used : OrCondition(com.sun.identity.entitlement.OrCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) ConditionTypeManager(com.sun.identity.policy.ConditionTypeManager)

Example 7 with Condition

use of com.sun.identity.policy.interfaces.Condition in project OpenAM by OpenRock.

the class PrivilegePolicyMapping method createIPCondition1.

private Condition createIPCondition1(PolicyManager pm) throws PolicyException {
    ConditionTypeManager mgr = pm.getConditionTypeManager();
    Condition cond = mgr.getCondition("IPCondition");
    cond.setProperties(ipConditionEnvMap1);
    return cond;
}
Also used : OrCondition(com.sun.identity.entitlement.OrCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) ConditionTypeManager(com.sun.identity.policy.ConditionTypeManager)

Example 8 with Condition

use of com.sun.identity.policy.interfaces.Condition in project OpenAM by OpenRock.

the class UpgradeUtils method removeDelegationPolicyAttribute.

/**
      * Removes attribute from a condition.
      *
      * @param policyName Name of Policy.
      * @param attributeName the name of the attribute to be removed.
      * @param conditionName name of the condition
      */
public static void removeDelegationPolicyAttribute(String policyName, String attributeName, String conditionName) {
    String classMethod = "UpgradeUtils:removeDelegationPolicyAttribute";
    try {
        PolicyManager pm = new PolicyManager(ssoToken, HIDDEN_REALM);
        Policy policy = pm.getPolicy(policyName);
        Condition cond = policy.getCondition(conditionName);
        HashMap newMap = new HashMap();
        if (cond != null) {
            Map orig = cond.getProperties();
            Iterator i = (orig.keySet()).iterator();
            while (i.hasNext()) {
                String key = (String) i.next();
                if (!key.equals(attributeName)) {
                    HashSet values = (HashSet) orig.get(key);
                    newMap.put(key, values);
                }
            }
            if (debug.messageEnabled()) {
                debug.message(classMethod + "attributes :" + newMap);
            }
            cond.setProperties(newMap);
            policy.replaceCondition(conditionName, cond);
        }
        pm.replacePolicy(policy);
    } catch (PolicyException e) {
        debug.error(classMethod, e);
    } catch (SSOException e) {
        debug.error(classMethod, e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) Condition(com.sun.identity.policy.interfaces.Condition) PolicyManager(com.sun.identity.policy.PolicyManager) HashMap(java.util.HashMap) PolicyException(com.sun.identity.policy.PolicyException) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SSOException(com.iplanet.sso.SSOException) ByteString(org.forgerock.opendj.ldap.ByteString) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 9 with Condition

use of com.sun.identity.policy.interfaces.Condition in project OpenAM by OpenRock.

the class PrivilegeUtils method privilegeToPolicy.

public static Policy privilegeToPolicy(String realm, Privilege privilege) throws PolicyException, SSOException, EntitlementException {
    Policy policy = new Policy(privilege.getName());
    policy.setDescription(privilege.getDescription());
    if (privilege.getEntitlement() != null) {
        Entitlement entitlement = privilege.getEntitlement();
        Set<Rule> rules = entitlementToRule(realm, entitlement);
        for (Rule rule : rules) {
            policy.addRule(rule);
        }
    }
    EntitlementSubject es = privilege.getSubject();
    if ((es != null) && (es != Privilege.NOT_SUBJECT)) {
        Subject sbj = eSubjectToEPSubject(es);
        policy.addSubject(getSubjectName(es), sbj, false);
    }
    EntitlementCondition ec = privilege.getCondition();
    if (ec != null) {
        Condition cond = eConditionToEPCondition(ec);
        policy.addCondition(getConditionName(ec), cond);
    }
    if (privilege.getResourceAttributes() != null) {
        Map<String, ResponseProvider> nrps = resourceAttributesToResponseProviders(privilege.getResourceAttributes());
        for (String rpName : nrps.keySet()) {
            ResponseProvider responseProvider = nrps.get(rpName);
            policy.addResponseProvider(rpName, responseProvider);
        }
    }
    policy.setCreatedBy(privilege.getCreatedBy());
    policy.setCreationDate(privilege.getCreationDate());
    policy.setLastModifiedBy(privilege.getLastModifiedBy());
    policy.setLastModifiedDate(privilege.getLastModifiedDate());
    return policy;
}
Also used : Policy(com.sun.identity.policy.Policy) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) OrCondition(com.sun.identity.entitlement.OrCondition) AndCondition(com.sun.identity.entitlement.AndCondition) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Condition(com.sun.identity.policy.interfaces.Condition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) EntitlementCondition(com.sun.identity.entitlement.EntitlementCondition) IDRepoResponseProvider(com.sun.identity.policy.plugins.IDRepoResponseProvider) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) Rule(com.sun.identity.policy.Rule) Entitlement(com.sun.identity.entitlement.Entitlement) 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)

Example 10 with Condition

use of com.sun.identity.policy.interfaces.Condition in project OpenAM by OpenRock.

the class ConditionEditViewBean method handleButton1Request.

private void handleButton1Request(CachedPolicy cachedPolicy) throws ModelControlException {
    submitCycle = true;
    boolean forwarded = false;
    Condition deleted = null;
    String origName = (String) getPageSessionAttribute(EDIT_CONDITION_NAME);
    Policy policy = cachedPolicy.getPolicy();
    try {
        Condition condition = createCondition();
        if (condition != null) {
            String name = (String) propertySheetModel.getValue(CONDITION_NAME);
            if (origName.equals(name)) {
                policy.replaceCondition(name, condition);
            } else {
                deleted = policy.removeCondition(origName);
                policy.addCondition(name, condition);
            }
            deleted = null;
            setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information", "policy.condition.updated");
            cachedPolicy.setPolicyModified(true);
        }
    } catch (NameAlreadyExistsException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (InvalidNameException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (NameNotFoundException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
    } catch (AMConsoleException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", e.getMessage());
    } finally {
        if (deleted != null) {
            try {
                policy.addCondition(origName, deleted);
            } catch (NameAlreadyExistsException e) {
                debug.warning("ConditionEditViewBean.handleButton1Request", e);
            } catch (InvalidNameException e) {
                debug.warning("ConditionEditViewBean.handleButton1Request", e);
            }
        }
    }
    forwardTo();
}
Also used : Condition(com.sun.identity.policy.interfaces.Condition) Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) InvalidNameException(com.sun.identity.policy.InvalidNameException) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) NameAlreadyExistsException(com.sun.identity.policy.NameAlreadyExistsException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

Condition (com.sun.identity.policy.interfaces.Condition)27 Policy (com.sun.identity.policy.Policy)10 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)8 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)8 PolicyException (com.sun.identity.policy.PolicyException)8 HashMap (java.util.HashMap)8 Set (java.util.Set)8 HashSet (java.util.HashSet)7 Map (java.util.Map)7 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)6 EntitlementCondition (com.sun.identity.entitlement.EntitlementCondition)6 OrCondition (com.sun.identity.entitlement.OrCondition)6 PrivilegeCondition (com.sun.identity.policy.plugins.PrivilegeCondition)6 ConditionTypeManager (com.sun.identity.policy.ConditionTypeManager)5 PolicyManager (com.sun.identity.policy.PolicyManager)5 SSOException (com.iplanet.sso.SSOException)4 Iterator (java.util.Iterator)4 AndCondition (com.sun.identity.entitlement.AndCondition)3 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)2 EntitlementException (com.sun.identity.entitlement.EntitlementException)2