如何正确使用LDAPPersister

时间:2019-02-14 19:30:23

标签: java active-directory windows-server-2012-r2 unboundid-ldap-sdk

我正在尝试使用LDAPPersister中的getAll()方法来访问指定活动目录组织单位中的对象。

我只找到一个密码example

这是我的代码:

LDAPPersister ldapPersister = LDAPPersister.getInstance(Group.class);
String dn = "ou=Groups,ou=ou2,ou=ou1,dc=dc2,dc=dc1";
SearchResult searchResult = ldapPersister.getAll(ldapConn, dn, groupsObjectSearchListener);
private ObjectSearchListener<Group> groupsObjectSearchListener = new ObjectSearchListener<Group>() {
        @Override
        public void objectReturned(Group group) {
            log.info("objectReturned");
            groups.add(group);
        }

        @Override
        public void unparsableEntryReturned(SearchResultEntry searchResultEntry, LDAPPersistException e) {
            log.info("unparsableEntryReturned");
        }

        @Override
        public void searchReferenceReturned(SearchResultReference searchResultReference) {
            log.info("unparsableEntryReturned");
        }
    };

组类是从schema生成的。

结果是(没有来自提供的侦听器的日志):

LDAPException(resultCode=1 (operations error), diagnosticMessage='00002120: SvcErr: DSID-0312044F, problem 5012 (DIR_ERROR), data 592060
 ', ldapSDKVersion=4.0.9, revision=29290')

我还尝试了另一种获取组对象的方法:

String dn = "ou=Groups,ou=ou2,ou=ou1,dc=dc2,dc=dc1";
Filter filter = Filter.create("(objectClass=Group)");
SearchRequest searchRequest = new SearchRequest(dn, SearchScope.ONE, filter);
SearchResult searchResult = ldapConn.search(searchRequest);
LDAPPersister ldapPersister = LDAPPersister.getInstance(Group.class);
Group group = (Group) ldapPersister.decode(searchResult.getSearchEntries().get(0));

它给出了预期的结果(4组),没有错误-所以dn和连接应该没问题。

无论如何,我将非常感谢任何有效的代码示例或解释我做错了什么。

0 个答案:

没有答案