Friday, April 25, 2008

Importing Connector XML more than once

Sometimes there is a need to duplicate a resource object, IT Resource, Process Definitions, Forms, Adapters etc. So, the easiest way to do this to reimport the out of the box connector xml or export the connector xml from your environment if you have customizations on the connector. The following example lists the minimal changes that need to be done in order for this xml to be reimported successfully. I am using Unix SSH Connector to demonstrate what changes need to be done.

Firstly, backup your OIM database. Even if you are on a VMWare, remember, Database export is always good.

Next, get a free tool like "xml notepad" from Microsoft or any other xml editor tool.

Open the xml with the editor and do the following:

1. Replace All the "SSH User" to "Linux02" (or choose whatever name you want).

2. Go to the Form Name node and replace it from "UD_SSH" to "UD_L02".

3. Delete objectDataDefinition node.

4. Just import and its all done.

5. Occasionally, if the import fails, do a reimport again. Delete the nodes from the selections in deployment manager which are already in the OIM from the first import (They come with a big X mark on the side).

Wednesday, April 16, 2008

OAM ObSSOCookie Logoff JavaScript Code

You may use the following code to Delete ObSSOCookie (or any other) cookie to logoff from OAM.

<script type="text/javascript">
// this deletes the cookie when called

function LogoffOAM(){
Logoff('ObSSOCookie', '/', '');
}

function Logoff( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";

javascript:Confirm();

}
function Get_Cookie( name ) {

var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}


function closeWindow(win) {


win.open('','_parent','');

win.close();


}


function Confirm ()
{

window.location = "http://www.bhatiacorp.com";

}

function logoffRedirect ()
{
alert(" You are logged off.\n\n You will be redirected to Corporate Web Site.");
window.location = "http://www.bhatiacorp.com";
}



</script>

Friday, April 11, 2008

DistributionListUtils

package com.bhatiacorp.utils;

import java.security.Provider;
import java.security.Security;
import java.util.Hashtable;
import java.util.Vector;

import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

import Thor.API.tcResultSet;
import Thor.API.tcUtilityFactory;
import Thor.API.Operations.tcLookupOperationsIntf;

import com.thortech.util.logging.Logger;
import com.thortech.xl.dataaccess.tcDataProvider;

public class DistributionListUtils {

private String loggerTag;
private Logger logger;
private String CLASS_NAME;
public static double DISTRIBUTION_GROUP_GLOBAL = 2D;
public static double SECURITY_GROUP_GLOBAL = -2147483646D;
private String mLdapHost;
private String mLdapPort;
private String mAdminID;
private String mAdminPassword;
private boolean mUseSSL;
private String mLdapDistributionListLocation;
private String mRootContext;
private tcLookupOperationsIntf lookIntf;
private static String lookupCodeKeyCol = "Lookup Definition.Lookup Code Information.Code Key";
private static String lookupDecodeKeyCol = "Lookup Definition.Lookup Code Information.Decode";

public DistributionListUtils(String pLdapHost, String pLdapPort,
String pAdminID, String pAdminPassword, String pUseSSL,
String pLdapDistributionLocation, String pRootContext) {
loggerTag = "XL_INTG.BHATIACORP_UTILS";
logger = Logger.getLogger(loggerTag);
CLASS_NAME = getClass().getName();

mLdapHost = pLdapHost;
mLdapPort = pLdapPort;
mAdminID = pAdminID;
mAdminPassword = pAdminPassword;
mUseSSL = (pUseSSL.equalsIgnoreCase("true")) ? true : false;
mLdapDistributionListLocation = pLdapDistributionLocation;
mRootContext = pRootContext;
if (mUseSSL) {
Provider provider = Security.getProvider("com.sun.net.ssl.internal.ssl.Provider");
try {
if (provider == null) {
Class class1 = Class.forName("com.sun.net.ssl.internal.ssl.Provider");
Provider provider1 = (Provider) class1.newInstance();
Security.addProvider(provider1);
}
} catch (ClassNotFoundException classnotfoundexception) {
logger.error("DistributionListUtils -> Exception while setting provide for ssl. Could not find class com.sun.net.ssl.internal.ssl.Provider.\n"
+ classnotfoundexception.getMessage());
} catch (IllegalAccessException illegalaccessexception) {
logger.error("DistributionListUtils -> Exception while setting provide for ssl. IllegalAccessException: "
+ illegalaccessexception.getMessage());
} catch (InstantiationException instantiationexception) {
logger.error("DistributionListUtils -> Exception while setting provide for ssl. InstantiationException: "
+ instantiationexception.getMessage());
}
}

}

private DirContext getDirContext(String pLdapHost, String pLdapPort,
String pAdminID, String pAdminPassword,
boolean pUseSSL) {
DirContext ctx = null;
String providerurl = pLdapHost + ":" + pLdapPort;
if (pLdapPort == "") {
pLdapPort = "636";
}
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, providerurl);
if (pUseSSL == true) {
env.put(Context.SECURITY_PROTOCOL, "ssl");
}
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, pAdminID);
env.put(Context.SECURITY_CREDENTIALS, pAdminPassword);

