Search

10. Users and Roles

download PDF
Roles are the primary access control method in JBoss ON. A role creates a relationship between users and resources (through resource groups). The permissions set for the role define what permissions the users in the role have for the resource in the role.

10.1. Creating Roles

A user can only see and manage what resources are in the roles to which a user belongs. If there are no resources, then the user can do very little in JBoss ON, regardless of whatever their permissions are.
This script creates a role and adds a mixed group to it. It could be made more complex, like using different criteria to get different types of groups or adding multiple groups to the role at once.
The script steps are:
  1. Create a role and assigning the appropriate permissions. In this case, the role has manage inventory and view user permissions.
  2. Search for the group to add as a member.
  3. Search for the new role entry.
  4. Add the group to the role.

Example 25. A New Role

// create the role
var role = Role('Role Name - ' + java.util.Date());
role.description = 'This role is an example';
role.addPermission(Permission.MANAGE_INVENTORY);
role.addPermission(Permission.VIEW_USERS);
RoleManager.createRole(role);

//search for the group to add to the role
groupcriteria = new ResourceGroupCriteria();
groupcriteria.addFilterGroupCategory.toString('MIXED');

var groups = ResourceGroupManager.findResourceGroupsByCriteria(groupcriteria);

//search for the new role
var c = new RoleCriteria();
c.addFilterName('Role Name');
var roles = RoleManager.findRolesByCriteria( c );
RoleManager.addResourceGroupsToRole(roles.get(0).id,[groups.get(0).id]);

10.2. Creating Users

There are two parts to a user entry: the descriptive entry in JBoss ON and the principal, which is the login username/password pair.
The script steps are:
  1. Create a new user (subject) entry.
  2. Create a principal for the new user.
  3. Search for roles to add the user to and create an array.
  4. Add the user to the roles.

Example 26. Creatting a User and Adding Roles

//create the new user entry	
var newSubject = new Subject();
newSubject.setEmailAddress( 'admin@example.com' );
newSubject.setFirstName('John');
newSubject.setLastName('Smith' );
newSubject.setFactive(true);
newSubject.setFsystem(false);
newSubject.setName('jsmith');
var s = SubjectManager.createSubject(newSubject);

//create the login principal for the user
SubjectManager.createPrincipal( s.name, 'password' );

//search for the role and create an array
var c = new RoleCriteria();
c.addFilterName('Role Name');
var roles = RoleManager.findRolesByCriteria( c );
var role = roles.get(0);
var rolesArray = new Array(1);
rolesArray[0] = role.getId();

//add the new user to the roles in the array
RoleManager.addRolesToSubject(s.getId(), rolesArray );
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.