Пример #1
0
  private LdapInternalSearch getInternalSearch(Set<String> attrsToGet) {
    // This is a bit tricky. If the LdapFilter has an entry DN,
    // we only need to look at that entry and check whether it matches
    // the native filter. Moreover, when looking at the entry DN
    // we must not throw exceptions if the entry DN does not exist or is
    // not valid -- just as no exceptions are thrown when the native
    // filter doesn't return any values.
    //
    // In the simple case when the LdapFilter has no entryDN, we
    // will just search over our base DNs looking for entries
    // matching the native filter.

    LdapSearchStrategy strategy;
    List<String> dns;
    int searchScope;

    final String filterEntryDN = filter != null ? filter.getEntryDN() : null;
    if (filterEntryDN != null) {
      // Would be good to check that filterEntryDN is under the configured
      // base contexts. However, the adapter is likely to pass entries
      // outside the base contexts, so not checking in order to be on the
      // safe side.
      strategy = new ADDefaultSearchStrategy(true);
      dns = singletonList(filterEntryDN);
      searchScope = SearchControls.OBJECT_SCOPE;
    } else {
      strategy = getSearchStrategy();
      dns = getBaseDNs();
      searchScope = getLdapSearchScope();
    }

    final SearchControls controls = LdapInternalSearch.createDefaultSearchControls();
    final Set<String> ldapAttrsToGet = utils.getLdapAttributesToGet(attrsToGet, oclass);

    controls.setReturningAttributes(ldapAttrsToGet.toArray(new String[ldapAttrsToGet.size()]));
    controls.setSearchScope(searchScope);

    final String optionsFilter = LdapConstants.getSearchFilter(options);

    final String searchFilter =
        oclass.equals(ObjectClass.ACCOUNT)
            ? conn.getConfiguration().getAccountSearchFilter()
            : ((ADConfiguration) conn.getConfiguration()).getGroupSearchFilter();

    final String nativeFilter = filter != null ? filter.getNativeFilter() : null;

    return new LdapInternalSearch(
        conn, getSearchFilter(optionsFilter, nativeFilter, searchFilter), dns, strategy, controls);
  }
Пример #2
0
  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));
          }
        });
  }