Map user to portal
I create some users by groovy code. And now i want to map them to the portal to let them connect on it.
I dont know what code i have to add in my first code, to get that.
This is my current code to create users :
import java.util.logging.Logger;
import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.identity.UserCreator;
import org.bonitasoft.engine.identity.UserUpdater;
import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.api.impl.transaction.identity.AddUserMembership;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.profile.xml.ProfileMappingBinding;
final UserCreator user = new UserCreator (field_login1, field_pw1);
apiAccessor.getIdentityAPI().createUser(user);
return true
I map them to the role. Because i have 3 groupes G1, G2 and G3. In wich user can be Administrator or Client that's why i create two roles . So i map user like this : G1-Administrator for exemple.
And if it will not create user in the studio, how can i found it after closing the portal. In my cases users wich i add with my process they apear in the portal and once closed i lost them . And in all cases they not apear in my studio ?
Hey haris.subasic,
Actualy i have a big problem now. In my process i have 2 profiles Clients and administrators . When i create 2 users with a Client profile. If user1 start his case and ask to some administrator to confirm one tasks in his process, after the confirmation of his tasks it seems that in the portal, user2 get the same information while he never start a case . It should be sent only to user1 who started the case.
Why he send the information to all users with same profile ? I dont know how to manage this big problem !!!!!
Thank you.
Comments
When you say "user2 gets the same information" - what exactly does he get? Is there a task that you designed? Or an email notification? How is the information "sent" to all users of the profile? It might be due to some actor mapping based on the profile
API will add user on the engine level, that will be visible in the Portal, but it will not create it in the Studio, this is correct behaviour. What kind of actor mapping do you use for your Task3? Did you map it to a group, by any chance? Or a role?
Hello Rahmi,
here is a quick script to give you an idea how to do it by code (starting from your code from the question):
final identityAPI = apiAccessor.getIdentityAPI();
final profileAPI = apiAccessor.getProfileAPI();
final UserCreator user = new UserCreator (field_login2, field_pw2);
user.setFirstName(field_nom1).setLastName(field_prenom1);
identityAPI.createUser(user);
Long userId = identityAPI.getUserByUserName(field_login2).getId();
Long groupId = identityAPI.getGroupByPath("/acme").getId();
profileAPI.createProfileMember(1, userId, groupId, 1);
return true
Note that I used 1 for the profile id (that corresponds to the default User profile) and 1 for the role id (which corresponds to the default member role). You should update it to your needs. After this, your user should be able to connect to the Portal (like all other default users from Acme organization).
Hope this helps, Haris
Comments
Thank you for your help,
- Actualy i deleted the acme organisation and replace it by an other one with "opt" name. So i think i have just to replace /acme by /opt ?
When you said "toto" do you mean that i have to replace it with "the login" of user (In my case field_login1).
How can i get the right Id for diffirent parameters such (role, group and profil) , while i want to assign all this parameters to my new users !
Thanks
Thank you , i will see and if i get some errors i will tell you difficulties :)
Thank you enrico.curiotto,
Yeah now i add the other informations such first name and last name , as follow :
user.setFirstName(field_nom1).setLastName(field_prenom1);
apiAccessor.getIdentityAPI().createUser(user);
At this moment i want to map user to some profil (Users or administrators) to be able to connect in portal. I dont want to oblige the administrator to connect every time on the portal to map the new user i want to do all this job in my process.
Do you think it's possible ? and how ?
Thank you again.
Hi Rahmi, you code works just fine, and you can connect to the portal as and administrator, go to organization and you'll see your new user created. You only set username and password, so in the list you have firstname and lastname as blanks. You can easily put name and lastname with user.setFirstName("...."); and user.setLastName("...."); Be also aware of the unneded imports you have on your script.
Correcting the answer based on your observations: You have two ways to achieve that. 1) Assign manually the profile user to the supergroup of your organization (ACME in the default case) In this way, after you create the user it's sufficient to use the method addUserMembership: org.bonitasoft.engine.api.MembershipAPI.addUserMembership(long userId, long groupId, long roleId) in your code to associate the user created to the supergroup. This automatically will let the user access to the portal with User profile 2) Play with the ProfileAPI methods. You can access them via apiAccessor.getProfileApl()
Cheers
Comments
No, groovy is for server-side scripting, it cannot interact with the Studio.