Search in sources :

Example 1 with Condition

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

the class PMDefaultTimeConditionEditViewBean method getDefaultValues.

protected Map getDefaultValues() {
    Map values = null;
    try {
        CachedPolicy cachedPolicy = getCachedPolicy();
        Policy policy = cachedPolicy.getPolicy();
        String conditionName = (String) getPageSessionAttribute(ConditionOpViewBeanBase.PG_SESSION_CONDITION_NAME);
        Condition condition = policy.getCondition(conditionName);
        Map map = condition.getProperties();
        for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
            String propName = (String) iter.next();
            Set val = (Set) map.get(propName);
            if (propName.equals(SimpleTimeCondition.START_DATE)) {
                String strDate = (String) val.iterator().next();
                helper.setDate(this, true, strDate, getModel());
            } else if (propName.equals(SimpleTimeCondition.END_DATE)) {
                String strDate = (String) val.iterator().next();
                helper.setDate(this, false, strDate, getModel());
            } else if (propName.equals(SimpleTimeCondition.START_TIME)) {
                String strTime = (String) val.iterator().next();
                helper.setTime(this, true, strTime);
            } else if (propName.equals(SimpleTimeCondition.END_TIME)) {
                String strTime = (String) val.iterator().next();
                helper.setTime(this, false, strTime);
            } else if (propName.equals(SimpleTimeCondition.START_DAY)) {
                String strDay = (String) val.iterator().next();
                helper.setDay(this, true, strDay);
            } else if (propName.equals(SimpleTimeCondition.END_DAY)) {
                String strDay = (String) val.iterator().next();
                helper.setDay(this, false, strDay);
            } else if (propName.equals(SimpleTimeCondition.ENFORCEMENT_TIME_ZONE)) {
                String strTz = (String) val.iterator().next();
                helper.setTimeZone(this, canModify, strTz);
            }
        }
    } catch (NameNotFoundException e) {
        debug.warning("ConditionEditViewBean.getDefaultValues", e);
    } catch (AMConsoleException e) {
        debug.warning("ConditionEditViewBean.getDefaultValues", e);
    }
    //Yes, we are returning null;
    return values;
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) SimpleTimeCondition(com.sun.identity.policy.plugins.SimpleTimeCondition) Condition(com.sun.identity.policy.interfaces.Condition) Set(java.util.Set) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) Iterator(java.util.Iterator) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map)

Example 2 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)

Example 3 with Condition

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

the class PolicyModelImpl method getConditionViewBeanURL.

/**
     * Returns properties view bean URL of a condition.
     *
     * @param realmName Name of realm.
     * @param conditionTypeName Name of Condition Type.
     * @return properties view bean URL of a condition.
     */
public String getConditionViewBeanURL(String realmName, String conditionTypeName) {
    String url = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ConditionTypeManager condTypeMgr = policyMgr.getConditionTypeManager();
            Condition condition = condTypeMgr.getCondition(conditionTypeName);
            url = condTypeMgr.getViewBeanURL(condition);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getConditionViewBeanURL", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getConditionViewBeanURL", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getConditionViewBeanURL", e);
    }
    return url;
}
Also used : Condition(com.sun.identity.policy.interfaces.Condition) PolicyManager(com.sun.identity.policy.PolicyManager) ConditionTypeManager(com.sun.identity.policy.ConditionTypeManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 4 with Condition

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

the class MetaDataTest method createIPCondition.

private Condition createIPCondition(PolicyManager pm) throws PolicyException {
    Map<String, Set<String>> ipConditionEnvMap = new HashMap<String, Set<String>>();
    Set<String> set = new HashSet<String>();
    set.add("whatever.whatever");
    ipConditionEnvMap.put(Condition.DNS_NAME, set);
    ConditionTypeManager mgr = pm.getConditionTypeManager();
    Condition cond = mgr.getCondition("IPCondition");
    cond.setProperties(ipConditionEnvMap);
    return cond;
}
Also used : Condition(com.sun.identity.policy.interfaces.Condition) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 5 with Condition

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

the class PolicyEvaluatorTest method createIPCondition.

private Condition createIPCondition(PolicyManager pm) throws PolicyException {
    ConditionTypeManager mgr = pm.getConditionTypeManager();
    Condition cond = mgr.getCondition("IPCondition");
    Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    Set<String> set = new HashSet<String>();
    set.add("whatever.whatever");
    map.put(Condition.DNS_NAME, set);
    cond.setProperties(map);
    return cond;
}
Also used : Condition(com.sun.identity.policy.interfaces.Condition) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

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