Search in sources :

Example 21 with Policy

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

the class SelectServiceTypeViewBean method getTypeOptions.

protected OptionList getTypeOptions() {
    PolicyModel model = (PolicyModel) getModel();
    String curRealm = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
    try {
        Policy policy = getCachedPolicy().getPolicy();
        Map map = model.getServiceTypeNames();
        Map options = new HashMap();
        for (Iterator iter = map.keySet().iterator(); iter.hasNext(); ) {
            String name = (String) iter.next();
            String label = (String) map.get(name);
            if (model.requiredResourceName(policy, curRealm, name)) {
                String[] param = { label };
                String lbl = MessageFormat.format(model.getLocalizedString("policy.rules.withResourceName"), (Object[]) param);
                options.put(name + "|" + WITH_RESOURCE_SUFFIX, lbl);
            }
            if (model.notRequiredResourceName(policy, curRealm, name)) {
                String[] param = { label };
                String lbl = MessageFormat.format(model.getLocalizedString("policy.rules.withoutResourceName"), (Object[]) param);
                options.put(name + "|" + WITHOUT_RESOURCE_SUFFIX, lbl);
            }
        }
        return AMFormatUtils.getSortedOptionList(options, model.getUserLocale());
    } catch (AMConsoleException e) {
        debug.message("SelectServiceTypeViewBean.getTypeOptions " + "creating empty option list");
        return new OptionList();
    }
}
Also used : Policy(com.sun.identity.policy.Policy) HashMap(java.util.HashMap) Iterator(java.util.Iterator) PolicyModel(com.sun.identity.console.policy.model.PolicyModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) OptionList(com.iplanet.jato.view.html.OptionList)

Example 22 with Policy

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

the class PolicyOpViewBeanBase method handleTblSubjectsButtonDeleteRequest.

/**
     * Handles delete subject request.
     *
     * @param event Request Invocation Event.
     */
public void handleTblSubjectsButtonDeleteRequest(RequestInvocationEvent event) throws ModelControlException {
    CCActionTable table = (CCActionTable) getChild(TBL_SUBJECTS);
    table.restoreStateData();
    try {
        CachedPolicy cachedPolicy = getCachedPolicy();
        Policy policy = cachedPolicy.getPolicy();
        Integer[] selected = tblSubjectsModel.getSelectedRows();
        for (int i = 0; i < selected.length; i++) {
            tblSubjectsModel.setRowIndex(selected[i].intValue());
            String subjectName = (String) tblSubjectsModel.getValue(TBL_SUBJECTS_DATA_NAME);
            policy.removeSubject(subjectName);
        }
        cachedPolicy.setPolicyModified(true);
        populateSubjectsTable();
        forwardTo();
    } catch (AMConsoleException e) {
        debug.warning("PolicyOpViewBeanBase.handleTblSubjectsButtonDeleteRequest", e);
        redirectToStartURL();
    }
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) CCActionTable(com.sun.web.ui.view.table.CCActionTable) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 23 with Policy

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

the class PolicyOpViewBeanBase method reconstructPolicyGeneral.

private boolean reconstructPolicyGeneral(PolicyModel model) throws AMConsoleException {
    boolean bError = false;
    String policyName = (String) propertySheetModel.getValue(PolicyModel.TF_NAME);
    policyName = policyName.trim();
    String description = (String) propertySheetModel.getValue(ATTR_DESCRIPTION);
    description = description.trim();
    String isActive = (String) propertySheetModel.getValue(ATTR_ISACTIVE);
    boolean active = (isActive != null) && isActive.equals("true");
    if (policyName.length() == 0) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", "policy.missing.policyName");
        bError = true;
        return bError;
    }
    CachedPolicy cachedPolicy = getCachedPolicy();
    Policy policy = cachedPolicy.getPolicy();
    try {
        policy.setDescription(description);
        policy.setActive(active);
        policy.setName(policyName);
    } catch (InvalidNameException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", model.getErrorString(e));
        bError = true;
    }
    return bError;
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) InvalidNameException(com.sun.identity.policy.InvalidNameException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy)

Example 24 with Policy

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

the class PolicyOpViewBeanBase method populateSubjectsTable.

protected void populateSubjectsTable() throws AMConsoleException {
    tblSubjectsModel.clearAll();
    CachedPolicy cachedPolicy = getCachedPolicy();
    Policy policy = cachedPolicy.getPolicy();
    Set subjectsNames = policy.getSubjectNames();
    if ((subjectsNames != null) && !subjectsNames.isEmpty()) {
        PolicyModel model = (PolicyModel) getModel();
        String realmName = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
        QueryResults queryResults = model.getActiveSubjectTypes(realmName);
        Map localizedSbjTypeNames = (Map) queryResults.getResults();
        boolean firstEntry = true;
        for (Iterator iter = subjectsNames.iterator(); iter.hasNext(); ) {
            if (firstEntry) {
                firstEntry = false;
            } else {
                tblSubjectsModel.appendRow();
            }
            try {
                String name = (String) iter.next();
                Subject subject = policy.getSubject(name);
                tblSubjectsModel.setValue(TBL_SUBJECTS_DATA_NAME, name);
                String sbjTypeName = model.getSubjectTypeName(realmName, subject);
                String displayName = (String) localizedSbjTypeNames.get(sbjTypeName);
                if (displayName == null) {
                    displayName = sbjTypeName;
                }
                tblSubjectsModel.setValue(TBL_SUBJECTS_DATA_TYPE, displayName);
                tblSubjectsModel.setValue(TBL_SUBJECTS_ACTION_HREF, stringToHex(name));
            } catch (NameNotFoundException e) {
                debug.warning("PolicyOpViewBeanBase.populateSubjectsTable", e);
            }
        }
    }
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) Set(java.util.Set) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) Iterator(java.util.Iterator) PolicyModel(com.sun.identity.console.policy.model.PolicyModel) HashMap(java.util.HashMap) Map(java.util.Map) QueryResults(com.sun.identity.console.base.model.QueryResults) Subject(com.sun.identity.policy.interfaces.Subject)

Example 25 with Policy

use of com.sun.identity.policy.Policy 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)

Aggregations

Policy (com.sun.identity.policy.Policy)68 CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)37 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)32 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)24 Set (java.util.Set)22 PolicyException (com.sun.identity.policy.PolicyException)17 PolicyManager (com.sun.identity.policy.PolicyManager)16 HashSet (java.util.HashSet)16 Map (java.util.Map)16 SSOException (com.iplanet.sso.SSOException)15 Rule (com.sun.identity.policy.Rule)15 Subject (com.sun.identity.policy.interfaces.Subject)14 HashMap (java.util.HashMap)14 Iterator (java.util.Iterator)13 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)12 InvalidNameException (com.sun.identity.policy.InvalidNameException)11 NameAlreadyExistsException (com.sun.identity.policy.NameAlreadyExistsException)10 Condition (com.sun.identity.policy.interfaces.Condition)10 SMSException (com.sun.identity.sm.SMSException)7 Referral (com.sun.identity.policy.interfaces.Referral)6