Search in sources :

Example 31 with AttrSet

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

the class DirectoryServicesImpl method getAttributesFromDS.

/**
     * Gets the specific attributes corresponding to the entryDN. This method
     * obtains the DC Tree node attributes and also performs compliance related
     * verification checks in compliance mode. Note: In compliance mode you can
     * skip the compliance checks by setting ignoreCompliance to "false".
     * 
     * @param token
     *            a valid SSOToken
     * @param entryDN
     *            the DN of the entry whose attributes need to retrieved
     * @param attrNames
     *            a Set of names of the attributes that need to be retrieved.
     *            The attrNames should not be null.
     * @param ignoreCompliance
     *            a boolean value specificying if compliance related entries
     *            need to ignored or not. Ignored if true.
     * @return a Map containing attribute names as keys and Set of values
     *         corresponding to each key.
     * @throws AMException
     *             if an error is encountered in fetching the attributes
     */
public Map getAttributesFromDS(SSOToken token, String entryDN, Set attrNames, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    if (attrNames == null) {
        return getAttributes(token, entryDN, ignoreCompliance, byteValues, profileType);
    }
    try {
        // Convert the attrNames to String[]
        String[] names = (String[]) attrNames.toArray(new String[attrNames.size()]);
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        // Perform compliance related checks
        AttrSet attrSet;
        if (!ignoreCompliance && ComplianceServicesImpl.isComplianceUserDeletionEnabled()) {
            // check for deleted user by getting complaince attributes
            attrSet = complianceImpl.verifyAndGetAttributes(po, names);
        } else {
            attrSet = po.getAttributes(names);
        }
        AMHashMap attributes = (AMHashMap) CommonUtils.attrSetToMap(attrSet, byteValues);
        // Obtain DC tree attributes if applicable            
        Map dcAttributes = getDCTreeAttributes(token, entryDN, attrNames, byteValues, profileType);
        attributes.copy(dcAttributes);
        return attributes;
    } catch (UMSException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.getAttributes(): " + "Unable to get attributes: ", e);
        }
        // Extract the ldap error code from Exception
        throw new AMException(token, "330", e);
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) AMHashMap(com.iplanet.am.sdk.AMHashMap) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 32 with AttrSet

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

the class CallBackHelper method preProcess.

