Ejemplo n.º 1
0
 /**
  * Removes a sub role from this role.
  *
  * @param role The role to remove.
  */
 @Override
 public void removeRole(Role role) {
   if (role.isMasterRole()) {
     throw new APSSimpleUserServiceException(
         "Bad role '" + role.getId() + "'! A master role cannot be added to another role!");
   }
   if (this.roles != null) {
     this.roles.remove(role);
   }
 }
Ejemplo n.º 2
0
 /**
  * Adds a sub role to this role.
  *
  * @param role The role to add.
  */
 @Override
 public void addRole(Role role) {
   if (role.isMasterRole()) {
     throw new APSSimpleUserServiceException(
         "Bad role '" + role.getId() + "'! A master role cannot be added to another role!");
   }
   if (this.roles == null) {
     this.roles = new LinkedList<RoleEntity>();
   }
   this.roles.add((RoleEntity) role);
 }
Ejemplo n.º 3
0
  /**
   * Returns true if the role has the specified sub role name.
   *
   * @param roleName The name of the role to check for.
   */
  @Override
  public boolean hasRole(String roleName) {
    boolean hasRole = false;

    if (this.roles != null) {
      // Lets check the "local" roles first.
      for (Role role : this.roles) {
        hasRole = role.getId().equals(roleName);
        if (hasRole) break;
      }

      // Then we check the sub roles if no match has been found.
      if (!hasRole) {
        for (Role role : this.roles) {
          hasRole = role.hasRole(roleName);
          if (hasRole) break;
        }
      }
    }

    return hasRole;
  }