Product SiteDocumentation Site

5.2.2. Managing Groups

The following example demonstrates how to create a new group called employees:
  Group employees = new Group("employees");
It is also possible to assign a parent group when creating a group. The following example demonstrates how to create a new group called managers, using the employees group created in the previous example as the parent group:
  Group managers = new Group("managers", employees);
To lookup an existing Group, the getGroup() method may be used. If the group name is unique, it can be passed as a single parameter:
  Group employees = BasicModel.getGroup(identityManager, "employees");
If the group name is not unique, the parent group must be passed as the second parameter (although it can still be provided if the group name is unique):
  Group managers = BasicModel.getGroup(identityManager, "managers", employees);
It is also possible to modify a Group's name and other properties (besides its parent) after it has been created. The following example demonstrates how to disable the "employees" group we created above:
  Group employees = BasicModel.getGroup(identityManager, "employees");
  employees.setEnabled(false);
  identityManager.update(employees);
To remove an existing group, we can use the remove() method:
  Group employees = BasicModel.getGroup(identityManager, "employees");
  identityManager.remove(employees);