我试图获取LDAP用户内部属性,但无法找到如何获取它们
DirContext ctx = this.getDirContext(); List<Employee> list = new ArrayList<Employee>(); NamingEnumeration<SearchResult> results = null; try { SearchControls controls = new SearchControls(); controls.setSearchScope(SearchControls.SUBTREE_SCOPE); results = ctx.search("","(objectclass=person)",controls); while (results.hasMore()) { SearchResult searchResult = results.next(); Attributes attributes = searchResult.getAttributes(); String fullName = this.getValue(attributes.get("cn")); //so on... } // so on
从LDAP,我也想获取每个员工/个人的内部属性.
默认情况下,它不返回内部属性[ex:createTimestamp]
解决方法
除非您要求,否则您将无法获得任何操作属性.目前你不是要求任何属性,这相当于构造SearchControls,或者之后调用SearchControls.setReturningAttributes(String []),使用参数new String [] {“*”}:这给你所有的非 – 操作属性.
要获取操作属性,请使用参数new String [] {“*”,“”}.