Pages

Ads 468x60px

Thursday, July 26, 2012

Java: Add/Delete User of IBM Tivoli Access Manager (ITAM-eb)


This will help you to add/delete user of IBM Tivoli Access Manager (ITAM-eb) using TAM Java API. Please configure your environment before running this. Your PATH, CLASSPATH, JAVAHOME environmental variables should be set before running this and you have to include PD.jar in your project and classpath. Configuration for TAM-eb should be correct otherwise there will be some problems with it. I used default values here which you have to change according to your requirements. For conection with IBM Tivoli Access Manager (ITAM-eb) visit:   http://usmanali112.blogspot.com/2012/07/java-connection-with-ibm-tivoli-access.html



import com.tivoli.pd.jadmin.PDUser;
import com.tivoli.pd.jutil.PDContext;
import com.tivoli.pd.jutil.PDMessages;
import com.tivoli.pd.jutil.PDRgyUserName;

// service for TAM user
public class UserService {

// to set default values for User services
private String rgySuffix = "c=us";
private PDMessages msgs = new PDMessages();

// create user in TAM
public void createUser(String firstName, String lastName,
String password, String group) {
PDContext ctxt = null;
PDRgyUserName pdRgyUserName = null;

ArrayList<String> groupList = new ArrayList<String>();

// Set default values to create user
String name = firstName + " " + lastName;
boolean ssoUser = true;
boolean pwdPolicy = true;

try {

// Initialize administration API Context
ctxt = TAMConnection.InitializeContext();
String rgyName = "cn=" + name + "," + rgySuffix;
pdRgyUserName = new PDRgyUserName(rgyName, firstName, lastName);
groupList.add(group);
PDUser.createUser(ctxt, name, pdRgyUserName, null,
password.toCharArray(), groupList, ssoUser, pwdPolicy,
msgs);
PDUser pdUser = new PDUser(ctxt, name, msgs);
pdUser.setAccountValid(ctxt, true, msgs);
// Close administration API Context
TAMConnection.CloseContext(msgs);
}catch (Exception ex) {
ex.getMessage();
}
return result;
}

// to delete TAM user
public void deleteUser(String name) {
PDContext ctxt = null;

try {
// Initialize administration API Context
ctxt = TAMConnection.InitializeContext();
PDUser.deleteUser(ctxt, name, true, msgs);
// Close administration API Context
TAMConnection.CloseContext(msgs);

} catch (Exception ex) {
ex.getMessage();
}
}
}

No comments:

Post a Comment