Search in sources :

Example 11 with SearchControl

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

the class DirectoryManagerImpl method search2.

public Map search2(String token, String entryDN, String searchFilter, List sortKeys, int startIndex, int beforeCount, int afterCount, String jumpTo, int timeOut, int maxResults, int scope, boolean allAttributes, String[] attrNames) throws AMRemoteException, SSOException, RemoteException {
    // Construct the SortKeys
    initialize();
    SortKey[] keys = null;
    int keysLength = 0;
    if (sortKeys != null && (keysLength = sortKeys.size()) != 0) {
        keys = new SortKey[keysLength];
        for (int i = 0; i < keysLength; i++) {
            String data = (String) sortKeys.get(i);
            keys[i] = new SortKey();
            keys[i].reverse = data.startsWith("true:");
            keys[i].attributeName = data.substring(5);
        }
    }
    // Construct SearchControl
    SearchControl sc = new SearchControl();
    if (keys != null) {
        sc.setSortKeys(keys);
    }
    if (jumpTo == null) {
        sc.setVLVRange(startIndex, beforeCount, afterCount);
    } else {
        sc.setVLVRange(jumpTo, beforeCount, afterCount);
    }
    sc.setTimeOut(timeOut);
    sc.setMaxResults(maxResults);
    sc.setSearchScope(scope);
    sc.setAllReturnAttributes(allAttributes);
    // Perform the search
    try {
        AMSearchResults results = dsServices.search(tm.createSSOToken(token), entryDN, searchFilter, sc, attrNames);
        // Convert results to Map
        Map answer = results.getResultAttributes();
        if (answer == null) {
            answer = new HashMap();
        }
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_COUNT, Integer.toString(results.getTotalResultCount()));
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_RESULTS, results.getSearchResults());
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_CODE, Integer.toString(results.getErrorCode()));
        return (answer);
    } catch (AMException amex) {
        if (debug.messageEnabled()) {
            debug.message("DMI::search(with SearchControl):  entryDN=" + entryDN + "the exception is: " + amex);
        }
        throw convertException(amex);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AMException(com.iplanet.am.sdk.AMException) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 12 with SearchControl

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

the class DirectoryManagerImpl method search3.

public Map search3(String token, String entryDN, String searchFilter, List sortKeys, int startIndex, int beforeCount, int afterCount, String jumpTo, int timeOut, int maxResults, int scope, boolean allAttributes, Set attrNamesSet) throws AMRemoteException, SSOException, RemoteException {
    // Construct the SortKeys
    initialize();
    SortKey[] keys = null;
    int keysLength = 0;
    if (sortKeys != null && (keysLength = sortKeys.size()) != 0) {
        keys = new SortKey[keysLength];
        for (int i = 0; i < keysLength; i++) {
            String data = (String) sortKeys.get(i);
            keys[i] = new SortKey();
            keys[i].reverse = data.startsWith("true:");
            keys[i].attributeName = data.substring(5);
        }
    }
    // Construct SearchControl
    SearchControl sc = new SearchControl();
    if (keys != null) {
        sc.setSortKeys(keys);
    }
    if (jumpTo == null) {
        sc.setVLVRange(startIndex, beforeCount, afterCount);
    } else {
        sc.setVLVRange(jumpTo, beforeCount, afterCount);
    }
    sc.setTimeOut(timeOut);
    sc.setMaxResults(maxResults);
    sc.setSearchScope(scope);
    sc.setAllReturnAttributes(allAttributes);
    String[] attrNames = new String[attrNamesSet.size()];
    attrNames = (String[]) attrNamesSet.toArray(attrNames);
    // Perform the search
    try {
        AMSearchResults results = dsServices.search(tm.createSSOToken(token), entryDN, searchFilter, sc, attrNames);
        // Convert results to Map
        Map answer = results.getResultAttributes();
        if (answer == null) {
            answer = new HashMap();
        }
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_COUNT, Integer.toString(results.getTotalResultCount()));
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_RESULTS, results.getSearchResults());
        answer.put(com.iplanet.am.sdk.remote.RemoteServicesImpl.AMSR_CODE, Integer.toString(results.getErrorCode()));
        return (answer);
    } catch (AMException amex) {
        if (debug.messageEnabled()) {
            debug.message("DMI::search(with SearchControl3): entryDN=" + entryDN + "the exception is: " + amex);
        }
        throw convertException(amex);
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AMException(com.iplanet.am.sdk.AMException) SortKey(com.iplanet.ums.SortKey) SearchControl(com.iplanet.ums.SearchControl) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 13 with SearchControl

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

the class AMObjectImpl method searchObjects.

protected AMSearchResults searchObjects(String namingAttr, String objectClassFilter, String wildcard, AMSearchControl searchControl, String avfilter) throws AMException, SSOException {
    SSOTokenManager.getInstance().validateToken(token);
    StringBuilder filterSB = new StringBuilder();
    filterSB.append("(&").append(constructFilter(namingAttr, objectClassFilter, wildcard));
    if (avfilter != null) {
        filterSB.append(avfilter);
    }
    filterSB.append(")");
    if (debug.messageEnabled()) {
        debug.message("AMObjectImpl.searchObjects(" + namingAttr + ", " + objectClassFilter + ", " + wildcard + ", " + avfilter + "): DN=" + entryDN + ", level " + searchControl.getSearchScope());
        debug.message("AMObjectImpl.searchObjects(): filter: " + filterSB.toString());
    }
    SearchControl sc = searchControl.getSearchControl();
    String[] returnAttrs = searchControl.getReturnAttributes();
    return dsServices.search(token, entryDN, filterSB.toString(), sc, returnAttrs);
}
Also used : SearchControl(com.iplanet.ums.SearchControl)

Example 14 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(AMSearchControl searchControl, String avfilter) 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 filter = "(&" + gfilter + getSearchFilter(AMObject.USER) + avfilter + ")";
    if (debug.messageEnabled()) {
        debug.message("AMGroupImpl.searchUsers: " + filter);
    }
    searchControl.setSearchScope(scope);
    SearchControl sc = searchControl.getSearchControl();
    String[] returnAttrs = searchControl.getReturnAttributes();
    return dsServices.search(super.token, base, filter, sc, returnAttrs);
}
Also used : SearchControl(com.iplanet.ums.SearchControl)

Example 15 with SearchControl

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

the class AMObjectImpl method searchObjects.

protected AMSearchResults searchObjects(int[] objectTypes, String wildcard, Map avPairs, AMSearchControl searchControl) throws AMException, SSOException {
    SSOTokenManager.getInstance().validateToken(token);
    StringBuilder filterSB = new StringBuilder();
    filterSB.append("(&");
    filterSB.append("(|");
    for (int i = 0; i < objectTypes.length; i++) {
        String namingAttr = AMNamingAttrManager.getNamingAttr(objectTypes[i]);
        String objectClassFilter = getSearchFilter(objectTypes[i]);
        filterSB.append(constructFilter(namingAttr, objectClassFilter, wildcard));
    }
    filterSB.append(")");
    if ((avPairs != null) && !avPairs.isEmpty()) {
        filterSB.append(constructFilter(avPairs));
    }
    filterSB.append(")");
    if (debug.messageEnabled()) {
        debug.message("AMObjectImpl.searchObjects(): filter: " + filterSB.toString());
    }
    SearchControl sc = searchControl.getSearchControl();
    String[] returnAttrs = searchControl.getReturnAttributes();
    return dsServices.search(token, entryDN, filterSB.toString(), sc, returnAttrs);
}
Also used : SearchControl(com.iplanet.ums.SearchControl)

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