0

我正在尝试从我的活动目录 (AD LDS/ADAM) 中获取所有用户的列表但是,我不断收到以下错误:

查找失败:javax.naming.NameNotFoundException:[LDAP:错误代码 32 - 000020 8D:NameErr:DSID-031522C9,问题 2001(NO_OBJECT),数据 0,最佳匹配:'DC=PORTAL,DC=COMPANY,DC=BE '

我的代码:

public static void main(String[] args) {
        try {
            DirContext ctx = new InitialDirContext(Environment.getEnvironment());
            NamingEnumeration enumeration = ctx
                    .list("OU=ACCOUNTS,DC=PORTAL,DC=COMPANY,DC=BE");

            while (enumeration.hasMore()) {
                NameClassPair nc = (NameClassPair) enumeration.next();
                System.out.println(enumeration);
            }

            // Close the context when we're done
            ctx.close();

        } catch (AuthenticationException e) {
            System.out.println("Invalid credentials");
        } catch (NamingException e) {
            System.out.println("Lookup failed: " + e);
        }
    }

编辑:添加了连接细节

public static Hashtable getEnvironment() {
        // Set up the environment for creating the initial context
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.sun.jndi.ldap.LdapCtxFactory");
        env.put(Context.PROVIDER_URL, "ldap://localhost:389/");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");

        env.put(Context.SECURITY_PRINCIPAL,
                "CN=Admin,OU=System Accounts,DC=PORTAL,DC=COMPANY,DC=BE");
        env.put(Context.SECURITY_CREDENTIALS, "Pass123");
        env.put(Context.REFERRAL, "follow");

        return env;
    }
4

1 回答 1

0

让它与这个代码一起工作:

NamingEnumeration enumResult = context.search(
             "DC=PORTAl,DC=COMPANY,DC=BE", "(CN=*)",
             controls);
于 2012-03-14T10:06:23.350 回答