How to find the attributes on an LDAP server using JNDI.
1 posts in topic
Flat View  Flat View

Posted By:   neal_ravindran
Posted On:   Thursday, August 15, 2002 07:35 AM

How can I find the attributes on an LDAP server using JNDI?

I know the LDAP server URL et al and just want to get the LDAP attributes from the server using JNDI. Possible?

(Something similar to getting the database metadeta, column names of tables etc using JDBC )

Re: How to find the attributes on an LDAP server using JNDI.

Posted By:   Nicholas_Whitehead  
Posted On:   Friday, August 16, 2002 08:01 AM


This code will dump all the users in a branch of an LDAP server along with the attributes and their values:

env.put(Context.InitialContextFactory, "com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.SECURITY_AUTHENTICATION, "simple");

env.put(Context.SECURITY_PRINCIPAL, "ou=People, o=JNDITutorial");

env.put(Context.SECURITY_CREDENTIALS, "mysecret");

// Create the initial context

DirContext ctx = new InitialDirContext(env);

Attributes matchAttrs = new BasicAttributes(true); // ignore attribute name case

matchAttrs.put(new BasicAttribute("objectClass", "organizationalPerson"));

NamingEnumeration nenum ="", matchAttrs);

while(nenum.hasMore()) {

SearchResult sr = (SearchResult);

log("Retrieved:" + sr.getName());

Object obj = dc.lookup(sr.getName());

Attributes attrs = sr.getAttributes();

NamingEnumeration attrEnum = attrs.getAll();

while(attrEnum.hasMore()) {

Attribute attr = (Attribute);

log(attr.getID() + ":" + attr.get());




About | Sitemap | Contact