LDAP 不返回所有属性

LDAP not returning all attributes

我正在使用 Ldap 从 AD LDS 检索帐户:

Hashtable props = new Hashtable();
props.put(Context.SECURITY_PRINCIPAL, "cn=adminuser,o=myorg,c=uk");
props.put(Context.SECURITY_CREDENTIALS, "password");
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldaps://myldapserver:636");
InitialLdapContext context = new InitialLdapContext(props, null);

SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setReturningAttributes(null);
    // according to javadoc, null means "return all attributes"

NamingEnumeration<SearchResult> results =
    context.search(userBase, "cn=SOMEUSER", controls);

帐户恢复正常。但并非 SOMEUSER 的所有属性都得到返回。

具体来说,msDS-UserPasswordExpired 属性永远不会恢复。


但是...如果我在 SearchControls 中列出该属性:

controls.setReturningAttributes(new String[] {
    "msDS-UserPasswordExpired", "cn", "mail"
});

然后它 神奇地回来了。

为什么? SearchControl javadoc 在说谎吗?

如何告诉它我 真的 真的 想要 所有 属性?

解决方法是列出我想要返回的每个属性。但这太可怕了,并且会使添加未来的字段非常容易出错。

密码控制属性是操作属性,除非您特别要求,否则不会return编辑。

How do I tell it that I really really want all attributes back?

您将new String[]{"*", "+"}指定为return的属性ID:"*"表示所有非操作属性,"+"表示所有操作属性。但这通常不是一个好主意。您的业​​务 none 有很多运营属性。只问你真正需要的。