Search in sources :

Example 1 with UMSException

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

the class DirectoryServicesImpl method getGroupFilterAndScope.

// ##########Group and role related APIs
/**
     * Returns an array containing the dynamic group's scope, base dn, and
     * filter.
     */
public String[] getGroupFilterAndScope(SSOToken token, String entryDN, int profileType) throws SSOException, AMException {
    String[] result = new String[3];
    int scope;
    String base;
    String gfilter;
    try {
        DynamicGroup dg = (DynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
        scope = dg.getSearchScope();
        base = dg.getSearchBase().getDn();
        gfilter = dg.getSearchFilter();
        result[0] = Integer.toString(scope);
        result[1] = base;
        result[2] = gfilter;
    } catch (EntryNotFoundException e) {
        debug.error("AMGroupImpl.searchUsers", e);
        String msgid = getEntryNotFoundMsgID(profileType);
        String expectionEntryName = getEntryName(e);
        Object[] args = { expectionEntryName };
        throw new AMException(AMSDKBundle.getString(msgid, args), msgid, args);
    } catch (UMSException e) {
        debug.message("AMGroupImpl.searchUsers", e);
        throw new AMException(AMSDKBundle.getString("341"), "341", e);
    }
    return result;
}
Also used : DynamicGroup(com.iplanet.ums.DynamicGroup) AssignableDynamicGroup(com.iplanet.ums.AssignableDynamicGroup) UMSException(com.iplanet.ums.UMSException) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) AMException(com.iplanet.am.sdk.AMException) Guid(com.iplanet.ums.Guid)

Example 2 with UMSException

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

the class DirectoryServicesImpl method search.

// RENAME from searchUsingSearchControl => search()
/**
     * Search the Directory
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the entry to start the search with
     * @param searchFilter
     *            search filter
     * @param searchControl
     *            search control defining the VLV indexes and search scope
     * @param attrNames
     *            name of attributes
     * @return Set set of matching DNs
     */
public AMSearchResults search(SSOToken token, String entryDN, String searchFilter, SearchControl searchControl, String[] attrNames) throws AMException {
    AMSearchResults amResults = null;
    try {
        SortKey[] skeys = searchControl.getSortKeys();
        SortKey skey = null;
        if (skeys != null && skeys.length > 0 && skeys[0].attributeName != null) {
            skey = skeys[0];
        }
        String userLocale = CommonUtils.getUserLocale(token);
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.search() search with " + "searchcontrol locale = " + userLocale);
        }
        Collator collator = Collator.getInstance(Locale.getLocale(userLocale));
        SearchControl sc;
        if (skey != null) {
            sc = new SearchControl();
            sc.setMaxResults(searchControl.getMaxResults());
            sc.setSearchScope(searchControl.getSearchScope());
            sc.setTimeOut(searchControl.getTimeOut());
        } else {
            sc = searchControl;
        }
        PersistentObject po = UMSObject.getObjectHandle(token, new Guid(entryDN));
        SearchResults results;
        if (attrNames == null) {
            if (skey == null) {
                results = po.search(searchFilter, sc);
            } else {
                String[] tmpAttrNames = { skey.attributeName };
                results = po.search(searchFilter, tmpAttrNames, sc);
            }
        } else {
            if (skey == null) {
                results = po.search(searchFilter, attrNames, sc);
            } else {
                String[] tmpAttrNames = new String[attrNames.length + 1];
                System.arraycopy(attrNames, 0, tmpAttrNames, 0, attrNames.length);
                tmpAttrNames[attrNames.length] = skey.attributeName;
                results = po.search(searchFilter, tmpAttrNames, sc);
            }
        }
        amResults = getSearchResults(results, skey, attrNames, collator, sc.isGetAllReturnAttributesEnabled());
    } catch (UMSException ue) {
        if (debug.warningEnabled()) {
            debug.warning("DirectoryServicesImpl.search() with search " + "control entryDN: " + entryDN + " Search Filter: " + searchFilter + " Error occurred: ", ue);
        }
        processInternalException(token, ue, "341");
    }
    return amResults;
}
Also used : UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) Guid(com.iplanet.ums.Guid) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) Collator(java.text.Collator)

Example 3 with UMSException

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

the class COSManager method updateDefinition.

/**
     * Updates the contents of a COS definition with the new contents. The COS
     * definition must already exist in the persistent layer, before its
     * contents can be replaced.
     * 
     * @param cosDef
     *            The COS definition containing new contents, which will replace
     *            the same definition in the persistent layer.
     * 
     * @throws UMSException
     *             The exception thrown from the data layer.
     * @supported.api
     */
public void updateDefinition(ICOSDefinition cosDef) throws UMSException {
    PersistentObject pObject = (PersistentObject) cosDef;
    if (pObject.getGuid() == null) {
        String msg = i18n.getString(IUMSConstants.REPLACE_DEFINITION_NOT_PERSISTENT);
        throw new UMSException(msg);
    }
    pObject.save();
}
Also used : UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject)