// TODO: Remove this. Use the Maps interface only
public AttrSet preProcess(SSOToken token, String entryDN, String orgDN, AttrSet oldAttrSet, AttrSet newAttrSet, int operation, int objectType, boolean softDelete) throws AMException {
    Set implSet = getPrePostImpls(orgDN);
    if (implSet != null && !implSet.isEmpty()) {
        // Post processing impls present
        // Iterate through the Pre-Processing Impls and execute
        Iterator itr = implSet.iterator();
        Map newAttrMap = CommonUtils.attrSetToMap(newAttrSet);
        Map oldAttrMap = CommonUtils.attrSetToMap(oldAttrSet);
        while (itr.hasNext()) {
            String className = (String) itr.next();
            AMCallBack impl = getCallBackObject(className);
            if (impl == null) {
                continue;
            }
            try {
                Map map;
                switch(operation) {
                    case CREATE:
                        map = impl.preProcessCreate(token, entryDN, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case MODIFY:
                        map = impl.preProcessModify(token, entryDN, oldAttrMap, newAttrMap, objectType);
                        newAttrMap = ((map == null) ? newAttrMap : map);
                        break;
                    case DELETE:
                        impl.preProcessDelete(token, entryDN, oldAttrMap, softDelete, objectType);
                        break;
                }
            } catch (AMException ae) {
                // Exception thrown by the external impl
                debug.error("CallBackHelper.preProcess(): Preprocessing" + "impl " + className + " exception thrown by impl:", ae);
                throw ae;
            }
        }
        return CommonUtils.mapToAttrSet(newAttrMap);
    }
    // not null as newAttrSet will be the latest one needed for updation
    return ((newAttrSet != null) ? newAttrSet : oldAttrSet);
}
Also used : AMCallBack(com.iplanet.am.sdk.AMCallBack) AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) Iterator(java.util.Iterator) AMException(com.iplanet.am.sdk.AMException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 33 with AttrSet

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

the class MiscUtils method mapToAttrSet.

/**
     * Method to convert a Map to AttrSet.
     * 
     * @param map
     *            a map contaning attribute names as keys and a Set of attribute
     *            values corresponding to each map key.
     * @param byteValues
     *            if true then values are bytes otherwise strings
     * @return an AttrSet having the contents of the supplied map
     */
public static AttrSet mapToAttrSet(Map map, boolean byteValues) {
    AttrSet attrSet = new AttrSet();
    if (map == null) {
        return attrSet;
    }
    if (!byteValues) {
        Iterator itr = map.keySet().iterator();
        while (itr.hasNext()) {
            String attrName = (String) (itr.next());
            Set set = (Set) (map.get(attrName));
            String[] attrValues = (set == null ? null : (String[]) set.toArray(new String[set.size()]));
            attrSet.replace(new Attr(attrName, attrValues));
        }
    } else {
        Iterator itr = map.keySet().iterator();
        while (itr.hasNext()) {
            String attrName = (String) (itr.next());
            byte[][] attrValues = (byte[][]) (map.get(attrName));
            attrSet.replace(new Attr(attrName, attrValues));
        }
    }
    return attrSet;
}
Also used : AttrSet(com.iplanet.services.ldap.AttrSet) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 34 with AttrSet

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

the class MiscUtils method combineAttrSets.

/**
     * Combines 2 AttrSets and returns the result set. The original sets are not
     * modified.
     * 
     * @param attrSet1
     *            the first AttrSet
     * @param attrSet2
     *            the second AttrSet
     * @return an AttrSet which has combined values of attrSet1 & attrSet2
     */
public static AttrSet combineAttrSets(AttrSet attrSet1, AttrSet attrSet2) {
    AttrSet retAttrSet = new AttrSet();
    if (attrSet1 != null) {
        int count = attrSet1.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet1.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    if (attrSet2 != null) {
        int count = attrSet2.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet2.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    return retAttrSet;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 35 with AttrSet

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

the class CommonUtils method combineAttrSets.

/**
     * Combines 2 AttrSets and returns the result set. The original sets are not
     * modified.
     * 
     * @param attrSet1
     *            the first AttrSet
     * @param attrSet2
     *            the second AttrSet
     * @return an AttrSet which has combined values of attrSet1 & attrSet2
     */
protected static AttrSet combineAttrSets(AttrSet attrSet1, AttrSet attrSet2) {
    AttrSet retAttrSet = new AttrSet();
    if (attrSet1 != null) {
        int count = attrSet1.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet1.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    if (attrSet2 != null) {
        int count = attrSet2.size();
        for (int i = 0; i < count; i++) {
            Attr attr = attrSet2.elementAt(i);
            retAttrSet.add(attr);
        }
    }
    return retAttrSet;
}
Also used : Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Aggregations

AttrSet (com.iplanet.services.ldap.AttrSet)61 Attr (com.iplanet.services.ldap.Attr)33 Guid (com.iplanet.ums.Guid)19 Iterator (java.util.Iterator)16 Set (java.util.Set)14 UMSException (com.iplanet.ums.UMSException)13 AMException (com.iplanet.am.sdk.AMException)12 CreationTemplate (com.iplanet.ums.CreationTemplate)12 TemplateManager (com.iplanet.ums.TemplateManager)12 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 PersistentObject (com.iplanet.ums.PersistentObject)6 SSOException (com.iplanet.sso.SSOException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)4 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)4 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)3 AccessRightsException (com.iplanet.ums.AccessRightsException)3 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)3