Search in sources :

Example 41 with UMSException

use of com.iplanet.ums.UMSException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method getAttributes.

/**
     * Gets all 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 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 getAttributes(SSOToken token, String entryDN, boolean ignoreCompliance, boolean byteValues, int profileType) throws AMException, SSOException {
    try {
        // Obtain attributes from directory
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        AttrSet attrSet = po.getAttributes(po.getAttributeNames());
        /*
             * Add this 'dn' explicitly to the result set and return. reason:
             * when queried with this entrydn/dn the lower level api/ ldapjdk
             * does not return this attribute, but returns other ones.
             */
        attrSet.add(new Attr("dn", entryDN));
        attrSet.add(new Attr("entryDN", entryDN));
        // Perform Compliance related checks
        checkComplianceAttributes(attrSet, ignoreCompliance);
        AMHashMap attributes = (AMHashMap) CommonUtils.attrSetToMap(attrSet, byteValues);
        Map dcAttributes = getDCTreeAttributes(token, entryDN, null, byteValues, profileType);
        attributes.copy(dcAttributes);
        return attributes;
    } catch (IllegalArgumentException ie) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.getAttributes(): " + "Unable to get attributes: ", ie);
        }
        String locale = CommonUtils.getUserLocale(token);
        throw new AMException(AMSDKBundle.getString("330", locale), "330");
    } 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) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 42 with UMSException

use of com.iplanet.ums.UMSException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method renameEntry.

/**
     * Renames an entry. Currently used for only user renaming
     * 
     * @param token
     *            the sso token
     * @param objectType
     *            the type of entry
     * @param entryDN
     *            the entry DN
     * @param newName
     *            the new name (i.e., if RDN is cn=John, the value passed should
     *            be "John"
     * @param deleteOldName
     *            if true the old name is deleted otherwise it is retained.
     * @return new <code>DN</code> of the renamed entry
     * @throws AMException
     *             if the operation was not successful
     */
public String renameEntry(SSOToken token, int objectType, String entryDN, String newName, boolean deleteOldName) throws AMException {
    try {
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        String newRDN = getNamingAttribute(objectType) + "=" + newName;
        po.rename(newRDN, deleteOldName);
        return po.getDN();
    } catch (AccessRightsException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.renameEntry(): User does " + "not have sufficient access rights ", e);
        }
        throw new AMException(token, "460");
    } catch (EntryNotFoundException e) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.renameEntry(): Entry " + "not found: ", e);
        }
        String msgid = getEntryNotFoundMsgID(objectType);
        String entryName = getEntryName(e);
        Object[] args = { entryName };
        throw new AMException(AMSDKBundle.getString(msgid, args), msgid, args);
    } catch (UMSException ume) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.renameEntry(): Unable to " + "rename entry: ", ume);
        }
        throw new AMException(token, "360", ume);
    }
}
Also used : AccessRightsException(com.iplanet.ums.AccessRightsException) UMSException(com.iplanet.ums.UMSException) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid)

Example 43 with UMSException

use of com.iplanet.ums.UMSException in project OpenAM by OpenRock.

the class ComplianceServicesImpl method verifyAndGetAttributes.

/**
     * Method which adds additional compliance required attributes to the
     * existing list of attribute names and then fetches the attribute set from
     * LDAP. The compliance attributes are verified for "inetuserstatus"
     * attribute.
     * <p>
     * 
     * @param po a PersistentObject of the entry.
     * @param attributeNames Array of attribute names.
     * @throws AMException if the fetched attribute names has inetuserstatus
     *         attribute and the value of which is "deleted" or if unable to
     *         fetch the attribute set.
     */
protected AttrSet verifyAndGetAttributes(PersistentObject po, String[] attributeNames) throws AMException {
    // The only thing to verify for compliance is "deleted user". Hence,
    // fetch additional attribute "inetuserstatus" along with the given
    // attributes
    boolean found = false;
    // Check if "intetuserstatus" attribute already exists in request
    int i = 0;
    int numAttrs = attributeNames.length;
    String[] fetchAttributes = new String[numAttrs + 1];
    for (; i < numAttrs; i++) {
        if (attributeNames[i].equalsIgnoreCase(USER_STATUS_ATTRIBUTE)) {
            found = true;
            break;
        } else {
            fetchAttributes[i] = attributeNames[i];
        }
    }
    if (// Add "inetuserstatus" attribute
    !found)
        fetchAttributes[i] = USER_STATUS_ATTRIBUTE;
    else
        // use the original list of attr names
        fetchAttributes = attributeNames;
    // Fetch the attribute,value pairs
    AttrSet retAttrSet;
    try {
        retAttrSet = po.getAttributes(fetchAttributes);
    } catch (UMSException ue) {
        debug.error("Compliance.verifyAndGetAttributes(): ", ue);
        throw new AMException(AMSDKBundle.getString("330"), "330");
    }
    // Verify for deleted user
    verifyAttributes(retAttrSet);
    if (!found) {
        retAttrSet.remove(USER_STATUS_ATTRIBUTE);
    }
    return retAttrSet;
}
Also used : UMSException(com.iplanet.ums.UMSException) AMException(com.iplanet.am.sdk.AMException) AttrSet(com.iplanet.services.ldap.AttrSet)

