我正在尝试运行:

    Map<String, String> environmentProperties = new HashMap<String, String>();
    environmentProperties.put("java.naming.security.authentication", "simple");
    environmentProperties.put("java.naming.ldap.attributes.binary", "tokenGroups objectSid");

    LdapContextSource contextSource = new LdapContextSource();
    contextSource.setAnonymousReadOnly(false);
    contextSource.setPooled(false);

    contextSource.setUserDn("CN=Administrator,CN=Users,DC=someDomain,DC=com");
    contextSource.setPassword("password");

    contextSource.setUrls(new String[]{"ldap://url.goes.here"});
    contextSource.setBaseEnvironmentProperties(environmentProperties);
    contextSource.setDirObjectFactory(null);
    contextSource.afterPropertiesSet();

    final SearchControls searchControls = new SearchControls();
    searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    ContextExecutor contextExecutor = new ContextExecutor() {
       public Object executeWithContext(DirContext ctx) throws NamingException {
          EventDirContext ectx = (EventDirContext) ctx.lookup("CN=Users,,DC=someDomain,DC=com");
          ectx.addNamingListener("", "(cn=*)", searchControls, new LDAPChangeListener());
          return null;
       }
    };


    LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
    ldapTemplate.setIgnorePartialResultException(true);

    ldapTemplate.executeReadOnly(contextExecutor);

但是,我的听众得到的第一条消息是:



我还运行了这段代码,发现here可以验证我的广告是否支持持久搜索,并且结果为true。
static boolean isPersistentSearchSupported(LdapContext rootContext)
        throws NamingException {
    SearchResult rootDSE;
    NamingEnumeration searchResults;
    Attributes attrs;
    NamingEnumeration attrEnum;
    Attribute attr;
    NamingEnumeration values;
    String value;
    String[] attrNames = { "supportedControl" };
    SearchControls searchControls = new SearchControls();

    searchControls.setCountLimit(0); // 0 means no limit
    searchControls.setReturningAttributes(attrNames);
    searchControls.setSearchScope(SearchControls.OBJECT_SCOPE);

    // search for the rootDSE object
    searchResults = rootContext.search("", "(objectClass=*)",
            searchControls);

    while (searchResults.hasMore()) {
        rootDSE = (SearchResult) searchResults.next();

        attrs = rootDSE.getAttributes();
        attrEnum = attrs.getAll();
        while (attrEnum.hasMore()) {
            attr = (Attribute) attrEnum.next();
            values = attr.getAll();
            while (values.hasMore()) {
                value = (String) values.next();
                if (value.equals("1.2.840.113556.1.4.528"))
                    return true;
            }
        }
    }
    return false;
}

我需要怎么做才能开始从AD获取事件?

最佳答案

根据documentation,作用域不能是Subtree,搜索过滤器必须是(objectClass=*)才能进行持久搜索。

08-28 00:14
查看更多