Lotus Java and Domino are integrated through LDAP!

Source: Internet
Author: User
Abstract: LDAP is a standard Lightweight Directory Access Protocol (Lightweight Directory Access Protocol). With LDAP, you can access User Information for user authentication. Dominor5/6 supports standard LDAP v3 Directories Service . This article describes how to use JNDI to access the Domino Directory and describes how to make full use of the existing Domino Directory resources in the organization. The method described in this article also applies to other directories that support LDAP v3 Server .
Why is directory service so important?
With Enterprise Medium Application Program We have to face the increasing number of users Data . These user data is distributed across the enterprise, bringing about a large Management And maintenance problems. To solve this problem, we usually need to build Standard Directory infrastructure in the enterprise. At the same time Implementation During EAI (Enterprise Application Integration), we often encounter the need for single-point login (SSO), and the foundation for successful implementation of SSO is that we have a good directory base.
Currently, Domino-based applications have been implemented in many organizations, for example: Office , Email And approval. Excellent compatibility with various standards Platform , Domino also provides good support for LDAP v3.
So, do organizations that have established Domino infrastructure consider getting more returns from their existing investments? Below, we use two examples to learn how to make full use of these directory resources stored in Domino.
Preparations
1. Learn more about JNDI
JNDI (Java Naming and Directory Interface) is a standard for accessing various naming and directory services in Java. It provides access to naming and directory services through a set of extended APIs: javax. Naming.
Before using JNDI, make sure that you have JNDI. jar and include it in the current classpath. If you do not have JNDI. jar, you can download it from references.
2. Configure the Domino server
Before using the following example, you must start your Domino server (I am using R6) and enable the LDAP service.
Since we do not need to use any special options, we do not need to make any modifications to the Domino LDAP configuration. We only need to confirm that the LDAP service has been loaded (input on the domino console: show tasks to check whether the LDAP service is loaded ). If the LDAP service has not been loaded, you can load it by entering load LDAP on the Domino server console.
Read directory information
The following Code Read the email address of a given user from the directory.
Package net. eservice4you. LDAP;
Import javax. Naming. context;
Import javax. Naming. Directory. initialdircontext;
Import javax. Naming. Directory. dircontext;
Import javax. Naming. Directory. attributes;
Import javax. Naming. namingexception;
Import java. util. hashtable;
Class getattr {
Public static void main (string [] ARGs ){
// Identify service provider to use
// Put the initialization information in a hashtable
Hashtable Env = new hashtable (11 );
Env. Put (context. initial_context_factory,
"Com. Sun. JNDI. LDAP. ldapctxfactory ");
Env. Put (context. provider_url, "LDAP: // localhost: 389/o = bjchp ");
// You need to change localhost Domino The full name or IP address of the server, and change o = to the name of your Domino Organization
Try {
// Create the initial directory Context
Dircontext CTX = new initialdircontext (ENV );
// Ask for all attributes of the object
// You need to change xinxibu to an existing registered user on the service
Attributes attrs = CTX. getattributes ("cn = xinxibu ");
// Find the mail address and print it
System. Out. println ("MAIL:" + attrs. Get ("mail"). Get ());
// Close the context when we're re done
CTX. Close ();
} Catch (namingexception e ){
System. Err. println ("problem getting attribute:" + E );
}
}
}
From the code, we can see the process of reading directory information:
1. Set the service provider and service URI used to hashtable.
2. initialize a dircontext.
3. Use context. getattributes to obtain all attributes of a specified user.
4. Use attrs. Get ("XXX") to obtain the attribute information.
5. Close the context connection.
Note: by default, only some user information can be searched in the Domino LDAP directory. You can view the "Domino Directory \ Domino LDAP Service" section in the domino administrator help and add more attributes to the list.
Verify user identity
The following code verifies the identity of an LDAP user by requesting the LDAP user to log on.
Package net. eservice4you. LDAP;
Import javax. Naming. context;
Import javax. Naming. Directory. initialdircontext;
Import javax. Naming. Directory. dircontext;
Import javax. Naming. namingexception;
Import javax. Naming. authenticationexception;
Import java. util. hashtable;
Class authuser {
Public static void main (string [] ARGs ){
// Identify service provider to use
Hashtable Env = new hashtable (11 );
Env. Put (context. initial_context_factory,
"Com. Sun. JNDI. LDAP. ldapctxfactory ");
Env. Put (context. provider_url, "LDAP: // localhost: 389/o = bjchp ");
// Change localhost to the full name or IP address of the Domino server, and change o = to the name of your Domino organization.
// Authenticate as xinxibu and password "1234"
Env. Put (context. security_authentication, "simple ");
Env. Put (context. security_principal, "cn = xinxibu, O = bjchp ");
Env. Put (context. security_credentials, "1234 ");
Try {
// Create the initial directory Context
Dircontext CTX = new initialdircontext (ENV );
System. Out. println ("authentication OK! ");
CTX. Close ();
} Catch (authenticationexception e ){
// If authenticationexception is caught, verification fails.
System. Err. println ("authentication fail:" + E );
} Catch (namingexception e ){
System. Err. println ("nameing exception:" + E );
}
}
}
We can see that to verify users, we need to do the following:
1. Set the service provider and URL used to hashtable.
2. Set the authentication method, user name, and password (for simple ).
3. initialize a dircontext. If an exception occurs when an authenticationexception is caught, verification fails.
4. Close the context connection.
In addition to the simple method we just used, we can also use Digest-MD5, Kerberos V5, X.509 and other methods to verify. You can view references to learn more.
Summary
If Domino is already used in your organization, consider LDAP if you need application integration!
The method described in this article also applies IBM Directory Server And OpenLDAP and other directory servers. I tested the code under JDK 1.4.1 + Domino 6. You can also use Domino 5, which also works well.
References
** Download Sample Code: jndiexample. Jar
** Access java.sun.com/products/jndito understand the latest situation about jndi. download the jndi api. Take a look at the JNDI Tutorial: java.sun.com/products/jndi/tutorial/index.html.
** For LDAP, you can visit the ldapman RFC page to learn about the ldap rfc. On developer works, you can also find a tutorial on how to build an LDAP Address Book: http://www-900.ibm.com/developer... tutorial/index.html.

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.