Reputation: 27
How can I know all my attributes for my active directory ??
I saw example like "ou=People" but I don't know how to access to the name "People" who is specific in my company. I don't have access of LDAP (or I don't know how to) so I don't know what I'm suppose to put.
DirContext ctx = null;
Hashtable<String, Object> env = new Hashtable<String, Object>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://"+serverAddress+":389");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, DOMAIN+username);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
ctx = new InitialDirContext(env);
Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case
matchAttrs.put(new BasicAttribute("mail", "[email protected]"));
Attributes attrs = ctx.getAttributes("");
// Search for objects that have those matching attributes
NamingEnumeration<SearchResult> answer = ctx.search("ou=Users", matchAttrs);
while (answer.hasMore()) {
SearchResult sr = (SearchResult)answer.next();
System.out.println(">>>" + sr.getName());
}
I have the error : Failed to bind to LDAP [LDAP: error code 1 - 000020D6: SvcErr: DSID-03100754, problem 5012 (DIR_ERROR), data 0 remaining name 'ou=Users'
How can I know which name the company use to put after ou=....
Thanks a lot !
Upvotes: 0
Views: 397
Reputation: 10833
You can use a ldap browser to explore the ldap. (I usually use softerra Ldap administrator) All the info you need to connect are within the first lines of your code (address, port and so on... )
Upvotes: 3