Example 4 with UMSException

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

the class COSManager method addDefinition.

/**
     * This method adds a COS definition to the persistent store. The definition
     * is added under the specified "guid" parameter.
     * 
     * @param cosDef
     *            The COS definition to be added.
     * 
     * @throws UMSException
     *             The exception thrown from the data layer.
     * @supported.api
     */
public void addDefinition(ICOSDefinition cosDef) throws UMSException {
    if (!(cosDef instanceof DirectCOSDefinition)) {
        String msg = i18n.getString(IUMSConstants.INVALID_COSDEFINITION);
        throw new UMSException(msg);
    }
    String[] cosAttributes = cosDef.getCOSAttributes();
    AbstractCollection aList = (AbstractCollection) Arrays.asList(ICOSDefinition.qualifiers);
    for (int i = 0; i < cosAttributes.length; i++) {
        String cosAttribute = null;
        String qualifier = null;
        StringTokenizer st = new StringTokenizer(cosAttributes[i]);
        if (st.hasMoreTokens()) {
            cosAttribute = st.nextToken();
        }
        if (cosAttribute == null) {
            String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
            throw new UMSException(msg);
        }
        if (st.hasMoreTokens())
            qualifier = st.nextToken();
        if (qualifier == null) {
            qualifier = ICOSDefinition.qualifiers[ICOSDefinition.DEFAULT];
            cosDef.removeCOSAttribute(cosAttribute);
            cosDef.addCOSAttribute(cosAttribute, ICOSDefinition.DEFAULT);
        }
        if (!aList.contains(qualifier)) {
            String msg = i18n.getString(IUMSConstants.INVALID_COS_ATTRIBUTE_QUALIFIER);
            throw new UMSException(msg);
        }
    }
    PersistentObject po = (PersistentObject) cosDef;
    _parentObject.addChild(po);
}
Also used : StringTokenizer(java.util.StringTokenizer) UMSException(com.iplanet.ums.UMSException) AbstractCollection(java.util.AbstractCollection) PersistentObject(com.iplanet.ums.PersistentObject)

Example 5 with UMSException

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

the class COSManager method removeDirectCOSAssignment.

/**
     * Removes a Direct COS assignment from a target persistent object. The COS
     * target persistent object could be a user, group, organization,
     * organizationalunit, etc. The COS target object must be persistent before
     * this method can be used.
     * 
     * @param pObject
     *            The COS target persistent object.
     * @param cosDef
     *            A COS definition.
     * @param sMgr
     *            A SchemaManager object, which is used to determine object
     *            classes for attributes.
     * 
     * @throws UMSException
     *             The exception thrown if any of the following occur: o an
     *             exception occurs determining the object class for the COS
     *             specifier. o an exception occurs determining the object class
     *             for the COS attributes. o there is an exception thrown rom
     *             the data layer.
     */
private void removeDirectCOSAssignment(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
    ArrayList aList;
    AttrSet attrSet = new AttrSet();
    try {
        //
        if (pObject.getAttribute(cosDef.getCOSSpecifier()) != null)
            attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
        // Get cosSpecifier object class - should only be one.
        // Include the cosSpecifier object class in the attribute
        // set for removal (only if itt exists).
        //
        aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
        String cosSpecObjectClass = (String) aList.get(0);
        if (objectClassExists(cosSpecObjectClass, pObject)) {
            attrSet.add(new Attr("objectclass", cosSpecObjectClass));
        }
        // Get the cos attributes from the definition (ex. mailquota).
        // For each of the attributes, get the objectclass. Include the
        // object classes in the attribute set for removal (if they exist).
        //
        String[] cosAttributes = cosDef.getCOSAttributes();
        String cosAttribute = null;
        for (int i = 0; i < cosAttributes.length; i++) {
            // Only get the attribute - not the qualifier
            //
            StringTokenizer st = new StringTokenizer(cosAttributes[i]);
            cosAttribute = st.nextToken();
            aList = (ArrayList) sMgr.getObjectClasses(cosAttribute);
            String cosAttributeObjectClass = (String) aList.get(0);
            if (objectClassExists(cosAttributeObjectClass, pObject)) {
                attrSet.add(new Attr("objectclass", cosAttributeObjectClass));
            }
        }
        if (attrSet.size() > 0) {
            pObject.modify(toModifications(ModificationType.DELETE, attrSet));
            pObject.save();
        }
    } catch (UMSException e) {
        LdapException le = (LdapException) e.getRootCause();
        // Ignore anything that is not a COS generated attribute's object class
        if (!ResultCode.OBJECTCLASS_VIOLATION.equals(le.getResult().getResultCode())) {
            throw e;
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) UMSException(com.iplanet.ums.UMSException) ArrayList(java.util.ArrayList) LdapException(org.forgerock.opendj.ldap.LdapException) Attr(com.iplanet.services.ldap.Attr) AttrSet(com.iplanet.services.ldap.AttrSet)

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