简体   繁体   English

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

[英]java - query extended properties from active directory

I am trying to retrieve information from an active directory. 我正在尝试从活动目录中检索信息。 It is working so far except I am not able to retrieve extended properties. 到目前为止,它可以正常工作,但是我无法检索扩展属性。

LDAP search filter: 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"));
}

Unfortunately I can retrieve only the default properties. 不幸的是,我只能检索默认属性。 How can I retrieve the extended properties? 如何检索扩展属性? Is there anything wrong with the code or did I forget something? 代码有什么问题还是我忘记了什么? Are the extended properties depending on user permissions? 扩展属性是否取决于用户权限?

finally i solved it by adding the property names to the returning attributes: 最后,我通过将属性名称添加到返回属性中来解决了该问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM