Tips & Tricks - User Management by Process
This post shows how user groups can be created using a process. The automated creation and assignment of users to user groups is also explained. You'll also find a Groovy script here for retrieving a user's memberships.
Create a user group
In any process, user groups can be created using a data group action. To do this, first create a data source, such as an event handler. In the event handler's properties, you can specify the source of the data for the new user group, such as the name. Then associate a data group action with the event source.
In the properties of the data group action, select the "Add Record" action.
For the target data group, select the "Set" data group from the "Users" system application.
In the field mapping, at least the following values should now be assigned to the target—the new user group in User Management:
-
A GUID that can be easily created by clicking "
" and selecting "Custom Value," and then assigned -
Class ID 6 (integer), which can also be created by clicking "Custom Value" and then assigned
-
the object name
Once the settings and the process have been saved, the new user group is created.
Create a user
New users can be created using a process and assigned to a user group. A Groovy action handles the insertion using the following script:
def user = g_om.createUser{
container = "System"
name = "user-${now().withoutFractionalSeconds}"
loginName = "UserU-${now().withoutFractionalSeconds}"
emailBiz = "user@example.org"
description = "User created with Groovy at ${now().withoutFractionalSeconds}"
memberOf = ["Users", "6AA80844C3F99EF93BF4598EB18605BF86FDD3C5"]
}
The access object "g_om" provides a structure that can be used to perform operations related to user management and the organizational structure of a portal. In this script example, the following properties are set when a user is created; *name* and *loginName* are required. All other features are optional.
-
container: The container in which the user object is to be created. You can specify the unique name (in our example, "System"), the GUID, or the container's path
- name: The unique object name
- loginName: The unique login name
- emailBiz: The user's email address
- description: Description of the user object
- memberOf: This is where the user's group memberships are defined.
You can specify the unique name, the GUID (in our example, "6AA80844C3F99EF93BF4598EB18605BF86FDD3C5"), or the path to the group.
A timestamp is used here for usernames and logins to ensure uniqueness. If, in a user management system, the uniqueness of a username and login is not ensured using an ID or a timestamp, but instead a different format is used—such as firstname.last_name, then when creating a new user, the system must check whether a user with the same information already exists and, if necessary, handle the error accordingly.
Retrieve a user's memberships
The following script can be used to determine a user's group memberships.
def user = g_om.getUser(g_session.user.guid)
def sets = g_om.getMembershipSets(user)
def strAdminGroupGuid = "EF16F15EDA8562E19D7DD75BF2OP3001F119193C"
if (sets*.guid.contains(strAdminGroupGuid))
return adminGroupMemberTrue
else
return adminGroupMemberFalse
In this example, "g_session.user.guid" is used to retrieve the GUID of the currently logged-in user. "g_om.getMembershipSets(member)" returns a list of all groups—including subgroups—of which the specified user is a member. You can then use an iteration over the GUIDs of the found groups to determine whether the GUID of the administrators group (which you must replace in the script with your own administrators group GUID) is included in the returned result set. Depending on the result of this evaluation—in this example, whether the user is a member of the Administrators group—a corresponding value is returned, which can be used, for example, in a Groovy condition to specifically trigger further process steps.


