使用javax.nameming查询LDAP服务器以获取信息



我正在使用javax.nameming.*库来处理LDAP服务器,只是想知道如何查询LDAP服务器以查看它是否支持特定的控制/扩展,特别是Simple Paged Results control extension?

http://www.ldapguru.info/ldap/the-root-dse.html提供了一些关于如何使用unbounddid Java LDAP库的信息,但我找不到任何地方描述如何使用javax.nameming.*库?

非常感谢!

使用以下方法实现此操作:

private static boolean isSimplePagedResultsControlExtensionSupported(
          final LdapContext ctx, final String connectionUrl) throws NamingException {
        Attribute attribute = null;
    try {
      Attributes attributes = ctx.getAttributes("" /* rootDSE */,
          new String[]{"supportedcontrol"});
      attribute = attributes.get("supportedcontrol");
    } catch (NamingException namingException) {
      logger.warning("Error retrieving supportedControls from rootDSE in LDAP authority ["
          + connectionUrl
          + "] - unable to determine if the Simple Paged Results Control Extension (RFC2696) is supported: "
          + namingException.getMessage());
      return false;
    }
    if (attribute == null) {
      logger.warning("Error retrieving supportedControls from rootDSE in LDAP authority ["
          + connectionUrl
          + "] - unable to determine if the Simple Paged Results Control Extension (RFC2696) is supported");
      return false;
    }
    NamingEnumeration<?> namingEnumeration = attribute.getAll();
    while (namingEnumeration.hasMore()) {
      Object object = namingEnumeration.next();
      if (object instanceof String) {
        final String supportedControlOid = (String)object;
        if (supportedControlOid.equals(SIMPLE_PAGED_RESULTS_CONTROL_EXTENSION_OID)) {
          logger.info("LDAP authority [" 
              + connectionUrl 
              + "] reports that it supports the Simple Paged Results Control Extension (RFC2696)"
              + " - a page size of ["
              + DEFAULT_SIMPLE_PAGED_RESULTS_CONTROL_EXTENSION_PAGE_SIZE
              + "] will be used");
          namingEnumeration.close();
          return true;
        }
      }
    }
    logger.info("LDAP authority [" 
        + connectionUrl 
        + "] reports that it does not support the Simple Paged Results Control Extension (RFC2696)");
    namingEnumeration.close();
    return false;
  }

最新更新