Creating Roles
Prerequisites
You have imported the required interfaces and gotten the required factories.
More information: User Management Functions for Roles .
Context
This procedure describes how to create a role programmatically in the user store. Use this procedure if you cannot use the existing user administration tools to create a role and need to customize your tools to create roles programmatically.
Procedure
Example
This example create a role with the name “demo_role” and sets the description attribute to “This role is for demo purposes.” .
public static void createRole(String roleName, String roleDescription) {
/*
* Note: The unique name of a role cannot exceed 200 characters.
* All other attributes have a maximum limit of 255 characters.
*/
try {
IRole mutableRole = roleFactory.newRole(roleName);
// Set the description attribute of the role.
mutableRole.setDescription(roleDescription);
// Write the changes to the user store.
mutableRole.save();
mutableRole.commit();
} catch (RoleAlreadyExistsException raeex) {
// TODO: Handle RoleAlreadyExistsException.
} catch (UMException umex) {
// TODO: Handle UMException.
} catch (UMRuntimeException umrex) {
// TODO: Handle UMRuntimeException.
}
}