How can i create a user and make him a member of a group automaticly
Hello , i'm a beginner in bonitasoft, and i'm looking for the solution to create new users using a form which is with a anonymous authentication, after that the user is created in the organisation and have the role of member of a group specified in the form . and the script of the creation of the new user is used in a script task , or i have to make two tasks the first is human and the second is a script task , I dont wanna make this manually with Organisation > Users and manage. best regards ,
You will have to use the IdentityAPI and MembershipAPI
for example
User createUser(String userName,
String password,
String firstName,
String lastName)
throws AlreadyExistsException,
CreationException
Will create the user (see documentataion here: [createUser][], and to add the user to a group see [here][] .
Something like:
import MembershipAPI;
def userName = "john.smith"
def defaultpwd = "bpm"
def firstName = "John";
def lastName = "Smith"
def userGroup = group("groupPath").getid()
def userID = createUser(userName, defaultpwd, firstName, lastName)
def groupID = addMembership(userId, userGroup, roleId)
NOTE: This is sample pseudo code, you will need to complete it to get it to work. I've not done this before, just pointing you in the right direction.
In fact you could also look at the documentation here to see how it is really done in a process.
http://documentation.bonitasoft.com/create-new-user http://documentation.bonitasoft.com/add-user-group
regards
[createUser]: http://documentation.bonitasoft.com/javadoc/api/6.3/org/bonitasoft/engin...(java.lang.String, java.lang.String, java.lang.String, java.lang.String) [here]: http://documentation.bonitasoft.com/javadoc/api/6.3/org/bonitasoft/engin...(long, long, long)
Comments
Thanks a lot sean , just i want to know about the
"groupPath" how can i find the path of a group
Getting the grouppath is done through the organization, if using Community I do this as follows:
List<Group> groupList = apiAccessor.getIdentityAPI().getGroups(0, 2000, GroupCriterion.NAME_ASC);
for (Group group : groupList) {
String orgPath = group.getPath();
String delimiter = "/";
String[] temp;
temp = orgPath.split(delimiter);
organization = temp[1];
//then process the organization path as required...
}
regards
thanks a lot sean thats really helps me . but i'm beginner in bonitasoft community so i want to ask you if i have to create this code in a script task . and adding the variables such as the username , password, group path,.. in the groovy script ? cause i want to authentificate with anonymous login and in the form i have to complete those fields after that the user is created in the group or subgroup specified i really appreciate your answers mr sean thanks a lot regards,
So what I think you're asking is
If so then, my big concern is security. Allowing people to assign their own logins not generally a good idea. However if it is really secure then OK.
I would do it this way.
Create a HTML page that people can go to Add JavaScript etc to call REST and add the user that way
See REST here and REST Identity API here
I can't help you further than that as I don't really do REST, but that's the way I would do it,
hope it gets you on your way,
regards Seán
thanks a lot sean that's really helps me