JNDI

What is LDAP? LDAP vs JNDI?

LDAP is a protocol that specifies how to access directory services(and not where to). Directory Service is like a database that contains information like database/website/users, etc.



What is Active Directory? Active Directory vs LDAP?

Active Directory is a directory service application/product from Microsoft. LDAP is a protocol to access directory services including AD. Examples of directory service providers are MS AD (hosted

on AWS/Azure/Baremetal, Okta, Sun Java Directory service (now Oracle), etc.


What is JNDI?

Java's API Naming & Directory Services Interface.


What is Naming Service?

A service by which (people friendly) names are associated (or Mapped) with objects. Example of names(associated object) are: Email, ComputerName, WebsiteName(IPAddress), FileName (with FileHandle), LDAP Name (LDAP Entry)

The important thing to note is that the name may have a syntax also called naming convention. E.g Unix File System's syntax is to use "/" as separator. DNS uses "." and is ordered from right to left. LDAP- name order from right to left, deliminated by "," (e.g. cn=Rosanna Lee, o=Sun, c=US), also each component is name-value pair, deliminator by "="

Name could either be a string (common way) or an object implementing Name interface.



What is a Directory Service?

Naming Service with attributes of objects. Thus, the lookup (or search) can be also be done for attributes and not just names. It is bound to an object by storing either an object or a reference to the object.

Context?

In Layman would mean - where to look for an object.

Javadoc. It is a java interface which represents a "naming context*" which contains a set of name-to-object bindings. It provides methods to examine and update these bindings.

*Naming Context: In goggle means a set of association between unique, people-friendly names and objects.

It provides two overloaded methods for lookup. One take parameter as String, second as Name.



What is Initial Context?

This class is the starting context for performing naming operations.



What is difference between SPI & API?

API vs SPI

What does NamingManager does actually? How NamingManager is a layer between API & SPI? How InitialContext is initialized when no parameters is passed?

NamingManager is a concrete class used in javax.naming.InitialContext class. It calls NamingManager to get the actual context.

NamingManager based on properties (combination of Map of properties passed as argument or SystemProperties) creates the Context object. It uses the property: Context.INITIAL_CONTEXT_FACTORY(String value of "java.naming.factory.initial") which corresponds to service provider's class name corresponding to javax.naming.spi.InitialContextFacotory

This, the property Context.INITIAL_CONTEXT_FACTORY should be provided to InitialContext using either the parameter or System Properties or jndi.properties.