ctx = new InitialDirContext(env);
} catch (Exception ex) {
ex.printStackTrace();
}
return ctx;
}

private DirContext getDirContext() {
DirContext ctx = null;
try {
if (mUseSSL = true) {
ctx = getDirContext("ldaps://" + mLdapHost, mLdapPort,
mAdminID, mAdminPassword, true);
} else {
ctx = getDirContext("ldap://" + mLdapHost, mLdapPort, mAdminID,
mAdminPassword, false);
}
} catch (Exception ex) {
ex.printStackTrace();
}
return ctx;
}

/**
* Close the directory context of the LDAP server.
*
*/
protected void closeContext(DirContext ctx) {
try {
if (ctx != null) {
ctx.close();
}
} catch (NamingException e) {
logger.warn("DirContext.close failed", e);
}
}

public String assignDistributionList(String pDepartmentID, String pUserId,
String pCompany) throws Exception {

String rtnval = "EXECUTION_SUCCESS";
String tempDepartmentID = new String(pDepartmentID);
if (this.isEmptyString(pDepartmentID)) {
tempDepartmentID = (pCompany.equalsIgnoreCase("BHATIACORP"))
? new String("0000")
: new String("0000-CON");
}

String groupName = "CN="+ tempDepartmentID;
String groupDN = groupName + "," + this.mLdapDistributionListLocation;

//check if group Exists.
Vector groupSearchResult = this.search("(&(objectclass=group)("+groupName+"))");
if(groupSearchResult.isEmpty()){
createGroup(groupDN, pCompany);
}

Vector memberList = getSepcifiedGroupAttributeValue(groupName, "member");
if(memberList == null)
memberList = new Vector();
for(int i = 0; i < memberList.size(); i++){
String member = (String)memberList.elementAt(i);
member = member.toUpperCase();
memberList.setElementAt(member, i);
}

String userDN = getUserDN(pUserId);
if(!memberList.contains(userDN)){
addUserToGroup(userDN, groupDN);
}

return rtnval;
}


public boolean addUserToGroup(String userDN, String groupDN) throws Exception{
DirContext dirCtx = null;
try{
BasicAttributes basicattributes = new BasicAttributes(true);
basicattributes.put(new BasicAttribute("member", userDN));
dirCtx = getDirContext();
dirCtx.modifyAttributes(groupDN,dirCtx.ADD_ATTRIBUTE, basicattributes);
return true;
}catch(Exception exp){
throw exp;
}finally{
this.closeContext(dirCtx);
}
}



public boolean removeUserToGroup(String userDN, String groupDN) throws Exception{
DirContext dirCtx = null;
try{
BasicAttributes basicattributes = new BasicAttributes(true);
basicattributes.put(new BasicAttribute("member", userDN));
dirCtx = getDirContext();
dirCtx.modifyAttributes(groupDN,dirCtx.REMOVE_ATTRIBUTE, basicattributes);
return true;
}catch(Exception exp){
throw exp;
}finally{
this.closeContext(dirCtx);
}
}

