Search in sources :

Example 1 with SearchControl

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

the class AMSearchControl method setAllReturnAttributes.

/**
     * Sets the specified boolean value to the variable. Boolean value is set to
     * true, if all attributes of the entries need to be obtained as part of the
     * search.
     * 
     * NOTE: If this <code>getAllReturnAttributes</code> boolean is set to
     * true as part of <code>AMSearchControl</code>, it overrides any other
     * <code>setReturnAttributes</code> set as part of the
     * <code>AMSearchControl</code>. This is similar to using a wildcard '*'
     * in search.
     * 
     * When the option for getting all attributes is set to true, the search
     * results will return a Map, where the Key is the DN of the search results,
     * and value is another Map of attribute names for keys and Sets for values
     * of those attributes.
     * 
     * @param getAllAttributes
     *            Boolean value set to true as part of the
     *            <code>AMSearchControl</code> to obtain all attributes as
     *            part of the search.
     * 
     * 
     */
public void setAllReturnAttributes(boolean getAllAttributes) {
    SearchControl sc = getSearchControl();
    sc.setAllReturnAttributes(getAllAttributes);
    getAllAttributesEnabled = getAllAttributes;
}
Also used : SearchControl(com.iplanet.ums.SearchControl)

Example 2 with SearchControl

use of com.iplanet.ums.SearchControl 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 SearchControl

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

the class AMRoleImpl method searchUsers.

/**
     * Searches for users in this role using wildcards and attribute values.
     * Wildcards can be specified such as a*, *, *a. To further refine the
     * search, attribute-value pairs can be specifed so that DNs of users with
     * matching attribute-value pairs will be returned.
     * 
     * @param wildcard
     *            wildcard pattern to be used in the search
     * @param avPairs
     *            attribute-value pairs to match when searching users
     * @param searchControl
     *            specifies the search scope to be used, VLV ranges etc.,
     * 
     * @return AMSearchResults which contains a Set DNs of Users matching the
     *         search
     * 
     * @throws AMException
     *             if there is an internal error in the AM Store
     * @throws SSOException
     *             if the sign on is no longer valid
     */
public AMSearchResults searchUsers(String wildcard, Map avPairs, AMSearchControl searchControl) throws AMException, SSOException {
    int level = searchControl.getSearchScope();
    if ((level != AMConstants.SCOPE_ONE) && (level != AMConstants.SCOPE_SUB))
        throw new AMException(AMSDKBundle.getString("123", super.locale), "123");
    if ((wildcard == null) || (wildcard.length() == 0))
        throw new AMException(AMSDKBundle.getString("122", super.locale), "122");
    String userFilter = "(&(" + AMNamingAttrManager.getNamingAttr(USER) + "=" + wildcard + ")" + getSearchFilter(AMObject.USER) + "(" + roleDNsAN + "=" + super.entryDN + "))";
    String filter = null;
    if (avPairs == null) {
        filter = userFilter;
    } else {
        if (avPairs.isEmpty()) {
            filter = userFilter;
        } else {
            StringBuilder filterSB = new StringBuilder();
            filterSB.append("(&").append(userFilter).append("(|");
            Iterator iter = avPairs.keySet().iterator();
            while (iter.hasNext()) {
                String attributeName = (String) (iter.next());
                Iterator iter2 = ((Set) (avPairs.get(attributeName))).iterator();
                while (iter2.hasNext()) {
                    String attributeValue = (String) iter2.next();
                    filterSB.append("(").append(attributeName).append("=").append(attributeValue).append(")");
                }
            }
            filterSB.append("))");
            filter = filterSB.toString();
        }
    }
    SearchControl sc = searchControl.getSearchControl();
    String[] returnAttrs = searchControl.getReturnAttributes();
    return dsServices.search(super.token, getOrganizationDN(), filter, sc, returnAttrs);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) SearchControl(com.iplanet.ums.SearchControl)

Example 4 with SearchControl

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

the class AMGroupImpl method searchUsers.

/**
     * Searches for users in this group using wildcards. Wildcards can be
     * specified such as a*, *, *a.
     * 
     * @param wildcard
     *            wildcard pattern to be used in the search
     * @param avPairs
     *            attribute-value pairs to match when searching users
     * @param searchControl
     *            specifies the size limit and time limit
     * 
     * @return AMSearchResults which contains a Set DNs of Users matching the
     *         search
     * 
     * @throws AMException
     *             if there is an internal error in the AM Store
     * @throws SSOException
     *             if the sign on is no longer valid
     */
public AMSearchResults searchUsers(String wildcard, Map avPairs, AMSearchControl searchControl) throws AMException, SSOException {
    int scope;
    String base;
    String gfilter;
    if (profileType == DYNAMIC_GROUP || profileType == ASSIGNABLE_DYNAMIC_GROUP) {
        String[] array = dsServices.getGroupFilterAndScope(token, entryDN, profileType);
        scope = Integer.parseInt(array[0]);
        base = array[1];
        gfilter = array[2];
    } else {
        scope = AMConstants.SCOPE_SUB;
        base = getOrganizationDN();
        gfilter = "(iplanet-am-static-group-dn=" + entryDN + ")";
    }
    String userFilter = "(&" + gfilter + "(" + AMNamingAttrManager.getNamingAttr(USER) + "=" + wildcard + ")" + getSearchFilter(AMObject.USER) + ")";
    String filter = null;
    if (avPairs == null) {
        filter = userFilter;
    } else {
        if (avPairs.isEmpty()) {
            filter = userFilter;
        } else {
            StringBuilder filterSB = new StringBuilder();
            filterSB.append("(&").append(userFilter).append("(|");
            Iterator iter = avPairs.keySet().iterator();
            while (iter.hasNext()) {
                String attributeName = (String) (iter.next());
                Iterator iter2 = ((Set) (avPairs.get(attributeName))).iterator();
                while (iter2.hasNext()) {
                    String attributeValue = (String) iter2.next();
                    filterSB.append("(").append(attributeName).append("=").append(attributeValue).append(")");
                }
            }
            filterSB.append("))");
            filter = filterSB.toString();
        }
    }
    searchControl.setSearchScope(scope);
    SearchControl sc = searchControl.getSearchControl();
    String[] returnAttrs = searchControl.getReturnAttributes();
    return dsServices.search(super.token, base, filter, sc, returnAttrs);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator) SearchControl(com.iplanet.ums.SearchControl)

Example 5 with SearchControl

use of com.iplanet.ums.SearchControl 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

SearchControl (com.iplanet.ums.SearchControl)16 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)5 AMException (com.iplanet.am.sdk.AMException)4 Guid (com.iplanet.ums.Guid)4 PersistentObject (com.iplanet.ums.PersistentObject)4 SearchResults (com.iplanet.ums.SearchResults)4 UMSException (com.iplanet.ums.UMSException)4 Set (java.util.Set)4 SortKey (com.iplanet.ums.SortKey)3 HashSet (java.util.HashSet)3 Iterator (java.util.Iterator)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)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 EntryNotFoundException (com.iplanet.ums.EntryNotFoundException)1