Create a new user

Product version:
6.5, 6.4, 6.3, 6.2, 6.1, 6.0
Product edition:
  • Community
  • Teamwork
  • Efficiency
  • Performance
Get the PDF version

This example shows you how to create a new user and assign the user to a profile.

Create a new user by calling the createUser method:

// create new user, with username john and password bpm
final User user = identityAPI.createUser("john", "bpm");
System.out.println("New user created: " + user);

Alternatively, you can create a more complex user object as follows:

// create complex user
UserCreator creator = new UserCreator("john", "bpm");
creator.setFirstName("Johnny").setLastName("B. Good");
ContactDataCreator proContactDataCreator = new ContactDataCreator().setAddress("32 rue
        Gustave Eiffel"
).setCity("Grenoble").setPhoneNumber("555 14 12 541");
final User user2 = identityAPI.createUser(creator);

Now add the user to a Bonita BPM Portal profile. A user who does not have a profile cannot log in to Bonita BPM Portal.

// reference the user in the profile User
// the user must be now registered in one profile. Let's choose the profile user
org.bonitasoft.engine.api.ProfileAPI orgProfileAPI = apiAccessor.getProfileAPI();
SearchOptionsBuilder searchOptionsBuilder = new SearchOptionsBuilder(0,10);
searchOptionsBuilder.filter(ProfileSearchDescriptor.NAME, "user");
SearchResult<Profile> searchResultProfile = orgProfileAPI.searchProfiles(searchOptionsBuilder.done());
// we should find one result now
if (searchResultProfile.getResult().size()!=1)
        { return; }

// now register the user in the profile
Profile profile = searchResultProfile.getResult().get(0);
ProfileMemberCreator profileMemberCreator = new ProfileMemberCreator( profile.getId());
profileMemberCreator.setUserId( user.getId());

To create a user with more complete information, use the UserBuilder to create an instance of User and then use the createUser method with the User as parameter.

Get the PDF version
Last update on Feb, 17 2015