public boolean createGroup(String pGroupName, String companyName) throws Exception{
try{
String defaultGroupMemberShip = null;
double groupType = 0D;
String groupName = new String(pGroupName);
if(companyName.equalsIgnoreCase("BHATIACORP")){
defaultGroupMemberShip = "CN=ALL-BCORP-STAFF" +"," + this.mLdapDistributionListLocation;
groupType = DistributionListUtils.SECURITY_GROUP_GLOBAL;
}else{
defaultGroupMemberShip = "CN=ALL-NON-BCORP-STAFF" +"," + this.mLdapDistributionListLocation;
groupName = groupName.concat("-CON");
groupType = DistributionListUtils.DISTRIBUTION_GROUP_GLOBAL;
}
Double groupTypeDouble = new Double(groupType);
String groupTypeDoubleStr = Integer.toString(groupTypeDouble.intValue());
return createGroup(pGroupName, groupTypeDoubleStr, defaultGroupMemberShip );
}catch(Exception exp){
throw exp;
}
}

public boolean createGroup(String groupName, String groupType, String defaultGroupMembership) throws Exception{
DirContext dirCtx = null;
try{
dirCtx = getDirContext();
BasicAttributes basicattributes = new BasicAttributes(true);
basicattributes.put(new BasicAttribute("objectclass", "group"));
basicattributes.put(new BasicAttribute("cn", groupName));
basicattributes.put(new BasicAttribute("sAMAccountName", groupName));
basicattributes.put(new BasicAttribute("groupType", groupType));
basicattributes.put(new BasicAttribute("memberOf", defaultGroupMembership));
dirCtx.createSubcontext(groupName, basicattributes);
return true;
}catch(Exception exp){
throw exp;
}finally{
this.closeContext(dirCtx);
}
}

private String getUserDN(String pUserId) throws Exception{
DirContext dirCtx = null;
try{
String userId = "CN="+ pUserId;
dirCtx = getDirContext();
Vector searchResults = search("("+userId+ ")");
if(searchResults.isEmpty())return null;
String userDNValue = (String)searchResults.get(0);
String userDN = userDNValue + "," + this.mRootContext;
return new String(userDN.toUpperCase());
}catch(Exception exp){
throw exp;
}finally{
this.closeContext(dirCtx);
}
}


public Vector getSepcifiedGroupAttributeValue(String groupName, String lookfor) throws Exception{
DirContext dirCtx = getDirContext();
try{
String[] attributes = {lookfor};
Vector searchResults = search("("+groupName+ ")", attributes);
SearchResult searchResult = (SearchResult)searchResults.get(0);
Attributes searchResultAttributes = searchResult.getAttributes();
Attribute attr = searchResultAttributes.get(lookfor);
Vector attrVector = new Vector(attr.size());
for(int i=0; i< attr.size(); i++){
String value = new String(attr.get(i).toString());
attrVector.add(value.toUpperCase());
}
closeContext(dirCtx);
return attrVector;
}catch(Exception exp){
throw exp;
}finally{
this.closeContext(dirCtx);
}
}

public Vector search(String filter) throws Exception{
DirContext ctx = null;
try{
ctx = getDirContext();
SearchControls searchcontrols = new SearchControls();
searchcontrols.setSearchScope(2);
SearchResult searchresult;
NamingEnumeration namingenumeration = ctx.search(this.mRootContext, filter, searchcontrols);
Vector vector = new Vector();
for(;namingenumeration.hasMoreElements();vector.addElement(searchresult.getName())){
searchresult = (SearchResult)namingenumeration.nextElement();
searchresult.setRelative(false);
}
return vector;
}catch(Exception exception){
logger.error("Error during search : " + exception);
}finally{
closeContext(ctx);
}
return null;
}

public Vector search(String filter, String[] retAttr) throws Exception{
DirContext ctx = null;
try{
ctx = getDirContext();
SearchControls searchcontrols = new SearchControls();
searchcontrols.setSearchScope(2);
if(retAttr != null)
searchcontrols.setReturningAttributes(retAttr);
SearchResult searchresult;
NamingEnumeration namingenumeration = ctx.search(this.mRootContext, filter, searchcontrols);
Vector vector = new Vector();
for(;namingenumeration.hasMoreElements();vector.addElement(searchresult)){
searchresult = (SearchResult)namingenumeration.nextElement();
searchresult.setRelative(false);
}
return vector;
}catch(Exception exception){
logger.error("Error during search : " + exception);
}finally{
closeContext(ctx);
}
return null;
}

