Search in sources :

Example 21 with Rule

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

the class UpgradeUtils method getRule.

/**
     * Returns the policy <code>Rule</code> object.
     *
     * @param serviceName name of the service.
     * @param resourceName name of the resource
     * @return <code>Rule</code> object.
     */
private static Rule getRule(String serviceName, String resourceName) {
    String classMethod = "UpgradeUtils:getRule : ";
    Rule rule = null;
    try {
        Map actionsMap = new HashMap();
        Set values = new HashSet();
        values.add("allow");
        actionsMap.put("MODIFY", values);
        actionsMap.put("DELEGATE", values);
        actionsMap.put("READ", values);
        rule = new Rule(serviceName, resourceName, actionsMap);
    } catch (Exception e) {
        debug.error(classMethod + "Error creating rule ", e);
    }
    return rule;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ByteString(org.forgerock.opendj.ldap.ByteString) Rule(com.sun.identity.policy.Rule) Map(java.util.Map) HashMap(java.util.HashMap) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) UnknownPropertyNameException(com.sun.identity.common.configuration.UnknownPropertyNameException) PolicyException(com.sun.identity.policy.PolicyException) FileNotFoundException(java.io.FileNotFoundException) SSOException(com.iplanet.sso.SSOException) LdapException(org.forgerock.opendj.ldap.LdapException) SMSException(com.sun.identity.sm.SMSException) IOException(java.io.IOException) AMException(com.iplanet.am.sdk.AMException) ConfigurationException(com.sun.identity.common.configuration.ConfigurationException) HashSet(java.util.HashSet)

Example 22 with Rule

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

the class PrivilegePolicyMapping method privilegeToPolicy.

