0
我正在使用以下代碼從TDS LDAP中使用Java API檢索所有用戶。但是當我在返回屬性中包含圖像時,查詢不起作用。請幫我修復它。從TDS LDAP獲取所有用戶,包括圖像
String returnedAtts[] = {"jpegPhoto","cn","uid","UserAccountStatus"};
當我包含屬性「jpegPhoto」,我得到空的結果。
但沒有像下面這樣的屬性「jpegPhoto」,我正在獲取所有用戶的數據。我還需要所有用戶的圖像,所以查詢(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");
}
}
}
您忘記了開郵政編碼。 –
「不起作用」是什麼意思? – Chris