com.unboundid.ldap.sdk.LDAPConnection.search()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中com.unboundid.ldap.sdk.LDAPConnection.search()方法的一些代码示例,展示了LDAPConnection.search()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LDAPConnection.search()方法的具体详情如下:
包路径:com.unboundid.ldap.sdk.LDAPConnection
类名称:LDAPConnection
方法名:search

LDAPConnection.search介绍

[英]Processes the provided search request.

Note that if the search does not complete successfully, an LDAPSearchException will be thrown In some cases, one or more search result entries or references may have been returned before the failure response is received. In this case, the LDAPSearchException methods like getEntryCount, getSearchEntries, getReferenceCount, and getSearchReferences may be used to obtain information about those entries and references (although if a search result listener was provided, then it will have been used to make any entries and references available, and they will not be available through the getSearchEntries and getSearchReferences methods).
[中]处理提供的搜索请求。
请注意,如果搜索未成功完成,将抛出LDAPSearchException。在某些情况下,在收到失败响应之前,可能已返回一个或多个搜索结果条目或引用。在本例中,LDAPSearchException方法如getEntryCount、getSearchEntries、getReferenceCount、,和getSearchReferences可用于获取关于这些条目和引用的信息(尽管如果提供了搜索结果侦听器,则它将用于使任何条目和引用可用,并且它们将不会通过getSearchEntries和getSearchReferences方法可用)。

代码示例

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-minimal-edition

throws LDAPSearchException
return search((SearchRequest) searchRequest);

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

throws LDAPSearchException
return search((SearchRequest) searchRequest);

代码示例来源:origin: com.redhat.lightblue.ldap/lightblue-ldap-hystrix

@Override
protected SearchResult run() throws Exception {
  return getConnection().search(searchRequest);
}

代码示例来源:origin: gitblit/fathom

