0

Unboundit の LDAP SDK を使用して、netscape LDAP ディレクトリから名前を持ついくつかの属性を持つオブジェクトを取得しようとしています。問題は、属性の 1 つだけが返されることです。LDAP SDK は一意の属性名に大きく依存していると思いますが、異なる属性も返すように構成する方法はありますか?

@Test
public void testRetrievingUsingListener() throws LDAPException {
    long currentTimeMillis = System.currentTimeMillis();

    LDAPConnection connection = new LDAPConnection("xxx.xxx.xxx", 389,
            "uid=xxx-websrv,ou=xxxx,dc=xxx,dc=no",
            "xxxx");
    SearchRequest searchRequest = new SearchRequest(
            "ou=xxx,ou=xx,dc=xx,dc=xx",
            SearchScope.SUB, "(uid=xxx)", SearchRequest.ALL_USER_ATTRIBUTES );

    LDAPEntrySource entrySource = new LDAPEntrySource(connection,
            searchRequest, true);

    try {
        while (true) {
            try {
                System.out.println("*******************************************");
                Entry entry = entrySource.nextEntry();
                if (entry == null) {
                    // There are no more entries to be read.
                    break;
                } else {
                    Collection<Attribute> attributes = entry.getAttributes();
                    for (Attribute attr : attributes)
                    {
                        System.out.println (attr.getName() + " " + attr.getValue());

                    }
                }
            } catch (SearchResultReferenceEntrySourceException e) {
                // The directory server returned a search result reference.
                SearchResultReference searchReference = e
                        .getSearchReference();
            } catch (EntrySourceException e) {
                // Some kind of problem was encountered (e.g., the
                // connection is no
                // longer valid). See if we can continue reading entries.
                if (!e.mayContinueReading()) {
                    break;
                }
            }
        }
    } finally {
        entrySource.close();
    }

    System.out.println("Finished in "  + (System.currentTimeMillis() - currentTimeMillis));

}
4

1 に答える 1

0

一意でないLDAP属性は複数値と見なされ、String配列として表されます。

Attribute.getValues()の代わりに使用してくださいattribute.getValue

于 2012-09-20T13:08:13.413 に答える