Ads 468x60px

Wednesday, July 25, 2012

Java: Add User in IBM Tivoli Directory Server (TDS) LDAP using JNDI

It will help you to add user or other entries in IBM Tivoli Directory Server (TDS) using JNDI. I used default values and my own user information, so you have to change it according your requirements. Also the user attributes will depend upon your directory server schema. For connection with  IBM Tivoli Directory Server (TDS)/ LDAP visit:

import javax.naming.ldap.InitialLdapContext;

//this class perform all LDAP actions for the user
public class LDAPService {

private String base = "c=us"; // base for LDAP
private String realm = "cn=realm1"; // LDAP realm for user

// User information
private String surname = "Ali"; // user surname
private String givenname = "Usman"; // user given name or first name
private String userpassword = "********"; // user password
private String email = ""; // user email
private String distinguish_name = "sn=" + surname + "," + realm + "," + base;

// to add user in LDAP (TDS)
public void addUser() {
try {
InitialLdapContext context = LDAPConnection.InitializeContext();

Attributes attributes = new BasicAttributes();
Attribute objectClass = new BasicAttribute("objectClass");

// Define User attributes
attributes.put("sn", surname);
attributes.put("givenName", givenname);
attributes.put("userPassword", userpassword);
attributes.put("mail", email);

// call API to add user
context.createSubcontext(distinguish_name, attributes);

// Close LDAP Context

} catch (Exception ex) {

No comments:

Post a Comment