2016-12-14 8 views
0

Java APIを使用してTDS LDAPからすべてのユーザーを取得するには、以下のコードを使用しています。しかし、リターン属性にイメージを含めると、クエリは機能しません。私はそれを修正するのを助けてください。私は属性 "をjpegPhoto" が含まれる場合はイメージを含むTDS LDAPからすべてのユーザーを取得する

String returnedAtts[] = {"jpegPhoto","cn","uid","UserAccountStatus"}; 

、私は空の結果を取得しています。

ただし、以下のような属性「jpegPhoto」を指定しないと、すべてのユーザーのデータが必要になります.iすべてのユーザーのイメージも必要です(query(cn = *)はイメージ属性では機能しません)。

String returnedAtts[] = {"uid","cn","UserAccountStatus"}; 



try { 
     // Create the initial directory context 
     DirContext ctx = new InitialLdapContext(env,null); 
     //Create the search controls 
     SearchControls searchCtls = new SearchControls(); 
     //Specify the attributes to return 
     String returnedAtts[]={"jpegPhoto","DateofBirth","DateofJoining","cn","sn","UserAccountStatus","uid"}; 
       //String returnedAtts[]={"DateofBirth","DateofJoining","cn","sn","UserAccountStatus","uid"}; 
     searchCtls.setReturningAttributes(returnedAtts); 
     //Specify the search scope 
     searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); 

       String searchBase = "cn=parleRealm,o=parle"; 

     int totalResults = 0; 
     // Search for objects using the filter 
     NamingEnumeration answer = ctx.search(searchBase, "(&(objectClass=inetOrgPerson)(cn=*))", searchCtls); 

       while (answer.hasMoreElements()) { 

       SearchResult sr = (SearchResult)answer.next(); 
       totalResults++; 

       // Print out some of the attributes, catch the exception if the attributes have no values 
       Attributes attrs = (Attributes) sr.getAttributes(); 
       if (attrs != null) { 
        try { 
         if("Active".equals(attrs.get("UserAccountStatus").get().toString())){ 

         /* 
         ub=new UserBean(); 
         ub.setUid((String)attrs.get("uid").get()); 
         ub.setCn((String)attrs.get("cn").get()); 
         ub.setSn((String)attrs.get("sn").get()); 
         ub.setDateOfBirth((String)attrs.get("DateofBirth").get()); 
         ub.setDateofJoining((String)attrs.get("DateofJoining").get()); 
         list.add(ub);*/ 


         System.out.println(attrs.get("cn").get());  
        } 
        } 
       catch (Exception e) { 
         System.out.println(attrs.get("uid").get()+"is failed to read"); 
        } 
       } 
      } 
+0

コードを投稿するのを忘れました。 –

+0

「うまくいかない」とはどういう意味ですか? – Chris

答えて

0

java apiを使用してTDSのLDAPからすべてのユーザーデータを取得すると、以下のエラーが発生します。

javax.naming.CommunicationException: array index out of bounds [Root exception is com.sun.jndi.ldap.Ber$DecodeException: array index out of bounds]; remaining name 'cn=parleRealm,o=parle' 
javax.naming.CommunicationException: array index out of bounds [Root exception is com.sun.jndi.ldap.Ber$DecodeException: array index out of bounds]; remaining name 'cn=parleRealm,o=parle' at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:2003) 
    at com.sun.jndi.ldap.LdapCtx.searchAux(LdapCtx.java:1847) 
    at com.sun.jndi.ldap.LdapCtx.c_search(LdapCtx.java:1772) 
    at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(ComponentDirContext.java:386) 
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:356) 
    at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(PartialCompositeDirContext.java:339) 
    at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267) 
    at com.parle.Test.getUsers(Test.java:60) 
    at com.parle.Test.main(Test.java:112) 
Caused by: com.sun.jndi.ldap.Ber$DecodeException: array index out of bounds 
    at com.sun.jndi.ldap.BerDecoder.seek(BerDecoder.java:127) 
    at com.sun.jndi.ldap.LdapClient.parseAttribute(LdapClient.java:726) 
    at com.sun.jndi.ldap.LdapClient.getSearchReply(LdapClient.java:660) 
    at com.sun.jndi.ldap.LdapClient.search(LdapClient.java:562) 
    at com.sun.jndi.ldap.LdapCtx.doSearch(LdapCtx.java:1985) 
    ... 8 more 


my code is 

try { 
     // Create the initial directory context 
     DirContext ctx = new InitialLdapContext(env,null); 
     //Create the search controls 
     SearchControls searchCtls = new SearchControls(); 
     //Specify the attributes to return 
     String returnedAtts[]={"jpegPhoto","cn","sn","UserAccountStatus","uid"}; 
       //String returnedAtts[]={"jpegPhoto","DateofBirth","DateofJoining","cn","sn","UserAccountStatus","uid"}; 
     searchCtls.setReturningAttributes(returnedAtts); 
     //Specify the search scope 
     searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE); 

       String searchBase = "cn=parleRealm,o=parle"; 

     int totalResults = 0; 
     // Search for objects using the filter 
     NamingEnumeration answer = ctx.search(searchBase, "(&(objectClass=inetOrgPerson)(cn=r*))", searchCtls); 

       while (answer.hasMoreElements()) { 

       SearchResult sr = (SearchResult)answer.next(); 
       totalResults++; 

       // Print out some of the attributes, catch the exception if the attributes have no values 
       Attributes attrs = (Attributes) sr.getAttributes(); 
       if (attrs != null) { 
        try { 
         if("Active".equals(attrs.get("UserAccountStatus").get().toString())){ 

         /* 
         ub=new UserBean(); 
         ub.setUid((String)attrs.get("uid").get()); 
         ub.setCn((String)attrs.get("cn").get()); 
         ub.setSn((String)attrs.get("sn").get()); 
         ub.setDateOfBirth((String)attrs.get("DateofBirth").get()); 
         ub.setDateofJoining((String)attrs.get("DateofJoining").get()); 
         list.add(ub);*/ 


         System.out.println(attrs.get("jpegPhoto").get() + ">>> cn >> " + attrs.get("cn").get());  
        } 
        } 
       catch (Exception e) { 
         System.out.println(e); 
        // System.out.println(attrs.get("uid").get()+"is failed to read"); 
        } 
       } 
      } 

"jpegPhoto"リターン属性を削除すると、すべてのユーザーデータが取得されています。

関連する問題