Search in sources :

Example 56 with Attr

use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.

the class TemplateManager method encodeAttrSet.

/**
     * Encode an attrSet in a single attribute with multiple values using the
     * given attribute name and the values (tag,value) found in the given
     * attribute set. For example:
     * 
     * <pre>
     *    Attribute:
     *       required: objectclass=top
     *       required: objectclass=groupofuniquenames
     *       required: cn
     *       required: sn
     *  
     *    Attribute Set:
     *       objectclass: top
     *       objectclass: groupofuniquenames
     *       cn:
     *       sn:
     * </pre>
     * 
     * @param attrName
     *            Name of the encoded attribute.
     * @param attrSet
     *            Attribute set to be encoded in a single attribut.e
     * @param delimiter
     *            String token used as delimiter for the encoding.
     * @return Encoded attribute or null object if attrSet is empty.
     */
private Attr encodeAttrSet(String attrName, AttrSet attrSet, String delimiter) {
    if (attrSet == null || attrSet.size() == 0) {
        return null;
    }
    Enumeration attrEnum = attrSet.getAttributes();
    Attr encodedAttr = new Attr(attrName);
    while (attrEnum.hasMoreElements()) {
        Attr a = (Attr) attrEnum.nextElement();
        String[] values = a.getStringValues();
        String[] encodedValues = new String[values.length];
        if (values.length == 0) {
            encodedAttr.addValue(a.getName());
        } else {
            for (int i = 0; i < values.length; i++) {
                encodedValues[i] = a.getName() + delimiter + values[i];
            }
            encodedAttr.addValues(encodedValues);
        }
    }
    return encodedAttr;
}
Also used : Enumeration(java.util.Enumeration) Attr(com.iplanet.services.ldap.Attr)

Example 57 with Attr

use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.

the class TemplateManager method toSearchTemplate.

/**
     * Reads in a attribute set and converts name-value pairs to a
     * SearchTemplate object.
     * 
     * @param t
     *            attribute set contains template values
     * @return SearchTemplate object based on the name-value pairs
     */
private SearchTemplate toSearchTemplate(AttrSet t) {
    Attr nameAttr = t.getAttribute(TEMPLATE_NAME);
    String name = null;
    if (nameAttr != null) {
        name = nameAttr.getValue();
    }
    Attr filterAttr = t.getAttribute(SCHEMA2_SEARCH_FILTER);
    if (filterAttr == null) {
        filterAttr = t.getAttribute(TEMPLATE_SEARCH_FILTER);
    }
    String filter = null;
    if (filterAttr != null) {
        filter = filterAttr.getValue();
    }
    AttrSet attrSet = decodeAttr(t.getAttribute(TEMPLATE_ATTRS), "=");
    SearchTemplate template = new SearchTemplate();
    template = new SearchTemplate(name, attrSet, filter);
    return template;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 58 with Attr

use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.

the class TemplateManager method toCreationTemplate.

/**
     * Reads in a attribute set and converts name-value pairs to a
     * CreationTemplate object.
     * 
     * @param t
     *            attribute set contains template values
     * @return CreationTemplate object based on the name-value pairs
     */
private CreationTemplate toCreationTemplate(AttrSet t) {
    Attr nameAttr = t.getAttribute(TEMPLATE_NAME);
    String name = null;
    if (nameAttr != null) {
        name = nameAttr.getValue();
    }
    Attr namingAttr = t.getAttribute(TEMPLATE_NAMINGATTRIBUTE);
    String namingAttribute = null;
    if (namingAttr != null) {
        namingAttribute = namingAttr.getValue();
    }
    Attr classAttr = t.getAttribute(TEMPLATE_JAVACLASS);
    String[] classNames = null;
    if (classAttr != null) {
        classNames = classAttr.getStringValues();
    }
    AttrSet required = decodeAttr(t.getAttribute(TEMPLATE_REQUIRED), "=");
    AttrSet optional = decodeAttr(t.getAttribute(TEMPLATE_OPTIONAL), "=");
    AttrSet validated = decodeAttr(t.getAttribute(TEMPLATE_VALIDATED), "=");
    CreationTemplate template = new CreationTemplate();
    ArrayList classes = new ArrayList();
    try {
        if (classNames != null) {
            for (int i = 0; i < classNames.length; i++) {
                Class cls = Class.forName(classNames[i]);
                classes.add(cls);
            }
        }
        template = new CreationTemplate(name, required, optional, classes);
    } catch (ClassNotFoundException e) {
        template = new CreationTemplate(name, required, optional);
    }
    if (validated != null) {
        template.setValidation(validated);
    }
    if (namingAttribute != null) {
        template.setNamingAttribute(namingAttribute);
    }
    return template;
}
Also used : ArrayList(java.util.ArrayList) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 59 with Attr

use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.

the class Validation method validateAttributes.

/**
     * Determines whether each attribute in the ModSet is valid.
     * 
     * @param modSet
     *            modSet to test
     * @param cls
     *            Class associated with these attributes
     * @param guid
     *            the guid of the Organization where the config data is stored
     * @exception UMSException
     *                failure
     * @exception DataConstraintException
     *                data validation failure
     */
public static void validateAttributes(ModSet modSet, Class cls, Guid guid) throws UMSException, DataConstraintException {
    if (modSet == null) {
        return;
    }
    for (int i = 0; i < modSet.size(); i++) {
        Modification ldapMod = modSet.elementAt(i);
        if (!ModificationType.DELETE.equals(ldapMod.getModificationType())) {
            Attr attr = new Attr(ldapMod.getAttribute());
            validateAttribute(attr, cls, guid);
        }
    }
}
Also used : Modification(org.forgerock.opendj.ldap.Modification) Attr(com.iplanet.services.ldap.Attr)

Example 60 with Attr

use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.

the class Validation method validateAttributes.

/**
     * Determines whether each attribute in the attribute set is valid. Iterates
     * though the set checking each element to see if there is a validation
     * method that needs to execute.
     * 
     * @param attrSet
     *            attribute set to test
     * @param cls
     *            Class associated with these attribute set
     * @param guid
     *            the guid of the Organization where the config data is stored
     * @exception UMSException
     *                failure
     * @exception DataConstraintException
     *                data validation failure
     */
public static void validateAttributes(AttrSet attrSet, Class cls, Guid guid) throws UMSException, DataConstraintException {
    if (attrSet == null) {
        return;
    }
    String[] attrNames = attrSet.getAttributeNames();
    for (int i = 0; i < attrNames.length; i++) {
        Attr attr = attrSet.getAttribute(attrNames[i]);
        validateAttribute(attr, cls, guid);
    }
}
Also used : Attr(com.iplanet.services.ldap.Attr)

Aggregations

Attr (com.iplanet.services.ldap.Attr)89 AttrSet (com.iplanet.services.ldap.AttrSet)34 Guid (com.iplanet.ums.Guid)16 Iterator (java.util.Iterator)15 UMSException (com.iplanet.ums.UMSException)14 PersistentObject (com.iplanet.ums.PersistentObject)12 HashSet (java.util.HashSet)12 Set (java.util.Set)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 ByteString (org.forgerock.opendj.ldap.ByteString)9 AMException (com.iplanet.am.sdk.AMException)7 SSOException (com.iplanet.sso.SSOException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 Enumeration (java.util.Enumeration)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)3 CreationTemplate (com.iplanet.ums.CreationTemplate)3 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)3