SMSUtils.java revision f6d3e8d6653f14cfd38ebbbeac75a12a8536f0c7
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: SMSUtils.java,v 1.5 2008/07/11 01:46:21 arviranga Exp $
d135fba117a27e6d0de2f5518a274bba4c0a38efJames Phillpotts * Portions Copyrighted 2011-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.CaseInsensitiveHashMap;
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Joosteimport com.sun.identity.security.AdminTokenAction;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class SMSUtils {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String SERVICE = "Service";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String VERSION = "version";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String SUB_SCHEMA = "SubSchema";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String SUB_CONFIG = "SubConfiguration";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String GLOBAL_SCHEMA = "Global";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String GLOBAL_CONFIG = "GlobalConfiguration";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ORG_SCHEMA = "Organization";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major public static final String ORG_ATTRIBUTE_SCHEMA =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "OrganizationAttributeSchema";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major public static final String ORG_ATTRIBUTE_VALUE_PAIR =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "OrganizationAttributeValuePair";
28de0461d82a4e6471c71d793af7a9492ca98dd3Jaco Jooste public static final String I18N_KEY = "i18nKey";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ORG_CONFIG = "OrganizationConfiguration";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String DYNAMIC_SCHEMA = "Dynamic";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String USER_SCHEMA = "User";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String POLICY_SCHEMA = "Policy";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String GROUP_SCHEMA = "Group";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String DOMAIN_SCHEMA = "Domain";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String GENERIC_SCHEMA = "Generic";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String CONFIGURATION = "Configuration";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String INSTANCE = "Instance";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String SERVICE_ID = "id";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PRIORITY = "priority";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String COSPRIORITY = "cospriority";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String DEFAULT = "default";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String RESOURCE_BUNDLE_URL = "i18nJarURL";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PROPERTIES_FILENAME = "i18nFileName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String SERVICE_HIERARCHY = "serviceHierarchy";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String PROPERTIES_VIEW_BEAN_URL =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "propertiesViewBeanURL";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String REVISION_NUMBER = "revisionNumber";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String STATUS_ATTRIBUTE = "statusAttribute";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String VALIDATE = "validate";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String INHERITANCE = "inheritance";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ISSEARCHABLE = "isSearchable";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_INTERFACE = "PluginInterface";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_INTERFACE_CLASS = "interface";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_SCHEMA = "PluginSchema";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_SCHEMA_INT_NAME = "interfaceName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_SCHEMA_CLASS_NAME = "className";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_SCHEMA_JAR_URL = "jarURL";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_SCHEMA_ORG_NAME = "organizationName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_CONFIG = "PluginConfiguration";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String PLUGIN_CONFIG_SCHEMA_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "pluginSchemaName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_CONFIG_INT_NAME = "interfaceName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String PLUGIN_CONFIG_ORG_NAME = "organizationName";
f6d3e8d6653f14cfd38ebbbeac75a12a8536f0c7James Phillpotts public static final String SCHEMA_ATTRIBUTE = "AttributeSchema";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_VALUE_PAIR = "AttributeValuePair";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE = "Attribute";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_TYPE = "type";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_UITYPE = "uitype";
3286da3756e1d2f07709aafdbc5419b26ff71dffPhill Cunnington protected static final String ATTRIBUTE_LIST_ORDER = "listOrder";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_SYNTAX = "syntax";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_DEFAULT = "default";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_RANGE_START = "rangeStart";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_RANGE_END = "rangeEnd";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_MIN_VALUE = "minValue";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_MAX_VALUE = "maxValue";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_VALIDATOR = "validator";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_OPTIONAL = "IsOptional";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_SERVICE_ID = "IsServiceIdentifier";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_RESOURCE_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "IsResourceNameAllowed";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_STATUS_ATTR = "IsStatusAttribute";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String HAS_SERVICE_URLS = "HasServiceURLs";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_ANY = "any";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_VIEW_BEAN_URL =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "propertiesViewBeanURL";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_VALUE = "Value";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_DEFAULT_ELEMENT = "DefaultValues";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_DEFAULT_CLASS =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "DefaultValuesClassName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String CLASS_NAME = "className";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_CHOICE_CLASS =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ChoiceValuesClassName";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_CHOICE_VALUES_ELEMENT =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ChoiceValues";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_CHOICE_VALUE_ELEMENT =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ChoiceValue";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String ATTRIBUTE_COS_QUALIFIER = "cosQualifier";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_BOOLEAN_VALUES_ELEMENT =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "BooleanValues";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_TRUE_BOOLEAN_ELEMENT =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "BooleanTrueValue";
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major protected static final String ATTRIBUTE_FALSE_BOOLEAN_ELEMENT =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "BooleanFalseValue";
d135fba117a27e6d0de2f5518a274bba4c0a38efJames Phillpotts public static final String RESOURCE_NAME = "resourceName";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Performs a deep copy of the Map
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major public static Map<String, Object> copyAttributes(Map<String, Object> attributes) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major Map<String, Object> answer = attributes instanceof CaseInsensitiveHashMap ?
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major new CaseInsensitiveHashMap(attributes.size()) : new HashMap<String, Object>(attributes.size());
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major for (Map.Entry<String, Object> entry : attributes.entrySet()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Copy the HashSet
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static Map<String, Set<String>> getAttrsFromEntry(SMSEntry entry) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major SMSEntry.debug.message("SMSUtils: obtains attrs from entry: " + entry.getDN());
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major Map<String, Set<String>> answer = new HashMap<String, Set<String>>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] attrValues = entry.getAttributeValues(SMSEntry.ATTR_KEYVAL);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major String[] searchableAttrValues = entry.getAttributeValues(SMSEntry.ATTR_XML_KEYVAL);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (attrValues == null && searchableAttrValues == null) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major addAttributesToMap(entry, searchableAttrValues, answer);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major private static void addAttributesToMap(SMSEntry entry, String[] attrs, Map<String, Set<String>> attrMap) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major // Get attribute name and value
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major // Error in attribute values
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major SMSEntry.debug.error("SMSUtils: Invalid attribute entry: " + attribute
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (attrValue != null && !attrValue.isEmpty()) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void setAttributeValuePairs(SMSEntry e, Map<String, Object> attrs, Set<String> searchAttrNames)
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major SMSEntry.debug.message("SMSUtils: setting attrs to entry: " + e.getDN());
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major for (Map.Entry<String, Object> entry : attrs.entrySet()) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major boolean isSearchable = searchAttrNames.contains(attrName.toLowerCase());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // an attribute with no values
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.setAttribute(SMSEntry.ATTR_KEYVAL, values.toArray(new String[values.size()]));
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.setAttribute(SMSEntry.ATTR_XML_KEYVAL, srchValues.toArray(new String[srchValues.size()]));
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void addAttribute(SMSEntry e, String attrName, Set<String> values, Set<String> searchableAttrNames)
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major SMSEntry.debug.message("SMSUtils: adding attributes to entry: " + e.getDN());
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (searchableAttrNames.contains(attrName.toLowerCase())) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.addAttribute(SMSEntry.ATTR_XML_KEYVAL, attrName + "=" + value);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.addAttribute(SMSEntry.ATTR_KEYVAL, attrName + "=" + value);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void removeAttribute(SMSEntry e, String attrName) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] attrValues = e.getAttributeValues(SMSEntry.ATTR_KEYVAL);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major String[] searchableAttrValues = e.getAttributeValues(SMSEntry.ATTR_XML_KEYVAL);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (attrValues == null && searchableAttrValues == null) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.removeAttribute(SMSEntry.ATTR_KEYVAL, attrValue);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major for (String searchableAttrValue : searchableAttrValues) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.removeAttribute(SMSEntry.ATTR_XML_KEYVAL, searchableAttrValue);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void removeAttributeValues(SMSEntry e, String attrName, Set<String> values, Set searchableAttrNames)
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (attrName == null || values == null || values.isEmpty()) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (searchableAttrNames.contains(attrName.toLowerCase())) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major e.removeAttribute(SMSEntry.ATTR_XML_KEYVAL, attrName + "=" + value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster e.removeAttribute(SMSEntry.ATTR_KEYVAL, attrName + "=" + value);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void replaceAttributeValue(SMSEntry entry, String attrName, String oldValue, String newValue,
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major Set<String> searchableAttrNames) throws SMSException {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (searchableAttrNames.contains(attrName.toLowerCase())) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major entry.removeAttribute(SMSEntry.ATTR_XML_KEYVAL, attrName + "=" + oldValue);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major entry.addAttribute(SMSEntry.ATTR_XML_KEYVAL, attrName + "=" + newValue);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major entry.removeAttribute(SMSEntry.ATTR_KEYVAL, attrName + "=" + oldValue);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entry.addAttribute(SMSEntry.ATTR_KEYVAL, attrName + "=" + newValue);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static void replaceAttributeValues(SMSEntry entry, String attrName, Set<String> oldValues, Set<String> newValues,
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major Set<String> searchableAttrNames) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster removeAttributeValues(entry, attrName, oldValues, searchableAttrNames);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add other values
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major if (searchableAttrNames.contains(attrName.toLowerCase())) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major entry.addAttribute(SMSEntry.ATTR_XML_KEYVAL, attrName + "=" + value);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major entry.addAttribute(SMSEntry.ATTR_KEYVAL, attrName + "=" + value);
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major static String toAttributeValuePairXML(Map<String, Set<String>> map) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major for (Map.Entry<String, Set<String>> e : map.entrySet()) {
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major buff.append("<").append(SMSUtils.ATTRIBUTE_VALUE_PAIR).append(">\n");
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major .append(" ").append(SMSUtils.NAME).append("=\"").append(e.getKey()).append("\"/>\n");
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major buff.append(" <").append(SMSUtils.ATTRIBUTE_VALUE).append(">")
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major .append(SMSSchema.escapeSpecialCharacters(value))
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major .append("</").append(SMSUtils.ATTRIBUTE_VALUE).append(">\n");
d4b8d8f560390b2e8014bf37500efb7446f81510Peter Major buff.append("</").append(SMSUtils.ATTRIBUTE_VALUE_PAIR).append(">\n");
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste * Remove the validator attributes from the given attribute defaults map.
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste * @param attributeDefaults The attribute defaults.
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste * @param serviceSchema The service schema in which the attributes are specified.
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste * @return A copy of the attribute defaults with the validators removed.
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste public static Map<String, Set<String>> removeValidators(Map<String, Set<String>> attributeDefaults,
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste final Map<String, Set<String>> subset = new HashMap<String, Set<String>>();
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste for (Map.Entry<String, Set<String>> entry : attributeDefaults.entrySet()) {
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste if (!AttributeSchema.Type.VALIDATOR.equals(serviceSchema.getAttributeSchema(name).getType())) {
100d882219e8f87f6253fa08a4b7bde5a6e97f08Jaco Jooste subset.put(name, new HashSet<String>(entry.getValue()));
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * Walk the schema tree from the given service schema to find a dynamic validator with the given name. The search
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * will end as soon as the attribute describing the validator is found.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @param serviceSchema The service schema from which to star the search.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @param validatorName The name of the validator to look for.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @param validators Then list to add the validators to.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @return A list of dynamic validators.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @throws SSOException, SMSException If the schema could not be read.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste public static void findDynamicValidators(ServiceSchema serviceSchema, String validatorName,
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste List<Class<DynamicAttributeValidator>> validators)
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste if (serviceSchema == null || validatorName == null) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste Set<AttributeSchema> attributeSchemas = serviceSchema.getAttributeSchemas();
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste for (AttributeSchema schema : attributeSchemas) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste if (schema.getType() == AttributeSchema.Type.VALIDATOR && validatorName.equals(schema.getName())) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste final Set<String> validatorClassNames = schema.getDefaultValues();
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste for (String validatorClassName : validatorClassNames) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste final Class clazz = Class.forName(validatorClassName);
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste if (DynamicAttributeValidator.class.isAssignableFrom(clazz)) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste SMSEntry.debug.error("SMSUtils: Validator class not found: " + validatorClassName, e);
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste Set<String> schemaNames = serviceSchema.getSubSchemaNames();
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste findDynamicValidators(serviceSchema.getSubSchema(schemaName), validatorName, validators);
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * Retrieve a list of dynamic validators with the given name for a specific service.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @param serviceName The name of the service to search through.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @param validatorName The name of the attribute in which the validators were specified.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @return A list of {@link DynamicAttributeValidator}s associated with the given attribute or
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * an empty list if none were found.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste * @throws SSOException, SMSException If the schema could not be read.
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste public static List<Class<DynamicAttributeValidator>> findDynamicValidators(String serviceName, String validatorName)
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste List<Class<DynamicAttributeValidator>> validators = new ArrayList<Class<DynamicAttributeValidator>>();
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste if (StringUtils.isBlank(validatorName) || "no".equalsIgnoreCase(validatorName)) {
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste ServiceSchemaManager ssm = new ServiceSchemaManager(serviceName,
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste AccessController.doPrivileged(AdminTokenAction.getInstance()));
44533057912ac5c4bca52935b8fbc8e6d59d0671Jaco Jooste findDynamicValidators(ssm.getSchema(SchemaType.GLOBAL), validatorName, validators);