private SearchResult doSearch(LDAPConnection ldapConnection, String base, String filter) {
  try {
    return ldapConnection.search(base, SearchScope.SUB, filter);
  } catch (LDAPSearchException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Problem searching LDAP", e);
    }
    return null;
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap

private SearchResult doSearch(LDAPConnection ldapConnection, String base, String filter) {
  try {
    return ldapConnection.search(base, SearchScope.SUB, filter);
  } catch (LDAPSearchException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Problem searching LDAP", e);
    }
    return null;
  }
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public List<LdapAccount> getAllAccounts() throws LdapSystemException {
  try (LDAPConnection conn = ldapPool.getConnection()) {
    String baseDn = config.getLdapUserBaseDN();
    SearchResult searchResult = conn.search(baseDn, ONE, "(objectClass=inetOrgPerson)");
    return searchResult.getSearchEntries().stream().map(entry -> accountFromEntry(entry)).collect(Collectors.toList());
  } catch (LDAPException e) {
    throw new LdapSystemException(e);
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap

private SearchResult doSearch(LDAPConnection ldapConnection, String base, boolean dereferenceAliases, String filter, List<String> attributes) {
  try {
    SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
    if (dereferenceAliases) {
      searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
    }
    if (attributes != null) {
      searchRequest.setAttributes(attributes);
    }
    return ldapConnection.search(searchRequest);
  } catch (LDAPException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Problem searching LDAP", e);
    }
    return null;
  }
}

代码示例来源:origin: gitblit/fathom

private SearchResult doSearch(LDAPConnection ldapConnection, String base, boolean dereferenceAliases, String filter, List<String> attributes) {
  try {
    SearchRequest searchRequest = new SearchRequest(base, SearchScope.SUB, filter);
    if (dereferenceAliases) {
      searchRequest.setDerefPolicy(DereferencePolicy.SEARCHING);
    }
    if (attributes != null) {
      searchRequest.setAttributes(attributes);
    }
    return ldapConnection.search(searchRequest);
  } catch (LDAPException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Problem searching LDAP", e);
    }
    return null;
  }
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public Set<String> getAllGroupNames() throws LdapSystemException {
  Set<String> result = new HashSet<>();
  try (LDAPConnection conn = ldapPool.getConnection()) {
    String baseDN = config.getLdapGroupsBaseDN();
    log.info("Group base DN: " + baseDN);
    String filter = "(objectClass=" + config.getLdapGroupsObjectClass() + ")";
    SearchResult searchResult = conn.search(baseDN, SUB, filter, GROUP_NAME_ATTR);
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
      String name = entry.getAttributeValue(GROUP_NAME_ATTR);
      result.add(name);
    }
  } catch (LDAPException e) {
    throw new LdapSystemException(e);
  }
  return result;
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

Filter.createEqualityFilter("objectClass", Task.OC_TASK);
final SearchResult result = connection.search(Task.SCHEDULED_TASKS_BASE_DN,
   SearchScope.SUB, filter);

代码示例来源:origin: apiman/apiman

private void getResults(String searchDn, String filter, LdapSearchScope scope,
    final IAsyncResultHandler<List<SearchResultEntry>> result) {
  try {
    SearchScope searchScope = (scope == LdapSearchScope.ONE) ? SearchScope.ONE : SearchScope.SUB;
    List<SearchResultEntry> searchResults = connection.search(searchDn, searchScope, filter).getSearchEntries();
    result.handle(AsyncResultImpl.create(searchResults));
  } catch (LDAPException e) {
    ldapErrorHandler.handle(DefaultExceptionFactory.create(e));
  } catch (Exception e) {
    result.handle(AsyncResultImpl.<List<SearchResultEntry>>create(e));
  }
}

代码示例来源:origin: io.apiman/apiman-gateway-engine-core

private void getResults(String searchDn, String filter, LdapSearchScope scope,
    final IAsyncResultHandler<List<SearchResultEntry>> result) {
  try {
    SearchScope searchScope = (scope == LdapSearchScope.ONE) ? SearchScope.ONE : SearchScope.SUB;
    List<SearchResultEntry> searchResults = connection.search(searchDn, searchScope, filter).getSearchEntries();
    result.handle(AsyncResultImpl.create(searchResults));
  } catch (LDAPException e) {
    ldapErrorHandler.handle(DefaultExceptionFactory.create(e));
  } catch (Exception e) {
    result.handle(AsyncResultImpl.<List<SearchResultEntry>>create(e));
  }
}

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-staticsecurity-ldap

protected SearchResult execute(SearchRequest request, String bindDN, String password) {
  LDAPConnection connection = null;
  try {
    if (allowAllSocketFactory) {
      SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
      connection = new LDAPConnection(sslUtil.createSSLSocketFactory(), serverHost, serverPort);
    } else {
      connection = new LDAPConnection(serverHost, serverPort);
    }
    if (bindDN != null) {
      BindResult auth = connection.bind(bindDN, password);
      if (!auth.getResultCode().isConnectionUsable()) {
        log.error("Connection not usable, result code : " + auth.getResultCode());
      }
    }
    return connection.search(request);
  } catch (LDAPException le) {
    String message = le.getMessage();
    if (!message.startsWith("Unable to bind as user ")) {
      log.error(le.getMessage(), le);
    }
  } catch (GeneralSecurityException gse) {
    log.error(gse.getMessage(), gse);
  } finally {
    if (null != connection) {
      connection.close();
    }
  }
  return null;
}

代码示例来源:origin: hlavki/g-suite-identity-sync

@Override
public Map<String, LdapGroup> getAccountGroups(String accountDN) throws LdapSystemException {
  Map<String, LdapGroup> result = new HashMap<>();
  try (LDAPConnection conn = ldapPool.getConnection()) {
    String baseDN = config.getLdapGroupsBaseDN();
    log.info("Group base DN: " + baseDN);
    Filter filter = Filter.createANDFilter(
        Filter.createEqualityFilter("objectClass", config.getLdapGroupsObjectClass()),
        Filter.createEqualityFilter(config.getLdapGroupsMemberAttr(), accountDN));
    SearchResult searchResult = conn.search(baseDN, SUB, filter,
        GROUP_NAME_ATTR, config.getLdapGroupsMemberAttr(), GROUP_DESC_ATTR);
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
      String dn = entry.getDN();
      String name = entry.getAttributeValue(GROUP_NAME_ATTR);
      String description = entry.getAttributeValue(GROUP_DESC_ATTR);
      Set<String> members = new HashSet<>(Arrays.asList(entry.getAttributeValues(config.getLdapGroupsMemberAttr())));
      result.put(dn, new LdapGroup(name, dn, description, members));
    }
  } catch (LDAPException e) {
    throw new LdapSystemException(e);
  }
  return result;
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

new SearchRequest(dn, SearchScope.BASE, DereferencePolicy.NEVER, 1,
            0, false, filter, attributes);
result = search(searchRequest);

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

try
 searchResult = ldapConnection.search(searchRequest);

代码示例来源:origin: com.nimbusds/infinispan-cachestore-ldap

searchResult = connection.search(searchRequest);

代码示例来源:origin: com.nimbusds/infinispan-ldap-cache-store

searchResult = connection.search(searchRequest);

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

final SearchResult result = conn.search(searchRequest.duplicate());
if (result.getEntryCount() != 1)

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

final SearchResult searchResult = conn.search(searchRequest);
setResponseControls(searchResult);

相关文章

LDAPConnection类方法