March 2, 2015 at 7:21 pm #3312F3bioParticipant
we would like when creating a new user (internal or external), from the UI, the username field is generated automatically and unique.
For example, if we wanted that the “rule” of creation was “firstname-lastname” (plus an incremental number if it already exists), if firstname is “openidm” and lastname “admin”, the rule should return “openidm-admin2”.
There is a “best practice” to do it?March 2, 2015 at 10:11 pm #3314Jake FeaselModerator
The UI creates managed/user records, so to control the behavior for new managed/users you need to adjust the script that is executed as part of the create event. You can do so within conf/managed.json:
I suggest making a copy of the default script (bin/defaults/script/ui/onCreate-user-set-default-fields.js) and placing it in your project-specific script folder, and then update that reference in managed.json to refer to your custom file (“script/onCreate-custom.js”). Within this copy, add the necessary logic to calculate the userName field.
You will also need to update the policy for managed/user, since it expects the content to be posted with a userName already populated. All you will need to do is remove the policies for userName (they won’t be necessary now that you are implementing your own policies programmatically within that above script).
Finally you will need to update the UI template so that admin users won’t be prompted to enter the userName themselves. Copy the files
to this folder:
Within AdminUserProfileTemplate, I suggest changing the html for the userName field so that it is readonly. Within AdminUserRegistrationTemplate, I would just remove the field entirely. This should prevent people from attempting to define the property.
JakeMarch 3, 2015 at 9:01 am #3315F3bioParticipant
Thanks Jake for your reply.
This can be a good solution, but when i created the user I don’t know the real username and the administrator must search for the new user.
So I’m trying something a bit different, but I’m stuck:
- Editing AdminUserProfileTemplate and AdminUserRegistrationTemplate and make userName readonly
ui/default/enduser/public/org/forgerock/openidm/ui/admin/users/AdminUserRegistrationView.jsand add two events (change input[name=givenName/sn]) that call a function; this function first check if firstname and lastname are present and after that try to create the userName
I’m stuck with this strategy because I can’t understand how to check the unique policy of the userName.
Have you got some suggestion? Unless I rollback and try your solution and add an email that notify the administrator the new username through email.
You must be logged in to reply to this topic.