private List<String> getBaseDNs() {
   List<String> result;
   QualifiedUid container = options.getContainer();
   if (container != null) {
     result =
         singletonList(
             LdapSearches.findEntryDN(conn, container.getObjectClass(), container.getUid()));
   } else {
     result = Arrays.asList(baseDNs);
   }
   assert result != null;
   return result;
 }
  public final void executeADQuery(final ResultsHandler handler) {
    final String[] attrsToGetOption = options.getAttributesToGet();
    final Set<String> attrsToGet = utils.getAttributesToGet(attrsToGetOption, oclass);

    final LdapInternalSearch search = getInternalSearch(attrsToGet);

    search.execute(
        new SearchResultsHandler() {

          @Override
          public boolean handle(String baseDN, SearchResult result) throws NamingException {
            return handler.handle(
                utils.createConnectorObject(
                    result.getNameInNamespace(), result, attrsToGet, oclass));
          }
        });
  }
  private int getLdapSearchScope() {
    String scope = options.getScope();

    if (scope == null) {
      if (oclass.is(ObjectClass.ACCOUNT_NAME)) {
        scope = ((ADConfiguration) conn.getConfiguration()).getUserSearchScope();
      } else {
        scope = ((ADConfiguration) conn.getConfiguration()).getGroupSearchScope();
      }
    }

    if (OperationOptions.SCOPE_OBJECT.equals(scope)) {
      return SearchControls.OBJECT_SCOPE;
    } else if (OperationOptions.SCOPE_ONE_LEVEL.equals(scope)) {
      return SearchControls.ONELEVEL_SCOPE;
    } else if (OperationOptions.SCOPE_SUBTREE.equals(scope) || scope == null) {
      return SearchControls.SUBTREE_SCOPE;
    } else {
      throw new IllegalArgumentException("Invalid search scope " + scope);
    }
  }
 public static String getSearchFilter(OperationOptions options) {
   return (String) options.getOptions().get(SEARCH_FILTER_NAME);
 }
 public static String[] getLdapUidAttributes(OperationOptions options) {
   return (String[]) options.getOptions().get(LDAP_UID_ATTRS_NAME);
 }
  public void executeQuery(
      ObjectClass objectClass, Filter query, ResultsHandler handler, OperationOptions options) {

    SortKey[] sortKeys = options.getSortKeys();
    if (null == sortKeys) {
      sortKeys = new SortKey[] {new SortKey(Name.NAME, true)};
    }

    // Rebuild the full result set.
    TreeSet<ConnectorObject> resultSet =
        new TreeSet<ConnectorObject>(new ResourceComparator(sortKeys));

    if (null != query) {
      for (ConnectorObject co : collection.values()) {
        if (query.accept(co)) {
          resultSet.add(co);
        }
      }
    } else {
      resultSet.addAll(collection.values());
    }

    // Handle the results
    if (null != options.getPageSize()) {
      // Paged Search
      final String pagedResultsCookie = options.getPagedResultsCookie();
      String currentPagedResultsCookie = options.getPagedResultsCookie();
      final Integer pagedResultsOffset =
          null != options.getPagedResultsOffset()
              ? Math.max(0, options.getPagedResultsOffset())
              : 0;
      final Integer pageSize = options.getPageSize();

      int index = 0;
      int pageStartIndex = null == pagedResultsCookie ? 0 : -1;
      int handled = 0;

      for (ConnectorObject entry : resultSet) {
        if (pageStartIndex < 0 && pagedResultsCookie.equals(entry.getName().getNameValue())) {
          pageStartIndex = index + 1;
        }

        if (pageStartIndex < 0 || index < pageStartIndex) {
          index++;
          continue;
        }

        if (handled >= pageSize) {
          break;
        }

        if (index >= pagedResultsOffset + pageStartIndex) {
          if (handler.handle(entry)) {
            handled++;
            currentPagedResultsCookie = entry.getName().getNameValue();
          } else {
            break;
          }
        }
        index++;
      }

      if (index == resultSet.size()) {
        currentPagedResultsCookie = null;
      }

      if (handler instanceof SearchResultsHandler) {
        ((SearchResultsHandler) handler)
            .handleResult(new SearchResult(currentPagedResultsCookie, resultSet.size() - index));
      }
    } else {
      // Normal Search
      for (ConnectorObject entry : resultSet) {
        if (!handler.handle(entry)) {
          break;
        }
      }
      if (handler instanceof SearchResultsHandler) {
        ((SearchResultsHandler) handler).handleResult(new SearchResult());
      }
    }
  }