public String getLookupCodeValue(String lookupName, String valueToLookFor, tcDataProvider tcdataprovider)
throws Exception{
lookIntf = (tcLookupOperationsIntf)tcUtilityFactory.getUtility(tcdataprovider, "Thor.API.Operations.tcLookupOperationsIntf");
tcResultSet tcresultset = lookIntf.getLookupValues(lookupName);
int i = tcresultset.getRowCount();
for(int j = 0; j < i; j++){
tcresultset.goToRow(j);
if(valueToLookFor.equalsIgnoreCase(tcresultset.getStringValue(lookupDecodeKeyCol)))
return tcresultset.getStringValue(lookupCodeKeyCol);
}
return "";
}

/**
* Return true if the given string is empty.
*/
public final boolean isEmptyString(String toCheck) {
if ((toCheck != null) && (toCheck.trim().length() > 0)) {
return false;
}
return true;
}

/**
* Return true if the given object is null.
*/
public final boolean isNull(Object toCheck) {
return (toCheck == null);
}

}//end of class DistributionListUtils


courtesy:Rajesh Mittal

RandomPasswordGenerator

package com.bhatiacorp.utils;

import java.util.Random;

public class RandomPasswordGenerator {

public static int DEFAULT_PASSWORD_LENGTH=8;
public static char[] Special_Character = {'!','@','#','$','%','^','&','*','(',')' };
public static char getSpecialCharacter(){
Random rand = new Random();
int randInt = rand.nextInt(10);
return Special_Character[randInt];
}

public static String getPassword(int n) {
if(n <=8 ){
n=DEFAULT_PASSWORD_LENGTH;
}
char[] pw = new char[n];
int c = 'A';
int r1 = 0;
int i=0;
String tempString = new String();
while(i< n){
r1 = (int)(Math.random() * 4);
l1: switch(r1) {
case 0: c = '0' + (int)(Math.random() * 10); break l1;
case 1: c = 'a' + (int)(Math.random() * 26); break l1;
case 2: c = 'A' + (int)(Math.random() * 26); break l1;
case 3: c = getSpecialCharacter(); break;
}

char c1 = (char)c;
boolean isExisting = false;
l2: for(int j=0; j < i; j++){
if(c1 == pw[j]){
isExisting = true;
break l2;
}
}
if(!isExisting){
pw[i] = (char)c;
i++;
}

}
return new String(pw);
}

}

LdapOperations

You may use the following code to create quick ldap assisting functions:
==========================================
LdapOperations.java
==========================================

package com.bhatiacorp.operations;

import java.util.Hashtable;

import javax.naming.*;
import javax.naming.directory.*;

import com.thortech.util.logging.Logger;

public class LdapOperations {

private String loggerTag;
private Logger logger;
private String CLASS_NAME;
private String ldapHost;
private String ldapPort;
private String adminID;
private String adminPassword;
boolean useSSL;

public LdapOperations(String ldapHost, String ldapPort, String adminID, String adminPassword, boolean useSSL){
this.ldapHost = ldapHost;
this.ldapPort = ldapPort;
this.adminID = adminID;
this.adminPassword = adminPassword;
this.useSSL = useSSL;
loggerTag = "XL_INTG.BHATIACORP_LDAPOPERATIONS";
logger = Logger.getLogger(loggerTag);
CLASS_NAME = getClass().getName();

logger.info(" server name = " + ldapHost );
logger.info(" server port = " + ldapPort );
logger.info("adminId = " + adminID);
logger.info(" useSSL = " + useSSL );
}


private DirContext getContext(String ldaphost, String ldapport, String adminID, String adminpassword, boolean useSSL)
{
DirContext ctx=null;
String providerurl=ldaphost+":"+ldapport;
if(ldapport=="")
{
ldapport="636";
}
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY ,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL ,providerurl);
if(useSSL==true)
{
// if SSL is used - use can use ssl enabled ldaphost
// eg. "ldaps://localhost:636"
// else
// eg. "ldap://localhost:636"
env.put(Context.SECURITY_PROTOCOL, "ssl");
}
env.put(Context.SECURITY_AUTHENTICATION ,"simple");
env.put(Context.SECURITY_PRINCIPAL ,adminID);
env.put(Context.SECURITY_CREDENTIALS ,adminpassword);
ctx = new InitialDirContext(env);

}
catch(Exception ex)
{
ex.printStackTrace();
}
return ctx;
}

