The following code shows how to create a new user using the Strategy Web API 9.0.x - 9.2.x and how to initialize the creation of the profile folders all within the same piece of code.
Note: As of Strategy 9.0.0 - 9.2.x when creating a new user using the Strategy Web API the session created needs to be of type Admin. An Admin connection does not have to specify the project name. Creating the user profiles however does require a project connection since the folders are stored under each project.
The code accomodates for this by creating two separate sessions one to create the user (admin session) and one to create the profile folders (project connection).
package com.Strategy.standalone;
import com.Strategy.web.beans.UserEntityBean;
import com.Strategy.web.beans.WebBeanException;
import com.Strategy.web.beans.WebBeanFactory;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.web.objects.admin.users.WebUser;
import com.Strategy.webapi.EnumDSSXMLAuthModes;
public class CreateUser {
public static void main(String[] args) {
WebIServerSession isess = WebObjectsFactory.getInstance().getIServerSession();
isess.setServerName("xxxxxxx");
isess.setLogin("administrator");
//isess.setProjectName("Strategy Tutorial");
isess.setPassword("");
isess.setServerPort(0);
isess.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
WebIServerSession isessProj = WebObjectsFactory.getInstance().getIServerSession();
isessProj.setServerName("xxxxxxx");
isessProj.setLogin("administrator");
isessProj.setProjectName("Strategy Tutorial");
isessProj.setPassword("");
isessProj.setServerPort(0);
isessProj.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
try {
isess.getSessionID();
UserEntityBean user = null;
user = WebBeanFactory.getInstance().newUserBean();
user.setSessionInfo(isess);
user.InitAsNew();
//Fetch properties for the user
WebUser ua = (WebUser) user.getUserEntityObject();
//Set basic user information
ua.setLoginName("ZZZ_TestUser");
ua.setFullName("Sample User");
user.getObjectInfo().setDescription("This user was created using SDK");
//ua.createProfile();
//Save new User
user.save();
//close admin session
isess.closeSession();
//Gather user ID for later retrieval
String userID = user.getObjectID();
//Destroy User Object
user = null;
//Create a new User object
user = WebBeanFactory.getInstance().newUserBean();
user.setSessionInfo(isessProj);
user.InitAsNew();
//Attach the above created user
user.setObjectID(userID);
WebUser ub = (WebUser) user.getUserEntityObject();
//Initialize profile folders
//ub.createProfile();
//Save user changes
user.save();
System.out.println("Done");
isessProj.closeSession();
} catch (WebBeanException ex) {
System.out.println("Error creating a session: " + ex.getMessage());
} catch (WebObjectsException e) {
e.printStackTrace();
}
}
}