Pages

Ads 468x60px

Thursday, July 26, 2012

Java: Add/Delete Group and Show Groups list of IBM Tivoli Access Manager (ITAM-eb)


This will help you to add/delete group and get all groups list 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 java.util.ArrayList;
import com.tivoli.pd.jadmin.PDGroup;
import com.tivoli.pd.jutil.PDContext;
import com.tivoli.pd.jutil.PDMessages;
import com.tivoli.pd.jutil.PDRgyGroupName;

// service for the TAM groups
public class GroupService {

private String rgySuffix = "c=us";
private PDMessages msgs = new PDMessages();

// create group in TAM
public void createGroup(String group) {
PDContext ctxt = null;
try {
ctxt = TAMConnection.InitializeContext();
this.rgySuffix = TAMConnection.registrysuffix;
String rgyGroup = "cn=" + group + "," + rgySuffix;
PDRgyGroupName pdRgyGroupName = new PDRgyGroupName(rgyGroup);
PDGroup.createGroup(ctxt, group, pdRgyGroupName, null, null, msgs);
TAMConnection.CloseContext(msgs);
} catch (Exception ex) {
ex.getMessage();
}

}

// to delete group from TAM
public void deleteGroup(String group) {
PDContext ctxt = null;

try {
ctxt = TAMConnection.InitializeContext();
PDGroup.deleteGroup(ctxt, group, true, msgs);
TAMConnection.CloseContext(msgs);

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

// to get all groups from TAM
public ArrayList<String> getGroup() {
PDContext ctxt = null;
                ArrayList<String> list = null;
try {
ctxt = TAMConnection.InitializeContext();
list = PDGroup.listGroups(ctxt,
PDGroup.PDGROUP_ALLPATTERN, PDGroup.PDGROUP_MAXRETURN,
true, msgs);

TAMConnection.CloseContext(msgs);
}  catch (Exception ex) {
ex.getMessage();
}
return list;
}
}

No comments:

Post a Comment