Search in sources :

Example 11 with CachedPolicy

use of com.sun.identity.console.policy.model.CachedPolicy in project OpenAM by OpenRock.

the class SubjectOpViewBeanBase method getCachedPolicy.

protected CachedPolicy getCachedPolicy() throws AMConsoleException {
    CachedPolicy policy = null;
    String cacheID = (String) getPageSessionAttribute(ProfileViewBeanBase.PG_SESSION_POLICY_CACHE_ID);
    if (cacheID != null) {
        PolicyCache cache = PolicyCache.getInstance();
        PolicyModel model = (PolicyModel) getModel();
        policy = model.getCachedPolicy(cacheID);
    }
    return policy;
}
Also used : CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) PolicyModel(com.sun.identity.console.policy.model.PolicyModel) PolicyCache(com.sun.identity.console.policy.model.PolicyCache)

Example 12 with CachedPolicy

use of com.sun.identity.console.policy.model.CachedPolicy in project OpenAM by OpenRock.

the class SubjectEditViewBean method handleButton1Request.

private void handleButton1Request(CachedPolicy cachedPolicy) throws ModelControlException {
    submitCycle = true;
    Subject deleted = null;
    String origName = (String) getPageSessionAttribute(EDIT_SUBJECT_NAME);
    Policy policy = cachedPolicy.getPolicy();
    try {
        Subject subject = createSubject();
        if (subject != null) {
            String name = (String) propertySheetModel.getValue(SUBJECT_NAME);
            if (origName.equals(name)) {
                policy.replaceSubject(name, subject, isExclusive());
            } else {
                deleted = policy.removeSubject(origName);
                policy.addSubject(name, subject, isExclusive());
            }
            deleted = null;
            setInlineAlertMessage(CCAlert.TYPE_INFO, "message.information", "policy.subject.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.addSubject(origName, deleted);
            } catch (NameAlreadyExistsException e) {
                debug.warning("SubjectEditViewBean.handleButton1Request", e);
            } catch (InvalidNameException e) {
                debug.warning("SubjectEditViewBean.handleButton1Request", e);
            }
        }
    }
    forwardTo();
}
Also used : 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) Subject(com.sun.identity.policy.interfaces.Subject)

Example 13 with CachedPolicy

use of com.sun.identity.console.policy.model.CachedPolicy 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 14 with CachedPolicy

use of com.sun.identity.console.policy.model.CachedPolicy 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 15 with CachedPolicy

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

Aggregations

CachedPolicy (com.sun.identity.console.policy.model.CachedPolicy)53 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)38 Policy (com.sun.identity.policy.Policy)37 PolicyModel (com.sun.identity.console.policy.model.PolicyModel)26 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)21 NameAlreadyExistsException (com.sun.identity.policy.NameAlreadyExistsException)10 InvalidNameException (com.sun.identity.policy.InvalidNameException)9 Map (java.util.Map)9 Set (java.util.Set)9 PolicyCache (com.sun.identity.console.policy.model.PolicyCache)6 Condition (com.sun.identity.policy.interfaces.Condition)6 Subject (com.sun.identity.policy.interfaces.Subject)6 HashMap (java.util.HashMap)6 Iterator (java.util.Iterator)6 Referral (com.sun.identity.policy.interfaces.Referral)5 ResponseProvider (com.sun.identity.policy.interfaces.ResponseProvider)5 CCActionTable (com.sun.web.ui.view.table.CCActionTable)5 Rule (com.sun.identity.policy.Rule)4 QueryResults (com.sun.identity.console.base.model.QueryResults)1 SimpleTimeCondition (com.sun.identity.policy.plugins.SimpleTimeCondition)1