【发布时间】:2017-10-24 21:52:33
【问题描述】:
我正在使用 Java 连接到 Active Directory,现在我喜欢使用 DirContext 的 getAttributes 方法来查找所有属性而无需进行搜索。
我找到了这个示例 http://www.java2s.com/Code/Java/JNDI-LDAP/howtoretrieveallattributesofanamedobject.htm,它运行良好 - 但它需要对象的 CN,而此时我没有 CN。
这是我的代码:
Hashtable<String, Object> env = new Hashtable<String, Object>(11);
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://192.168.18.106:389/OU=journaldesigner,DC=dataplan,DC=intern");
env.put(Context.SECURITY_PRINCIPAL, "kfriese@dataplan.intern" );
env.put(Context.SECURITY_CREDENTIALS, "fridolin" );
env.put(Context.SECURITY_AUTHENTICATION, "simple" );
DirContext ctx = new InitialDirContext(env);
Attributes answer = ctx.getAttributes("cn=Klaus Friese");
如果我替换这一行:
Attributes answer = ctx.getAttributes("cn=Klaus Friese");
有了这个
Attributes answer = ctx.getAttributes("sAMAccountName=kfriese");
我收到一个错误:
javax.naming.NameNotFoundException: [LDAP: error code 32 - 0000208D: NameErr: DSID-0310020A, problem 2001 (NO_OBJECT), data 0, best match of:
'OU=JournalDesigner,DC=dataplan,DC=intern'
我现在搜索了一段时间,但没有找到任何相关信息 - 我可以使用 sAMAccountName 获取属性吗?我需要对 CN 执行此操作吗? AD 服务器是 Microsoft Active Directory。
谢谢 克劳斯
【问题讨论】:
标签: java active-directory ldap