Class RoleBuilder

java.lang.Object
com.avoka.tm.svc.RoleBuilder

public class RoleBuilder extends Object

Provides a Role value object builder class.

Examples

Please find the Role builder examples below.

Create a Role

This example shows how to create a Role object.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role newRole = new RoleBuilder()
                .setRoleName("RoleTest")
                .setRoleDescription("Desc1")
                .setActiveFlag(true)
                .setClientAssignableFlag(true)
                .create();  

Update a Role's Active Flag

This example shows how to update a Role's Active Flag.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role role = new RoleBuilder()
                .setRoleName("RoleTest")
                .setActiveFlag(false)
                .update() 

Create/Update a Role

The example below shows how to create or update a Role and assign a user.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role role = new RoleBuilder()
                .setRoleName("RoleTest")
                .addUser("UserLoginName1")
                .createOrUpdate() 

The example below shows how to create or update a Role and set all users have this role.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role role = new RoleBuilder()
                .setRoleName("RoleTest")
                .setUserLoginNames(Set.of("UserLoginName1", "UserLoginName2", "UserLoginName3"))
                .createOrUpdate() 

The example below shows how to create or update a Role and assign a permission.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role role = new RoleBuilder()
                .setRoleName("RoleTest")
                .addPermission("PortalName", "PermissionName")
                .createOrUpdate() 

The example below shows how to create or update a Role and set all permissions for the role.

 import com.avoka.tm.svc.*
 import com.avoka.tm.vo.*

 Role role = new RoleBuilder()
                .setRoleName("RoleTest")
                .setPermissions("PortalName", Set.of("PermissionName1", "PermissionName2", "PermissionName3"))
                .createOrUpdate() 
Since:
23.04.0
  • Constructor Details

  • Method Details

    • setActiveFlag

      public RoleBuilder setActiveFlag(boolean activeFlag)
      Set the user activeFlag parameter.
      Parameters:
      activeFlag - the activeFlag
      Returns:
      the RoleBuilder
    • setClientAssignableFlag

      public RoleBuilder setClientAssignableFlag(boolean clientAssignableFlag)
      Set the clientAssignableFlag parameter.
      Parameters:
      clientAssignableFlag - the clientAssignableFlag
      Returns:
      the RoleBuilder
    • setRoleDescription

      public RoleBuilder setRoleDescription(String roleDescription)
      Set the roleDescription parameter.
      Parameters:
      roleDescription - the roleDescription parameter
      Returns:
      the RoleBuilder
    • setRoleName

      public RoleBuilder setRoleName(String roleName)
      Set the role name parameter.
      Parameters:
      roleName - the role name
      Returns:
      the RoleBuilder
    • addPermission

      public RoleBuilder addPermission(String spaceName, String permissionName)
      Add a permission to the role permissions for a specific space
      Parameters:
      spaceName - the space name
      permissionName - the permission name
      Returns:
      the RoleBuilder
    • removePermission

      public RoleBuilder removePermission(String spaceName, String permissionName)
      remove a permission from the role permissions for a specific space
      Parameters:
      spaceName - the space name
      permissionName - the permission name
      Returns:
      the RoleBuilder
    • setPermissions

      public RoleBuilder setPermissions(String spaceName, Set<String> setPermissionNames)
      set the role permissions for a specific space. It's important to know, this method removes all previous permissions for the specified space and add the permissions set which is provided here as parameter
      Parameters:
      spaceName - the space name
      setPermissionNames - the role permission names for a space
      Returns:
      the RoleBuilder
    • addUser

      @FluentSecurityPermission(permissions="role-assign") public RoleBuilder addUser(String userLoginName)
      Assign the user to the role.
      Parameters:
      userLoginName - the user login name should assign to the role
      Returns:
      the RoleBuilder
    • removeUser

      @FluentSecurityPermission(permissions="role-assign") public RoleBuilder removeUser(String userLoginName)
      Remove the user from role users
      Parameters:
      userLoginName - the user login name should not assign to the role
      Returns:
      the RoleBuilder
    • setUserLoginNames

      @FluentSecurityPermission(permissions="role-assign") public RoleBuilder setUserLoginNames(Set<String> userLoginNames)
      Set of user should have the role
      Parameters:
      userLoginNames - set of user login names
      Returns:
      the RoleBuilder
    • create

      public Role create()
      Create a new Role based on the specified parameter and return the new Role value object.
      Returns:
      the newly created Role value object
    • createOrUpdate

      public Role createOrUpdate()
      Create or update the role specified by the given parameters, and return current role value object. If the role specified by the roleName is not found then a new Role account will be created.
      Returns:
      create or update the role specified by the given parameters, and return current role value object
    • update

      public Role update()
      Update the role specified by the roleName parameter and return the update Role value object. This method will throw an IllegalArgumentException if the specified role specified by roleName parameter was not found.
      Returns:
      the update Role value object