private DirContext getContext()
{
DirContext ctx=null;
try {
ctx=getContext("ldap://"+ldapHost,ldapPort,adminID,adminPassword,useSSL);
}
catch(Exception ex)
{
ex.printStackTrace();
}

return ctx;
}


/**
* @param cn
* @param attribute
* @param value
* @return
*/
public String addAttribute(String cn,String attribute, String newvalue) throws NamingException{
String rtnval="EXECUTION_SUCCESS";
DirContext ctx= null;
try{
ctx=getContext();
ModificationItem[] mods = new ModificationItem[1];
mods[0]=new ModificationItem(DirContext.ADD_ATTRIBUTE,new BasicAttribute(attribute,newvalue));
ctx.modifyAttributes(cn, mods);

}catch(Exception ex){
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}finally{
ctx.close();
}
return rtnval;
}

/**
* @param cn
* @param attribute
* @param value
* @return
*/
public String modifyAttribute(String userId,String attribute, String newvalue) throws NamingException{
String rtnval="EXECUTION_SUCCESS";
DirContext ctx= null;
try{
System.out.println();
ModificationItem[] mods = new ModificationItem[1];
ctx=getContext();
mods[0]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(attribute,newvalue));
ctx.modifyAttributes("cn="+userId, mods);
}catch(Exception ex){
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}finally{
ctx.close();
}
return rtnval;
}

/**
* @param cn
* @param attribute
* @param value
* @return
*/
public String modifyAttributeWithOutFullDN(String userId,String directoryRootNode, String attribute, String newvalue) throws NamingException{
String rtnval="EXECUTION_SUCCESS";

DirContext ctx= null;
try
{
ctx=getContext();
logger.info(" userId = " + userId );
ModificationItem[] mods = new ModificationItem[1];
String userDN=searchFullDn(directoryRootNode, "cn=" + userId);
logger.info(" user full dn = " + userDN );
logger.info(" attr name = " + attribute + " value = " + newvalue);
mods[0]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(attribute,newvalue));
ctx.modifyAttributes(userDN, mods);

logger.info(" update was done successfully ");
}catch(Exception ex){
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}finally{
ctx.close();
}
return rtnval;
}

/*
public void printAttributes(Attributes attrs)
{
try
{
for (NamingEnumeration ae = attrs.getAll(); ae.hasMore();) {
Attribute attr = (Attribute)ae.next();
System.out.println("attribute: " + attr.getID());
for (NamingEnumeration e = attr.getAll(); e.hasMore();
System.out.println("value: " + e.next()));
}}catch(Exception ex)
{
ex.printStackTrace();
}

}
*/

/**
* @param cn
* @param attribute
* @param value
* @return
*/
public String deleteAttribute(String cn,String attribute, String newvalue) throws NamingException{
String rtnval="EXECUTION_SUCCESS";
ModificationItem[] mods = new ModificationItem[1];
try
{
DirContext ctx=getContext();
mods[0]=new ModificationItem(DirContext.REMOVE_ATTRIBUTE,new BasicAttribute(attribute,newvalue));
ctx.modifyAttributes(cn, mods);
}
catch(Exception ex)
{
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}
return rtnval;
}


public String setADManagerInfo(String userId,String directoryRootNode, String mgrEmployeeId) throws NamingException{
String rtnval="EXECUTION_SUCCESS";

DirContext ctx= null;
try
{
ctx=getContext();
logger.info(" userId = " + userId );
logger.info(" manager employee id = " + mgrEmployeeId);
ModificationItem[] mods = new ModificationItem[1];
String userDN=searchFullDn(directoryRootNode, "cn=" + userId);
logger.info(" Manager DN to be searched is = " + "(|(extensionAttribute1=" + mgrEmployeeId+ ")(cn="+ mgrEmployeeId+ "))");
String managerDN = searchFullDn(directoryRootNode, "(|(extensionAttribute1=" + mgrEmployeeId+ ")(cn="+ mgrEmployeeId+ "))" );
if(this.isEmptyString(managerDN)){
return "EXECUTION_FAILURE_MANAGER_DOESN'T_EXISTS";
}
logger.info(" user full dn = " + userDN );
logger.info(" attr name is manager value = " + managerDN);
mods[0]=new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("manager", managerDN));
ctx.modifyAttributes(userDN, mods);

logger.info(" update was done successfully ");
}catch(Exception ex){
rtnval="ERROR: "+ex.getMessage();
}finally{
ctx.close();
}
return rtnval;
}