Example 44 with UMSException

use of com.iplanet.ums.UMSException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method updateUserAttribute.

/**
     * Adds or remove static group DN to or from member attribute
     * 'iplanet-am-static-group-dn'
     * 
     * @param token
     *            SSOToken
     * @param members
     *            set of user DN's
     * @param staticGroupDN
     *            DN of the static group
     * @param toAdd
     *            true to add, false to remove
     * @throws AMException
     *             if there is an internal problem with AM Store.
     */
public void updateUserAttribute(SSOToken token, Set members, String staticGroupDN, boolean toAdd) throws AMException {
    if (debug.messageEnabled()) {
        debug.message("DirectoryServicesImpl.updateUserAttribute(): " + "groupDN:" + staticGroupDN + ", toAdd: " + toAdd + " members: " + members);
    }
    Attr attr = new Attr(STATIC_GROUP_DN_ATTRIBUTE, staticGroupDN);
    Iterator itr = members.iterator();
    while (itr.hasNext()) {
        String userDN = (String) itr.next();
        try {
            PersistentObject po = UMSObject.getObjectHandle(token, new Guid(userDN));
            if (toAdd) {
                po.modify(attr, ModificationType.ADD);
            } else {
                po.modify(attr, ModificationType.DELETE);
            }
            po.save();
        } catch (UMSException e) {
            debug.error("DirectoryServicesImpl.updateUserAttribute(): " + "Failed while trying to set the static groupDN " + staticGroupDN + " for user: " + userDN, e);
            throw new AMException(token, "351", e);
        }
    }
}
Also used : UMSException(com.iplanet.ums.UMSException) Iterator(java.util.Iterator) PersistentObject(com.iplanet.ums.PersistentObject) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid) Attr(com.iplanet.services.ldap.Attr)

Example 45 with UMSException

use of com.iplanet.ums.UMSException in project OpenAM by OpenRock.

the class DirectoryServicesImpl method setGroupFilter.

/**
     * Sets the filter for a dynamic group in the datastore.
     * 
     * @param token
     * @param entryDN
     * @param filter
     * @throws AMException
     * @throws SSOException
     */
public void setGroupFilter(SSOToken token, String entryDN, String filter) throws AMException, SSOException {
    try {
        DynamicGroup dynamicGroup = (DynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
        dynamicGroup.setSearchFilter(filter);
        dynamicGroup.save();
    } catch (UMSException ume) {
        debug.message("AMDynamicGroup.setSearchFilter() - Unable to " + "setFilter()", ume);
        throw new AMException(token, "352", ume);
    }
}
Also used : DynamicGroup(com.iplanet.ums.DynamicGroup) AssignableDynamicGroup(com.iplanet.ums.AssignableDynamicGroup) UMSException(com.iplanet.ums.UMSException) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid)

Aggregations

UMSException (com.iplanet.ums.UMSException)48 Guid (com.iplanet.ums.Guid)40 AMException (com.iplanet.am.sdk.AMException)31 PersistentObject (com.iplanet.ums.PersistentObject)24 AttrSet (com.iplanet.services.ldap.AttrSet)16 Attr (com.iplanet.services.ldap.Attr)14 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)11 AccessRightsException (com.iplanet.ums.AccessRightsException)10 DomainComponentTree (com.iplanet.ums.dctree.DomainComponentTree)8 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)6 SearchResults (com.iplanet.ums.SearchResults)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 DN (org.forgerock.opendj.ldap.DN)6 AMEntryExistsException (com.iplanet.am.sdk.AMEntryExistsException)5 AMHashMap (com.iplanet.am.sdk.AMHashMap)5 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)5 EntryAlreadyExistsException (com.iplanet.ums.EntryAlreadyExistsException)5 TreeMap (java.util.TreeMap)5 LdapException (org.forgerock.opendj.ldap.LdapException)5