JNDI & LDAP

Source: Internet
Author: User
Tags ldap protocol

JNDI (Java Naming and Directory Interface, Java Naming and Directory Interface) is a unified API provided for Java programs to access naming and directory services.

Naming Service, to put it bluntly, provides management of a name-key-value pair, that is, a key-value pair. A key represents the name of a resource, and a value represents the real address of the resource, the naming service allows you to find the corresponding object or resource by a unique name. In this way, the program only needs to know the name of a resource and can access it through JNDI, without the real physical address of the resource. This is a bit like a DNS service. DNS resolves a domain name to an IP address, so that you only need to enter a unique website name (that is, a domain name) in your browser to access the website, you do not need to remember the real IP address of the website.

Directory Service also provides a public resource management service. Directory Service is a special type of database that organizes and stores various public resources according to a certain data structure, such as a tree structure. The difference between such a special database and a traditional relational database is that it optimizes the query, and its data structure allows you to quickly find the desired resources, which guarantees a fast search capability, however, this design also sacrifices the efficiency of other aspects, for example, its update efficiency is much lower.

The key-value pairs managed in the directory service are also named. However, the key-value pairs have hierarchies, such as a tree, that is, a name or a name with a hierarchy, you can locate a subtree, not just an attribute. It can be seen that the directory service extends the concept of the Naming Service to provide a hierarchical information library. A directory service usually has a naming service, but a Naming Service does not have to have a directory service.

Currently, many different vendors provide directory services such as NIS, NDS, Active Directory, or full LDAP directory services, similar to database products of different database vendors, the implementation of these directory service products is different and has different characteristics. However, their front-end access supports the LDAP protocol.

Lightweight Directory Access Protocol (LDAP) was developed as a standard directory protocol in the early 1990s S. It is currently the most popular directory protocol and has nothing to do with the vendor or specific platform. LDAP defines how to access contents in the directory service in a unified manner, such as adding, modifying, and deleting an entry. Each directory service provider provides an interface for accessing the product through the LDAP protocol. In this way, we only need to focus on how to use the LDAP protocol.

JNDI is the API used to access LDAP in Java. developers use JNDI to communicate with the LDAP server, that is, they use JNDI to access LDAP, you do not need to deal with the specific features of the Directory Service. In this way, the two layers of LDAP and JNDI are abstracted to enable the Java program to access the Directory Service to achieve platform independence.

The jndi api is a standard API in j2se and is a common API. JNDI contains five packages: javax. Naming, javax. Naming. Directory, javax. Naming. event, javax. Naming. LDAP, javax. Naming. SPI.

Common JNDI operations include BIND, unbind, lookup, rename, namingenumeration listbindings, and namingenumeration list.

Use JNDI to access the Naming Service or directory service. The procedure is as follows:

1. Create a hashtable that includes defining the properties of the desired JNDI service, the LDAP server IP address and port to be connected;

2. Add any information related to user logon authentication to the hashed list;

3. Create an initial context object. If you access the Naming Service, use the initialcontext class. If you access the directory service, use the initialdircontext class;

4. Use the context object you just obtained to perform the required operations, such as adding new entries or searching entries;

5. Close the context object after completing the operation.


Reprint please indicate the source http://blog.csdn.net/shimiso

Technical Exchange Group: 173711587

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.