0

I am attempting to retrieve objects having several attributes with the name from netscape LDAP directory with LDAP SDK from Unboundit. The problem is that only one of the attributes are returned - I am guessing LDAP SDK relays heavily on unique attribute names, is there a way to configure it to also return non-distinct attributes as well?

@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));

}
ZnArK
  • 1,533
  • 1
  • 12
  • 23
  • found it: String[] values = attr.getValues(); String value=""; for (int i=0;i < values.length; i++) { value +=values[i]; } System.out.println (attr.getName() + " " + value); – Siavash Renani Sep 13 '12 at 13:36

1 Answers1

0

Non-unique LDAP attributes are considered multivalued and are reperesented as String array.

Use Attribute.getValues() instead of attribute.getValue.

rationalboss
  • 5,330
  • 3
  • 30
  • 50