0

I'm trying to get a list of all users from my active directory (AD LDS/ADAM) However, I keep getting the following error:

Lookup failed: javax.naming.NameNotFoundException: [LDAP: error code 32 - 000020 8D: NameErr: DSID-031522C9, problem 2001 (NO_OBJECT), data 0, best match of: 'DC=PORTAL,DC=COMPANY,DC=BE'

My code:

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);
        }
    }

EDIT: added connection details

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;
    }
Andreas
  • 2,007
  • 5
  • 26
  • 37
  • does the sub-ordinate `ou=accounts` exist? The search response indicates that the base object was matched as far as `dc=portal, ...`. – Terry Gardner Mar 13 '12 at 10:00
  • yes, it's a subdirectory of 'DC=PORTAL,DC=COMPANY,DC=BE' – Andreas Mar 13 '12 at 10:02
  • 1
    LDAP does not have 'directories' or 'sub-directories', it has 'sub-ordinates'. In any case the search response indicates the search proceeded as fas as `dc=portal`. Does the LDAP client have permission to search sub-ordinates of `dc=portal`? – Terry Gardner Mar 13 '12 at 10:30
  • I'm a bit new to this: how do I check the permission? - Updated original post with connection details – Andreas Mar 13 '12 at 10:44

1 Answers1

0

got it to work with this code:

NamingEnumeration enumResult = context.search(
             "DC=PORTAl,DC=COMPANY,DC=BE", "(CN=*)",
             controls);
Andreas
  • 2,007
  • 5
  • 26
  • 37