@Test(dependsOnMethods = { "policyToPrivilege" })
public void privilegeToPolicy() throws Exception {
    Policy p = PrivilegeUtils.privilegeToPolicy("/", privilege);
    Set<String> ruleNames = p.getRuleNames();
    for (String ruleName : ruleNames) {
        Rule r = p.getRule(ruleName);
        if (!RES_NAME.equals(r.getResourceName())) {
            throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: resource is incorrect");
        }
        if (!actionValues.equals(r.getActionValues())) {
            throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: action value is incorrect");
        }
    }
    Set<String> subjectNames = p.getSubjectNames();
    for (String subjectName : subjectNames) {
        Subject sbj = p.getSubject(subjectName);
        if (!(sbj instanceof PrivilegeSubject)) {
            throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: not instance of privilege subject");
        }
    }
    Set<String> conditionNames = p.getConditionNames();
    if (conditionNames.size() != 1) {
        throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: number of condition is incorrect");
    }
    for (String conditionName : conditionNames) {
        Condition cond = p.getCondition(conditionName);
        if (!(cond instanceof PrivilegeCondition)) {
            throw new Exception("PrivilegePolicyMapping.privilegeToPolicy: not instance of privilege condition");
        }
    }
}
Also used : Policy(com.sun.identity.policy.Policy) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) 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) PrivilegeCondition(com.sun.identity.policy.plugins.PrivilegeCondition) Rule(com.sun.identity.policy.Rule) PolicyException(com.sun.identity.policy.PolicyException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PrivilegeSubject(com.sun.identity.policy.plugins.PrivilegeSubject) Subject(com.sun.identity.policy.interfaces.Subject) Test(org.testng.annotations.Test)

Example 23 with Rule

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

the class PolicyOpViewBeanBase method populateRulesTable.

protected void populateRulesTable() throws AMConsoleException {
    tblRulesModel.clearAll();
    CachedPolicy cachedPolicy = getCachedPolicy();
    Policy policy = cachedPolicy.getPolicy();
    Set ruleNames = policy.getRuleNames();
    if ((ruleNames != null) && !ruleNames.isEmpty()) {
        PolicyModel model = (PolicyModel) getModel();
        Map localizedSvcTypeNames = model.getServiceTypeNames();
        boolean firstEntry = true;
        for (Iterator iter = ruleNames.iterator(); iter.hasNext(); ) {
            if (firstEntry) {
                firstEntry = false;
            } else {
                tblRulesModel.appendRow();
            }
            try {
                String name = (String) iter.next();
                Rule rule = policy.getRule(name);
                tblRulesModel.setValue(TBL_RULES_DATA_NAME, name);
                tblRulesModel.setValue(TBL_RULES_DATA_TYPE, localizedSvcTypeNames.get(rule.getServiceTypeName()));
                tblRulesModel.setValue(TBL_RULES_ACTION_HREF, stringToHex(name));
            } catch (NameNotFoundException e) {
                debug.warning("PolicyOpViewBeanBase.populateRulesTable", 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) Rule(com.sun.identity.policy.Rule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with Rule

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

the class PolicyOpViewBeanBase method handleTblRulesEditLinkRequest.

/**
     * Handles edit rule request.
     *
     * @param event Request Invocation Event.
     */
public void handleTblRulesEditLinkRequest(RequestInvocationEvent event) throws ModelControlException {
    PolicyModel model = (PolicyModel) getModel();
    String name = hexToString((String) getDisplayFieldValue(TBL_RULES_ACTION_HREF));
    setPageSessionAttribute(RuleEditViewBean.CALLING_VIEW_BEAN, getClass().getName());
    setPageSessionAttribute(RuleEditViewBean.EDIT_RULE_NAME, name);
    try {
        CachedPolicy cachedPolicy = getCachedPolicy();
        Policy policy = cachedPolicy.getPolicy();
        Rule rule = policy.getRule(name);
        RuleEditViewBean vb = null;
        String resName = rule.getResourceName();
        if ((resName == null) || (resName.length() == 0)) {
            vb = (RuleNoResourceEditViewBean) getViewBean(RuleNoResourceEditViewBean.class);
            setPageSessionAttribute(RuleOpViewBeanBase.WITH_RESOURCE, Boolean.FALSE);
        } else {
            String realmName = (String) getPageSessionAttribute(AMAdminConstants.CURRENT_REALM);
            String serviceType = rule.getServiceTypeName();
            if (model.canCreateNewResource(realmName, serviceType)) {
                vb = (RuleEditViewBean) getViewBean(RuleEditViewBean.class);
            } else {
                vb = (RuleEditViewBean) getViewBean(RuleWithPrefixEditViewBean.class);
            }
            setPageSessionAttribute(RuleOpViewBeanBase.WITH_RESOURCE, Boolean.TRUE);
        }
        unlockPageTrail();
        passPgSessionMap(vb);
        vb.forwardTo(getRequestContext());
    } catch (NameNotFoundException e) {
        setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
        forwardTo();
    } catch (AMConsoleException e) {
        debug.warning("PolicyOpViewBeanBase.handleTblRulesEditLinkRequest", e);
        redirectToStartURL();
    }
}
Also used : Policy(com.sun.identity.policy.Policy) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) CachedPolicy(com.sun.identity.console.policy.model.CachedPolicy) PolicyModel(com.sun.identity.console.policy.model.PolicyModel) Rule(com.sun.identity.policy.Rule) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Example 25 with Rule

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

the class RuleAddViewBean method handleButton2Request.

/**
     * Handles create policy request.
     *
     * @param event Request invocation event
     */
public void handleButton2Request(RequestInvocationEvent event) throws ModelControlException {
    submitCycle = true;
    Rule rule = createRule();
    if (rule != null) {
        try {
            CachedPolicy cachedPolicy = getCachedPolicy();
            Policy policy = cachedPolicy.getPolicy();
            policy.addRule(rule);
            backTrail();
            cachedPolicy.setPolicyModified(true);
            forwardToPolicyViewBean();
        } catch (NameAlreadyExistsException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
            forwardTo();
        } catch (InvalidNameException e) {
            setInlineAlertMessage(CCAlert.TYPE_ERROR, "message.error", getModel().getErrorString(e));
            forwardTo();
        } catch (AMConsoleException e) {
            debug.warning("RuleAddViewBean.handleButton2Request", e);
            redirectToStartURL();
        }
    } else {
        forwardTo();
    }
}
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) NameAlreadyExistsException(com.sun.identity.policy.NameAlreadyExistsException) Rule(com.sun.identity.policy.Rule) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException)

Aggregations

Rule (com.sun.identity.policy.Rule)28 Policy (com.sun.identity.policy.Policy)15 HashSet (java.util.HashSet)12 Set (java.util.Set)12 PolicyException (com.sun.identity.policy.PolicyException)9 SSOException (com.iplanet.sso.SSOException)8 Subject (com.sun.identity.policy.interfaces.Subject)8 AMException (com.iplanet.am.sdk.AMException)6 InvalidAuthContextException (com.sun.identity.authentication.internal.InvalidAuthContextException)6 ConfigurationException (com.sun.identity.common.configuration.ConfigurationException)6 UnknownPropertyNameException (com.sun.identity.common.configuration.UnknownPropertyNameException)6 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)6 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)6 SMSException (com.sun.identity.sm.SMSException)6 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 LoginException (javax.security.auth.login.LoginException)6 ByteString (org.forgerock.opendj.ldap.ByteString)6