/**
* @param directoryRootNode
* @param nameToSearch
* @return
*/
public String searchFullDn(String directoryRootNode,String nameToSearch){
try
{
SearchControls searchControls = new SearchControls (SearchControls.SUBTREE_SCOPE, 1, 0, new String[0], true, false);
NamingEnumeration srchResults = getContext().search(directoryRootNode, "(&("+nameToSearch+")(objectclass=*))",searchControls);
if (srchResults.hasMore())
{
SearchResult sr = (SearchResult)srchResults.next();
return sr.getName().toString()+","+directoryRootNode;
}
} catch (NamingException e){
e.printStackTrace();
}
return "";
}

/**
*
* @param cnvalue
* @param fname
* @param lname
* @param treevalue
* @return
*/
public String createUser(String cnvalue, String fname, String lname, String treevalue){
String rtnval="EXECUTION_SUCCESS";
String treenodevalue="ou=People,dc=bhatiacorp,dc=com";
if(treevalue!="")
treenodevalue=treevalue;
try {
BasicAttributes attrs = new BasicAttributes();
BasicAttribute ocs = new BasicAttribute("objectClass");
ocs.add("top");
ocs.add("person");
ocs.add("organizationalPerson");
//Add whichever classes apply in your case
attrs.put(ocs);
attrs.put(new BasicAttribute("cn" , cnvalue));
attrs.put(new BasicAttribute("sn" , lname));
attrs.put(new BasicAttribute("displayName" , fname+" "+ lname));
String fulldn="cn="+cnvalue+","+treenodevalue;
getContext().createSubcontext(fulldn, attrs);
}
catch (Exception ex) {
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}

return rtnval;
}

/**
*
* @param cnvalue
* @return
*/
public String deleteUser(String cnvalue)
{
String rtnval="EXECUTION_SUCCESS";
String dn=searchFullDn("dc=bhatiacorp,dc=com", cnvalue);
try {
getContext().destroySubcontext(dn);
}
catch (Exception ex) {
rtnval="ERROR: "+ex.getMessage();
ex.printStackTrace();
}

return rtnval;

}


/**
* Return true if the given string is empty.
*/
public final boolean isEmptyString(String toCheck) {
if ((toCheck != null) && (toCheck.trim().length() > 0)) {
return false;
}
return true;
}

/**
* Return true if the given object is null.
*/
public final boolean isNull(Object toCheck) {
return (toCheck == null);
}

/**
*
* @param cn
* @param domain
* @param NewOU
* @return
*/
public String moveUser2NewOU(String cn, String domain,String NewOU){
String rtnval="EXECUTION_SUCCESS";
try {
DirContext ctx=getContext();
String OldCN="CN="+cn+",CN=Users,"+domain;
System.out.println("Old CN:"+OldCN);
String NewCN="CN="+cn+",OU="+NewOU+","+domain;
System.out.println("New CN:"+NewCN);
System.out.println("Starting Modify DN ");
ctx.rename(OldCN, NewCN);
System.out.println("Ended Modify DN with Success..."+rtnval);
//ctx.rename("CN=Rajnish Bhatia,OU=HR,dc=bhatiacorp,dc=com", "CN=Rajnish Bhatia,OU=IT,dc=bhatiacorp,dc=com");
//System.out.println(ctx.lookup("CN=Rajnish Bhatia,OU=IT,dc=bhatiacorp,dc=com"));
ctx.close();
} catch (Exception e) {
System.out.println("Ended Modify DN with Error...");
rtnval="ERROR : "+e.getMessage();
e.printStackTrace();
}
return rtnval;
}

/**
* @param args
*/
public static void main(String[] args) {
try
{
LdapOperations c=new LdapOperations();
//System.out.println(c.createUser("AB","ABtest","test","ou=People,dc=bhatiacorp,dc=com"));
System.out.println(c.modifyAttribute("cn=AB,ou=People,dc=bhatiacorp,dc=com", "extensionAttribute12", "12-12-1999"));
//System.out.println(c.searchFullDn("dc=bhatiacorp,dc=com","cn=AB"));
//System.out.println(c.deleteUser("cn=AB"));
}catch(Exception ex)
{
ex.printStackTrace();
}
}
}