2012-09-13 2 views
0

Unboundit에서 LDAP SDK가있는 netscape LDAP 디렉토리의 이름으로 여러 속성을 갖는 객체를 검색하려고합니다. 문제는 하나의 속성 만 반환된다는 것입니다. 고유 한 속성 이름에 LDAP SDK 릴레이를 많이 사용한다고 추측합니다. 고유하지 않은 속성도 반환하도록 구성하는 방법이 있습니까?Unboundit LDAP SDK와 함께 고유하지 않은 LDAP 속성 이름

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

} 
+0

발견 : String [] values ​​= attr.getValues ​​(); \t \t \t \t \t \t \t \t \t \t \t \t \t \t 문자열 값 = ""; \t \t \t \t \t \t \t 가 (; 나는 values.length를 <; I = 0 int로 난 ++) \t \t \t \t \t \t \t { \t \t \t \t \t \t \t \t 값 + = 값 [I]; \t \t \t \t \t \t \t \t} \t \t \t \t \t \t에서 System.out.println (attr.getName() + ""+ 값); –

답변

0

고유하지 않은 LDAP 속성은 다중 값으로 간주되며 String 배열로 다시 나타납니다.

attribute.getValue 대신 Attribute.getValues()을 사용하십시오.