Search in sources :

Example 1 with SearchResults

use of com.iplanet.ums.SearchResults 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 2 with SearchResults

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

the class COSManager method getDefinition.

/**
     * Returns COS definition given the name.
     * 
     * @param name Name of the COS definition.
     * @return A COS definition with the specified name.
     * @throws UMSException if exception occurred at the data layer.
     * @throws COSNotFoundException if the COS object is not found.
     * @supported.api
     */
public ICOSDefinition getDefinition(String name) throws UMSException, COSNotFoundException {
    ICOSDefinition cosDef = null;
    SearchResults sr = _parentObject.getChildren(ICOSDefinition.COSSUPERDEF_NAME_SEARCH + name + ")", DEF_ATTRIBUTE_NAMES, null);
    while (sr.hasMoreElements()) {
        cosDef = (ICOSDefinition) sr.next();
        if (cosDef.getName().equals(name)) {
            break;
        } else {
            cosDef = null;
        }
    }
    if (cosDef == null) {
        String msg = i18n.getString(IUMSConstants.COS_DEFINITION_NOT_FOUND);
        throw new COSNotFoundException(msg);
    }
    sr.abandon();
    return cosDef;
}
Also used : SearchResults(com.iplanet.ums.SearchResults)

Example 3 with SearchResults

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

the class DirectCOSDefinition method getCOSTemplates.

/**
     * Returns all templates for this definition.
     * 
     * @return a collection of COS templates
     * 
     * @throws UMSException
     *             The exception thrown from the data layer.
     * @supported.api
     */
public Collection getCOSTemplates() throws UMSException {
    COSTemplate cosTemplate = null;
    Collection cosTemplates = new ArrayList();
    String[] resultAttributes = { "*" };
    SearchResults sr = this.search("(objectclass=costemplate)", resultAttributes, null);
    while (sr.hasMoreElements()) {
        cosTemplate = (COSTemplate) sr.next();
        cosTemplates.add(cosTemplate);
    }
    return cosTemplates;
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) SearchResults(com.iplanet.ums.SearchResults)

Example 4 with SearchResults

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

the class DirectoryServicesImpl method getMembers.

/**
     * Get members for roles, dynamic group or static group
     * 
     * @param token
     *            SSOToken
     * @param entryDN
     *            DN of the role or group
     * @param objectType
     *            objectType of the target object, AMObject.ROLE or
     *            AMObject.GROUP
     * @return Set Member DNs
     */
public Set getMembers(SSOToken token, String entryDN, int objectType) throws AMException {
    try {
        SearchResults results;
        switch(objectType) {
            case AMObject.ROLE:
            case AMObject.MANAGED_ROLE:
                ManagedRole role = (ManagedRole) UMSObject.getObject(token, new Guid(entryDN));
                results = role.getMemberIDs();
                return searchResultsToSet(results);
            case AMObject.FILTERED_ROLE:
                FilteredRole filteredRole = (FilteredRole) UMSObject.getObject(token, new Guid(entryDN));
                results = filteredRole.getMemberIDs();
                return searchResultsToSet(results);
            case AMObject.GROUP:
            case AMObject.STATIC_GROUP:
                StaticGroup group = (StaticGroup) UMSObject.getObject(token, new Guid(entryDN));
                results = group.getMemberIDs();
                return searchResultsToSet(results);
            case AMObject.DYNAMIC_GROUP:
                DynamicGroup dynamicGroup = (DynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
                results = dynamicGroup.getMemberIDs();
                return searchResultsToSet(results);
            case AMObject.ASSIGNABLE_DYNAMIC_GROUP:
                // TODO: See if it works after removing this workaround
                // fake object to get around UMS problem.
                // UMS AssignableDynamicGroup has a class resolver, it is
                // added to resolver list in static block. So I need to
                // construct a dummy AssignableDynamicGroup
                AssignableDynamicGroup adgroup = (AssignableDynamicGroup) UMSObject.getObject(token, new Guid(entryDN));
                results = adgroup.getMemberIDs();
                return searchResultsToSet(results);
            default:
                throw new AMException(token, "114");
        }
    } catch (EntryNotFoundException e) {
        debug.error("DirectoryServicesImpl.getMembers() entryDN " + entryDN + " objectType: " + objectType + " Unable to get members: ", e);
        String msgid = getEntryNotFoundMsgID(objectType);
        String entryName = getEntryName(e);
        Object[] args = { entryName };
        throw new AMException(AMSDKBundle.getString(msgid, args), msgid, args);
    } catch (UMSException e) {
        debug.error("DirectoryServicesImpl.getMembers() entryDN " + entryDN + " objectType: " + objectType + " Unable to get members: ", e);
        LdapException le = (LdapException) e.getRootCause();
        if (le != null) {
            ResultCode resultCode = le.getResult().getResultCode();
            if (ResultCode.SIZE_LIMIT_EXCEEDED.equals(resultCode) || ResultCode.ADMIN_LIMIT_EXCEEDED.equals(resultCode)) {
                throw new AMException(token, "505", e);
            }
        }
        throw new AMException(token, "454", e);
    }
}
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) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) SearchResults(com.iplanet.ums.SearchResults) StaticGroup(com.iplanet.ums.StaticGroup) ManagedRole(com.iplanet.ums.ManagedRole) FilteredRole(com.iplanet.ums.FilteredRole) EntryNotFoundException(com.iplanet.ums.EntryNotFoundException) LdapException(org.forgerock.opendj.ldap.LdapException) AssignableDynamicGroup(com.iplanet.ums.AssignableDynamicGroup) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 5 with SearchResults

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

