Create users

1
0
-1

I want to create users with some groovy code. I tried with :

final UserCreator user = new UserCreator ("toto", "toto");

But it doesn't works !?

Thx

10 answers

1
+1
-1
This one is the BEST answer!

Hi.

If you want to create a user with an email you can do this :

import org.bonitasoft.engine.identity.ContactDataCreator;
import org.bonitasoft.engine.identity.UserCreator;

ContactDataCreator contactDataCreator = new ContactDataCreator();

contactDataCreator.setEmail("truc@machin.fr");

UserCreator userCreator = new UserCreator("UserName", "Password");
userCreator.setPersonalContactData(contactDataCreator);
userCreator.setFirstName("Firstname");
userCreator.setLastName("LastName");

apiAccessor.getIdentityAPI().createUser(userCreator);

Comments

Submitted by rahmi.hichem on Fri, 07/04/2014 - 15:45

Thanks it works :) .

1
0
-1

Hola amigos necesito el código para añadir el rol y grupo a un usuario al crearlo? xf gracias

Comments

Submitted by yannick.lombardi on Thu, 04/09/2015 - 09:02
import org.bonitasoft.engine.identity.Group;
import org.bonitasoft.engine.identity.Role;

try {
        Group group = apiAccessor.getIdentityAPI().createGroup("GroupName", "ParentGroup");
        Role role = apiAccessor.getIdentityAPI().createRole("RoleName");
        apiAccessor.getIdentityAPI().addUserMembership(user.getId(), group.getId(), role.getId());
}
catch (Exception e){}
Submitted by brolymichz on Fri, 04/10/2015 - 23:46

muchisismas gracias voy aprobarlo

1
0
-1

Hello,

i want to create in the same time the mail adresse of user thatway : After that the user complete de form i take his mail adresse and i create it exacly as i create a new profil with Login + PW as follow :

final UserCreator user = new UserCreator (field_u_login3, field_u_pw3);
user.setFirstName(field_f_name3).setLastName(field_p_name3);
apiAccessor.getIdentityAPI().createUser(user);

But i dont know what code to write to fill the mail adresse as i did with Login and PassWord

1
0
-1

Yeah, i found this :

addUser(String username,
        String password,
        String firstName,
        String lastName,
        String title,
        String jobTitle,
        String managerUserUUID,
        Map<String,String> profileMetadata)

But actualy i dont know what package and what parameters i should put ?!!

1
0
-1

And to map the user to some profile , have i to do it with code or in the portal with administrator role ?

Comments

Submitted by haris.subasic on Wed, 06/11/2014 - 12:14

You should be able to do it through APi, have a look at the ProfileAPI here , I think that the correct method would be createProfileMember.

Submitted by rahmi.hichem on Tue, 07/08/2014 - 16:04

With the createProfileMember method you think that we can attribute a privilege (Administrator or user) to be able to connect on the portal ?

Submitted by rahmi.hichem on Tue, 07/08/2014 - 17:16

Found it :)

apiAccessor.getProfileAPI().createProfileMember(2, user.getId(), group.getId(), role.getId())

1 : For the simple user 2 : For Administrator

You can make some combobox with the two choices and an IF..ELSE test before this line to attribute the right number

1
0
-1

It works thank you. But as you said he just create some user with username "toto", what if i want to create at the same time the password too ?!!

Comments

Submitted by haris.subasic on Tue, 06/10/2014 - 17:43

The user will also have the password "toto". What you need to more is to map this new user to some profile, for example User profile. It is only then that he would be able to log in to the Portal.

1
0
-1

It works now thank you. But as you said he just create some user with Login "toto". What if i want to create even the passweord at the same time ?

1
0
-1

Can you write me the all code here please because now it said : "Error while submitting the form". I think i have some error in my code.

And what i want, is just to create some user whith his password .

Thanks

1
0
-1

Hey,

I tried ur proposal but it doesn't works :/ .

I did this :

import org.bonitasoft.engine.identity.UserCreator;
import org.bonitasoft.engine.identity.UserUpdater;
import java.util.logging.Logger;

Logger log = Logger.getLogger ("org.bonitasoft.hichem")
log.severe (" DEBUG - START changePw " )

final UserCreator user = new UserCreator ("toto", "toto");
apiAccessor.getIdentityAPI().createUser(user);

return true

Comments

Submitted by haris.subasic on Tue, 06/10/2014 - 10:19

I just tried your code and it worked fine on my side, a user with username "toto" was created. Did you have any errors? How do you know it didn't work? Can you log in as admin and go to the list of users to look for "toto" user? Note that your newly created user will have only username, and no first name nor last name (will be displayed as empty in the Portal).

1
0
-1

Try to add this line after the UserCreator that you prepare:

apiAccessor.getIdentityAPI().createUser(user);

Comments

Submitted by rahmi.hichem on Mon, 07/21/2014 - 14:02

I tried to get the user Pass Word with this code but it doesn't works :

return BonitaUsers.getProcessInstanceInitiator(apiAccessor, processInstanceId).getPassword();

?!!

Submitted by yannick.lombardi on Mon, 07/21/2014 - 15:47

The getPassword() method is deprecated. It always return null. I think there is no method to get the password in 6.3.X version.

Notifications