针对Active Directory的LDAP身份验证有哪些可接受的SECURITY_PRINCIPAL格式?

Fun*_*ung 20 java authentication ldap active-directory

我试图通过LDAP对Active Directory验证用户.以下是我使用的代码片段:

private DirContext bindAsUser(String bindPrincipal, String password) {
    Hashtable<String,String> env = new Hashtable<String,String>();
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, bindPrincipal);
    env.put(Context.PROVIDER_URL, bindUrl);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.REFERRAL, "follow");

    try {
        return new InitialLdapContext(env, null);
    } catch (NamingException e) {
        e.printStackTrace()
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我提供的话,绑定代码有效:

  • 下层登录名,即NetBIOSDomainName\sAMAccountName(例如域\用户名),或
  • userPrincipalName (例如username@abc.com),或
  • distinguishedName (例如CN = username,OU = xxx,DC = abc,DC = com),或
  • objectSid (例如S-1-5-21-3623811015-3361044348-30300820-1013)

因为SECURITY_PRINCIPAL,如果使用sAMAccountName(例如用户名)失败(我猜只有森林中唯一的名称是有效的).

那么接受的模式是SECURITY_PRINCIPAL什么?我搜索了一些类似的问题,但都没有提供官方AD/LDAP文档的参考.或者它是我可以在某处查找的配置?谢谢!

bal*_*ate 12

从[MS-ADTS:Active Directory技术规范],我猜的AD官方文档.

http://msdn.microsoft.com/en-us/library/cc223499.aspx

"5.1.1.1.1简单验证"部分列出了简单验证支持的所有名称格式.