the class DCTreeServicesImpl method updateCacheAndReturnDomain.

/**
     * This is a private method to update cache
     */
private String updateCacheAndReturnDomain(SSOToken token, String canonOrgDN) throws AMException {
    try {
        DomainComponentTree dcTree = new DomainComponentTree(token, new Guid(DCTREE_START_DN));
        SearchControl scontrol = new SearchControl();
        scontrol.setSearchScope(SearchControl.SCOPE_SUB);
        PersistentObject po = UMSObject.getObject(token, new Guid(DCTREE_START_DN));
        String searchFilter = "(inetDomainBaseDN=" + canonOrgDN + ")";
        if (debug.messageEnabled()) {
            debug.message("DCTree.updateCache-> " + "searchFilter= " + searchFilter);
        }
        SearchResults results = po.search(searchFilter, null);
        int count = 0;
        String domainName = null;
        String canonDomain = null;
        while (results.hasMoreElements()) {
            DomainComponent dcNode = (DomainComponent) results.next();
            count++;
            domainName = dcTree.mapDCToDomainName(dcNode);
            if (debug.messageEnabled()) {
                debug.message("DCTree:updateCache-> " + "domainName= " + domainName);
            }
            Attr isCanonical = dcNode.getAttribute(INET_CANONICAL_DOMAIN);
            if (isCanonical != null) {
                /*
                     * if (AMCacheManager.isCachingEnabled()) {
                     * synchronized(canonicalDomainMap) {
                     * canonicalDomainMap.put(canonOrgDN, domainName); } }
                     */
                canonDomain = domainName;
            }
        /*
                 * if (AMCacheManager.isCachingEnabled()) {
                 * synchronized(domainMap) { domainMap.put(canonOrgDN,
                 * domainName); } }
                 */
        }
        results.abandon();
        if (count == 1) {
            canonDomain = domainName;
        /*
                 * if (AMCacheManager.isCachingEnabled()) {
                 * canonicalDomainMap.put(canonOrgDN, domainName); }
                 */
        }
        if (debug.messageEnabled()) {
            debug.message("DCTree.updateCache-> " + "returning domain= " + canonDomain);
        }
        return canonDomain;
    } catch (UMSException umse) {
        debug.error("DCTree:updateCache: UMSException", umse);
        return null;
    }
}
Also used : DomainComponent(com.iplanet.ums.dctree.DomainComponent) UMSException(com.iplanet.ums.UMSException) PersistentObject(com.iplanet.ums.PersistentObject) DomainComponentTree(com.iplanet.ums.dctree.DomainComponentTree) Guid(com.iplanet.ums.Guid) SearchControl(com.iplanet.ums.SearchControl) SearchResults(com.iplanet.ums.SearchResults) Attr(com.iplanet.services.ldap.Attr)

Aggregations

SearchResults (com.iplanet.ums.SearchResults)13 PersistentObject (com.iplanet.ums.PersistentObject)7 Guid (com.iplanet.ums.Guid)6 UMSException (com.iplanet.ums.UMSException)6 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)5 AMException (com.iplanet.am.sdk.AMException)4 SearchControl (com.iplanet.ums.SearchControl)4 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)3 ArrayList (java.util.ArrayList)3 LdapException (org.forgerock.opendj.ldap.LdapException)3 ResultCode (org.forgerock.opendj.ldap.ResultCode)3 Collection (java.util.Collection)2 AMPreCallBackException (com.iplanet.am.sdk.AMPreCallBackException)1 Attr (com.iplanet.services.ldap.Attr)1 AttrSet (com.iplanet.services.ldap.AttrSet)1 AccessRightsException (com.iplanet.ums.AccessRightsException)1 AssignableDynamicGroup (com.iplanet.ums.AssignableDynamicGroup)1 DynamicGroup (com.iplanet.ums.DynamicGroup)1 FilteredRole (com.iplanet.ums.FilteredRole)1 InvalidSearchFilterException (com.iplanet.ums.InvalidSearchFilterException)1