Search in sources :

Example 1 with Rule

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

the class RuleOpViewBeanBase method createRule.

protected Rule createRule() throws ModelControlException {
    Rule rule = null;
    String serviceType = (String) propertySheetModel.getValue(SERVICE_TYPE);
    String ruleName = getRuleName();
    Boolean b = ((Boolean) getPageSessionAttribute(WITH_RESOURCE));
    boolean withResource = (b != null) ? b.booleanValue() : false;
    String resourceName = (withResource) ? getResourceName() : null;
    // Get action values if this is not a referral policy
    actionValues = (!isReferralPolicy()) ? getActionValues(serviceType, withResource) : Collections.EMPTY_MAP;
    if ((ruleName != null) && (!withResource || (resourceName != null)) && (actionValues != null)) {
        rule = createRule(ruleName, serviceType, resourceName, actionValues);
    }
    return rule;
}
Also used : Rule(com.sun.identity.policy.Rule)

Example 2 with Rule

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

the class PolicyModelImpl method getProtectedResourceNames.

public Set getProtectedResourceNames(String realmName, String policyName) throws AMConsoleException {
    Set resourceNames = new HashSet();
    String policyID = cachePolicy(realmName, policyName);
    CachedPolicy cachedPolicy = getCachedPolicy(policyID);
    Policy policy = cachedPolicy.getPolicy();
    Set ruleNames = policy.getRuleNames();
    if ((ruleNames != null) && !ruleNames.isEmpty()) {
        for (Iterator iter = ruleNames.iterator(); iter.hasNext(); ) {
            String ruleName = (String) iter.next();
            try {
                Rule rule = policy.getRule(ruleName);
                if (rule != null) {
                    String resName = rule.getResourceName();
                    if ((resName != null) && (resName.trim().length() > 0)) {
                        resourceNames.add(resName);
                    }
                }
            } catch (NameNotFoundException nnfe) {
                if (debug.warningEnabled()) {
                    debug.warning("Cannot find the rule with name '" + ruleName + " in policy " + policy.getName(), nnfe);
                }
            }
        }
    }
    return resourceNames;
}
Also used : Policy(com.sun.identity.policy.Policy) Set(java.util.Set) HashSet(java.util.HashSet) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) Iterator(java.util.Iterator) Rule(com.sun.identity.policy.Rule) HashSet(java.util.HashSet)

Example 3 with Rule

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

the class PolicyModelImpl method getRuleNamesWithoutRes.

private Set getRuleNamesWithoutRes(Policy policy, String serviceTypeName) {
    Set rules = getRules(policy);
    Set selected = new HashSet(rules.size() * 2);
    for (Iterator iter = rules.iterator(); iter.hasNext(); ) {
        Rule rule = (Rule) iter.next();
        if (rule.getServiceTypeName().equals(serviceTypeName)) {
            String res = rule.getResourceName();
            if (res == null) {
                selected.add(rule.getName());
            }
        }
    }
    return selected;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) Rule(com.sun.identity.policy.Rule) HashSet(java.util.HashSet)

Example 4 with Rule

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

the class UpgradeUtils method createRealmAdminPolicy.

/**
     * Creates Realm Admin Policy.
     *
     * @param policyManager the policy manager object.
     * @param orgDN the organization dn.
     * @param orgID the organization identifier.
     */
private static void createRealmAdminPolicy(PolicyManager policyManager, String orgDN, String orgID) {
    String classMethod = "UpgradeUtils:createRealmAdminPolicy";
    try {
        String policyName = orgID + "^^RealmAdmin";
        Policy realmPolicy = new Policy(policyName, null, false, true);
        // create Rule
        String resourceName = "sms://*" + orgDN + "/*";
        Rule rule = getRule(DELEGATION_SERVICE, resourceName);
        if (rule != null) {
            realmPolicy.addRule(rule);
        }
        String universalID = getUniversalID(orgDN, ORG_ADMIN_ROLE);
        Subject subject = getSubject(policyManager, universalID);
        if (subject != null) {
            realmPolicy.addSubject(DELEGATION_SUBJECT, subject, false);
        }
        policyManager.addPolicy(realmPolicy);
    } catch (Exception e) {
        debug.error(classMethod + "Error creating realm admin policy", e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) ByteString(org.forgerock.opendj.ldap.ByteString) Rule(com.sun.identity.policy.Rule) Subject(com.sun.identity.policy.interfaces.Subject) 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)

Example 5 with Rule

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

the class UpgradeUtils method createDatastoresReadOnlyPolicy.

/**
     * Creates DataStores Read Only Policy
     *
     * @param policyManager the policy manager object.
     * @param orgDN the organization dn.
     * @param orgID the organization identifier.
     */
private static void createDatastoresReadOnlyPolicy(PolicyManager policyManager, String orgDN, String orgID) {
    String classMethod = "UpgradeUtils:createDatastoresReadOnlyPolicy";
    try {
        String policyName = orgID + "^^" + DATA_STORE_READ_ONLY;
        Policy realmPolicy = new Policy(policyName, null, false, true);
        // create Rule
        String serviceName = DELEGATION_SERVICE;
        String resourceName = "sms://*" + orgDN + "/" + IDREPO_SERVICE;
        Rule rule = getRule(serviceName, resourceName);
        if (rule != null) {
            realmPolicy.addRule(rule);
        }
        // add subjects
        String policyAdminRoleUniversalID = getUniversalID(orgDN, ORG_POLICY_ADMIN_ROLE);
        Subject subject = getSubject(policyManager, policyAdminRoleUniversalID);
        if (subject != null) {
            realmPolicy.addSubject(DELEGATION_SUBJECT, subject, false);
        }
        policyManager.addPolicy(realmPolicy);
    } catch (Exception e) {
        debug.error(classMethod + "Error creating datastores readonly policy", e);
    }
}
Also used : Policy(com.sun.identity.policy.Policy) ByteString(org.forgerock.opendj.ldap.ByteString) Rule(com.sun.identity.policy.Rule) Subject(com.sun.identity.policy.interfaces.Subject) 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)

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