As we started to talk about BO SDK ,at here, today we will continue with writing simple code about administration on users and groups.
Today we will try to create user and groups. First of all we will login our an administrators group accout to BO platform with coding.After we will create a user and a group.
I want to start with coding on users and groups because generally in projects I allways encounter user synchronization problem.
That is,customers have a portal and user structure based on portal and they don’t want to control BO users one by one
for every operation done on portal side.They want an automatically working program that do synchronization
for them when an update occurs on portal users information.
Not: All this samples will be given in Java and Business Objects 3.1 version. You can imagine sub-titles as methods of Java class.
2.1 Login to BO
Doing all of these work we need a valid IEnterpriseSession. I recommend you to use Administrator account for
working on Users and Groups.
// General Attributes Of Class
private IEnterpriseSession enterpriseSession = null;
private IInfoStore infoStore = null;
/*
to get IEnterpriseSession this method is general process
this process will not be repeated next samples
*/
private void login() throws Exception
{
try{
System.out.println("BOProxy.java::login() started");
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
/*Parameters
logon (
First Parameter : BO User Account ,
Second Parameter : Account Password,
Third Parameter : CMS Name,
Fourth Parameter : Login Type as you can use secEnterprise, secLDAP, secWinAD, secSAPR3
);
*/
enterpriseSession = sessionMgr.logon("Administrator", "", "CMSNAME", "secEnterprise");
infoStore = (IInfoStore) enterpriseSession.getService("InfoStore");
}catch(Exception e){
System.out.println("Exception "+e.getLocalizedMessage());
}
}
2.2 Creating Users
As you realized all of the process in Business Objects starts with a user which has rights.Today we
will try to create a user with simple properties.We will use IEnterpriseSession object from 2.1 .
/*
Creating User Process
*/
public void createUserProcess(){
try{
//This 4 line is standart procedure, this will give us an empty IInfoObject
IPluginMgr pluginMgr = infoStore.getPluginMgr();
IPluginInfo userPlugin = pluginMgr.getPluginInfo("CrystalEnterprise.User"); //$NON-NLS-1$
IInfoObjects newInfoObjects = infoStore.newInfoObjectCollection();
newInfoObjects.add (userPlugin);
//IInfoObject is basic object of the all BO objects
IInfoObject iObject = (IInfoObject) newInfoObjects.get(0);
//IUser extends IInfoObject. And below lines are special for IUser
IUser boUser = (IUser) iObject;
//Title means user account name as ID
boUser.setTitle ("demoUser");
boUser.setFullName("Demo User Account");
boUser.setEmailAddress("demo@sabrieker.com");
//Connection type with related your licence it can be IUser.NAMED or IUser.CONCURRENT
boUser.setConnection(IUser.NAMED);
//Password Properties
boUser.setNewPassword("Password");
boUser.setPasswordChangeAllowed(true);
boUser.setPasswordExpiryAllowed(true);
boUser.setPasswordToChangeAtNextLogon(true);
/*
For disabling user account you can use below lines
IUserAliases aliases = boUser.getAliases();
IUserAlias alias = (IUserAlias) aliases.toArray()[0];
alias.setDisabled(true);
*/
/*
After you have done your job with IUser object , you must commit IInfoObjects with IInfoStore.
You can't commit IInfoObject or IUser , you have to do it with IInfoObjects.
*/
infoStore.commit (newInfoObjects);
}catch(Exception e){
e.prinstacktrace();
}
}
2.3 Creating Groups
You will need groups to organize huge number of users or organize your rights with similar groups.It will give
you power of managing all right attending with a few clicks done on groups.
You can do right assignment based on users but it will probably confuse your works.
User Groups has two properties.First one is its ID ,its title, and second one is its description.
public void createGroup (){
IPluginMgr pluginMgr = infoStore.getPluginMgr();
IPluginInfo userGroupPlugin = pluginMgr.getPluginInfo("CrystalEnterprise.UserGroup");
IInfoObjects groupInfoObjects = infoStore.newInfoObjectCollection();
groupInfoObjects.add(userGroupPlugin);
IInfoObject iObject = (IInfoObject) groupInfoObjects.get(0);
IUserGroup group = (IUserGroup) iObject;
group.setTitle("demoGroup");
group.setDescription("Description About Group");
infoStore.commit (groupInfoObjects);
}
Next case we will be working on “demo” user and “demoGroup” group objects. We will get these objects from repository with using
IInfoStore object and a query. After we will make our user member of this group. See you
Pingback: Lecture – 31 Tidal Energy | Energy Alternatives New Zealand