java - 从活动目录查询扩展属性

时间:2015-12-18 07:53:04

标签: java active-directory ldap ldap-query

我正在尝试从活动目录中检索信息。它到目前为止工作,除了我无法检索扩展属性。

LDAP搜索过滤器:

String searchFilter = "(&(objectClass=user)(employeeId=*))";
String searchBase = "dc=DOM,dc=TLD";
String returnedAtts[]={"userPrincipalName"}; 
searchCtls.setReturningAttributes(returnedAtts); 

NamingEnumeration<SearchResult> answer = ldapContext.search(searchBase, searchFilter, searchCtls);
while (answer.hasMoreElements()) 
{ 
    SearchResult sr = (SearchResult)answer.next(); 
    Attributes attrs = sr.getAttributes(); 

    System.out.println(attrs.get("userPrincipalName"));
    System.out.println(attrs.get("employeeId"));
}

不幸的是我只能检索默认属性。如何检索扩展属性? 代码有什么问题或忘记了什么吗?扩展属性是否取决于用户权限?

1 个答案:

答案 0 :(得分:1)

最后我通过将属性名称添加到返回属性来解决它:

String returnedAtts[]={"userPrincipalName","department","employeeID","mail"}; 
searchCtls.setReturningAttributes(returnedAtts);