Search in sources :

Example 1 with PrefixResourceName

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

the class PolicyProperties method setResourceComparator.

/**
     * Sets the <code>ResourceName</code> to be used by policy client API
     *
     * @param str <code>ResourceName</code> to be used by different services
     * with control parameters formatted in a proprietary <code>String</code>
     * format
     *
     */
void setResourceComparator(String str) throws PolicyException {
    if (debug.messageEnabled()) {
        debug.message("PolicyProperties.setResourceComparator():" + "entering with str value=" + str);
    }
    ResourceName resourceComparator = null;
    String[] tokens = new String[5];
    String serviceName = null;
    String className = null;
    String delimiter = null;
    String wildCard = null;
    String oneLevelWildCard = null;
    String caseSensitive = null;
    int count = 0;
    Map configMap = new HashMap(4);
    StringTokenizer st = new StringTokenizer(str, PIPE);
    while (st.hasMoreTokens()) {
        tokens[count++] = st.nextToken();
        if (count > 4) {
            // accept only first five tokens
            break;
        }
    }
    for (int i = 0; i < count; i++) {
        int equal = tokens[i].indexOf("=");
        String name = tokens[i].substring(0, equal);
        String value = tokens[i].substring(equal + 1);
        if (name == null) {
            debug.error("PolicyProperties.setResourceComparator():" + "Resource comapartaor: name is null");
            continue;
        }
        if (value == null) {
            debug.error("PolicyProperties.setResourceComparator():" + "Resource comapartaor: value is null");
            continue;
        }
        if (debug.messageEnabled()) {
            debug.message("PolicyProperties.setResourceComparator():" + "Attr Name= " + name + ":Attr Value=" + value);
        }
        if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_TYPE)) {
            serviceName = value;
        } else if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_CLASS)) {
            configMap.put(PolicyConfig.RESOURCE_COMPARATOR_CLASS, className);
            className = value;
        } else if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_DELIMITER)) {
            delimiter = value;
            configMap.put(PolicyConfig.RESOURCE_COMPARATOR_DELIMITER, delimiter);
        } else if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_WILDCARD)) {
            wildCard = value;
            configMap.put(PolicyConfig.RESOURCE_COMPARATOR_WILDCARD, wildCard);
        } else if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_ONE_LEVEL_WILDCARD)) {
            oneLevelWildCard = value;
            configMap.put(PolicyConfig.RESOURCE_COMPARATOR_ONE_LEVEL_WILDCARD, oneLevelWildCard);
        } else if (name.equalsIgnoreCase(PolicyConfig.RESOURCE_COMPARATOR_CASE_SENSITIVE)) {
            caseSensitive = value;
            configMap.put(PolicyConfig.RESOURCE_COMPARATOR_CASE_SENSITIVE, caseSensitive);
        }
    }
    if (serviceName == null) {
        debug.error("PolicyProperties().setResourceComparator():" + "ResourceComparator definition" + " not well formed" + str);
        Object[] args = { str };
        throw new PolicyException(ResBundleUtils.rbName, "invalid_resource_comparator", args, null);
    } else {
        try {
            if (className != null) {
                Class resourceClass = Class.forName(className);
                resourceComparator = (ResourceName) resourceClass.newInstance();
                resourceComparator.initialize(configMap);
            }
        } catch (ClassNotFoundException e) {
            debug.error("PolicyProperties.setResourceComparator():" + "Illegal exception ", e);
        } catch (IllegalAccessException e) {
            debug.error("PolicyProperties.setResourceComparator():" + "Illegal exception ", e);
        } catch (InstantiationException e) {
            debug.error("PolicyProperties.setResourceComparator():" + "InstantiationException " + " exception ", e);
        } finally {
            if (resourceComparator == null) {
                debug.error("PolicyProperties.setResourceCompartor():" + "invalid configuration:" + str + ":defaulting to PrefixResourceName");
                resourceComparator = new PrefixResourceName();
            }
        }
        resourceComparators.put(serviceName, resourceComparator);
    }
}
Also used : HashMap(java.util.HashMap) PrefixResourceName(com.sun.identity.policy.plugins.PrefixResourceName) ResourceName(com.sun.identity.policy.interfaces.ResourceName) StringTokenizer(java.util.StringTokenizer) PolicyException(com.sun.identity.policy.PolicyException) HashMap(java.util.HashMap) Map(java.util.Map) PrefixResourceName(com.sun.identity.policy.plugins.PrefixResourceName)

Aggregations

PolicyException (com.sun.identity.policy.PolicyException)1 ResourceName (com.sun.identity.policy.interfaces.ResourceName)1 PrefixResourceName (com.sun.identity.policy.plugins.PrefixResourceName)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1