【问题标题】:Can't get connection with AD from Java无法从 Java 获得与 AD 的连接
【发布时间】:2013-09-12 13:49:33
【问题描述】:

我正在尝试从 MS AD 检索一些信息:特定分支的成员、部门名称、职位、etc

我用了很多例子,包括Apache Directory LDAP APIUnboundID,但我无法与AD建立联系。

RDN:

C:\Users\Aleksey> whoami /fqdn
       CN=my common name here,
       OU=my organization unit here,
       OU=organization unit 2 here,
       OU=organization unit 1 here,
       OU=main organization unit here,
       DC=.my domain here,
       DC=domain 2 here,
       DC=main domain here

对于搜索,我使用以下过滤器:

public class LdapRetriever {
    public static void main (String[] args) {
        Hashtable env = new Hashtable();

        env.put(Context.INITIAL_CONTEXT_FACTORY, 
            "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://" + 
            "ip of domain controller here" + ":389");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");
        // Also I try to use the following SECURITY_PRINCIPAL: 
        // my login only, my domain\ my login
        env.put(Context.SECURITY_PRINCIPAL, "my login here" + "@" + 
            "my domain here.domain 2 here.main domain here");
        env.put(Context.SECURITY_CREDENTIALS, "my password here");

        try {           
            DirContext ctx = new InitialLdapContext(env,null);
            String returnedAtts[]={"sn","title","department","givenName"};

            SearchControls searchCtls = new SearchControls();  
            searchCtls.setReturningAttributes(returnedAtts);  
            searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);

            String searchFilter = "(&(objectClass=user)(cn=*))";
            String searchBase = 
                "DC=my domain here,DC=domain 2 here,DC=main domain here";

            NamingEnumeration answer = ctx.search(searchBase, 
                searchFilter, searchCtls);
            ...

当我使用来自env 的数据创建目录上下文时,出现异常:

Exception in thread "main" javax.naming.AuthenticationException: 
[LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment:
AcceptSecurityContext error, data 531, vece

如果没有指定密码,我会得到以下异常:

Problem searching directory: 
javax.naming.NamingException:[LDAP:error code 1 - 00000000: 
LdapErr: DSID-0C090627, comment: 
In order to perform this operation a successful bind must be completed 
on the connection., data 0, vece]; remaining name 
'DC=my domain here,DC=domain 2 here,DC=main domain here'

我已确认我的帐户没有被锁定。

根据the list of common active directory LDAP bind errors

525​  user not found ​
52e​  invalid credentials ​
530​  not permitted to logon at this time​
531​  not permitted to logon at this workstation​
532​  password expired ​
533​  account disabled ​
701​  account expired ​
773​  user must reset password ​
775​  user account locked

就我而言,这意味着:“不允许在此工作站登录”,但我可以使用相同的凭据登录到域。

可能是什么原因?

【问题讨论】:

    标签: java active-directory ldap


    【解决方案1】:

    错误代码 531 很可能与 AD 的配置有关。 在某些情况下,用户只能从一个工作站登录,例如您的工作电脑。
    这是在用户的 userWorkstations 字段中配置的。
    当您无法使用 RDP 登录您的 AD 时,您需要您的 AD 管理员检查您的帐户是否有此字段,以及 AD 服务器是否包含在您的 userWorkstations 中,或者该字段已被完全删除。

    【讨论】:

    • 好消息,与 IBM WebSphere (WAS) v8 有相同的问题,其行为与 v7 不同。
    【解决方案2】:

    我的项目使用 ldap 身份验证。 我已经将您的来源与我的 impl 进行了比较。除了 SECURITY_PRINCIPAL 参数之外,其他都是相同的。

    它对我有用:

    String login = "login";
    String base = "ou=People,dc=example,dc=com";
    String dn = "uid=" + login + "," + base;
    env.put( Context.SECURITY_PRINCIPAL, dn );
    

    【讨论】:

      【解决方案3】:

      Error data 531, implies you can not login from that workstation. Error data 525, implies the entry does not exist.

      您可以通过发出以下命令从 DC 确定用户的 FDN: { dsquery 用户 -samid jim

      "CN=Jim Willeke,CN=Users,DC=mad,DC=willeke,DC=com" }

      我们有一些JNDI Samples 可以与 AD 一起使用(假设您知道正确的参数)

      您可能会发现使用 LDAP 浏览器更容易,并首先使用该浏览器进行身份验证,然后您就知道哪些参数可以工作。我们喜欢Apache Studio

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        • 2022-07-11
        相关资源
        最近更新 更多