JNDI FAQ

What is JNDI?
What do I need to download to start using JNDI?
What's the relationship between LDAP and JNDI?
When I try to modify an attribute, why do I get a SchemaViolationException?
When I cast an attribute value, why do I get a class cast exception?
How do I set up access control for a number of applications using the same LDAP server?
Is there a connection pooling mechanism in JNDI?
What's the format of an LDAP URL?
Does Sun have a LDIF parser?



What is JNDI?
JNDI is one of the J2EE API's. It provides interfaces for perform various naming and directory operations across different types of services. For more information about naming and directory services, refer to the article on Naming and directory services.
Back to top

What do I need to download to start using JNDI?
Download the standard Java extension package for JNDI. This will include the jndi.jar and providerutil.jar files. If you want to access an LDAP server, you also need to download the LDAP service provider interface. You can download Sun's LDAP SPI.
Back to top

What's the relationship between LDAP and JNDI?
JNDI has classes provided by Sun that will help your application interact with an LDAP server. JNDI applications work similarly to JDBC applications - write applications once and be free to use "drivers" from different vendors. Sun provides the "driver" that will help interact with the LDAP server. Sun also provides "drivers" for other naming services (like CORBA, Netscape). What Sun has not written is a driver to interact with ADSI.
Back to top

When I try to modify an attribute, why do I get a SchemaViolationException?
Two reasons - You are setting the attribute with the wrong data type. For example, an attribute of type 'Distinguished Name' is being assigned an integer value. Second, you are trying to modify the RDN of the entry. Modifying the RDN of a directory entry is equivalent to renaming the entry. Context.rename() should be used for that.
Back to top

When I cast an attribute value, why do I get a class cast exception?
Ensure that the attribute value is being cast according to its syntax. Casting string values to Integer will throw a ClassCastException.
Back to top

How do I set up access control for a number of applications using the same LDAP server?
There are 2 scenarios:
1. All the applications use the same access control.
2. Different applications allow different levels of access to the same user.
In either case, setting the ACL within the server is a very good approach. Only the way you set up the ACL will be different. In the first case, you can specify what operations a user can perform on a particular object. An application accessing the directory can authenticate itself using the user's authentication info. And it can provide access based on the ACL that you have set up. In the second case, you can define a set of special users. Each application connects to the directory as a user from this set of special users. The ACL that you set up on the directory will involve these users.
Information on LDAP security is available in the IBM Redbook, "LDAP Implementation Cookbook". You can download it from www.redbooks.ibm.com

Back to top

Is there a connection pooling mechanism in JNDI?
JNDI does not provide any connection pooling mechanism. You have to build it yourself if you need one. Netscape's Java SDK for LDAP has a connection pooling mechanism. You could see the way it is implemented (its open source) and build a similar one of your own for JNDI.
Back to top

What's the format of an LDAP URL?
RFC 2255 defines the basic structure of the LDAP URL. Its basic definition is:
"ldap://" [host [":" port] ] ["/" [dn ["?" [attributeList] ["?" [scope] ["?" [filterString] ["?" extensions]]]]]
  • host and port specify where the LDAP server is located
  • dn is the LDAP Distinguished Name to search for
  • attributeList is a comma-delimited list of what to retrieve
  • scope is either base, one, or sub [base is the default if unspecified]
  • filterSearch is the search filter
  • extensions is a comma-delimited list of extensions
Back to top

Does Sun have a LDIF parser?
No, as of now Sun does not have a LDIF parser. The only open source LDIF parser currently is from Netscape. The source is available from mozilla.org.
Back to top