Ejemplo n.º 1
0
 @Override
 public Collection<? extends GrantedAuthority> getAuthorities() {
   Collection<GrantedAuthority> grantedAuthorities = new HashSet<GrantedAuthority>();
   for (UserRole role : this.getUserRoles()) {
     grantedAuthorities.add(new SimpleGrantedAuthority(role.getRoleName()));
   }
   return grantedAuthorities;
 }
Ejemplo n.º 2
0
  /**
   * TODO Consider making this cacheable
   *
   * @param authorities The required authorities
   * @return True if the user has all the required authorities
   */
  public boolean hasAllAuthorities(Authority[] authorities) {
    Set<Authority> requiredAuthorities = Sets.newHashSet(authorities);
    Set<Authority> grantedAuthorities = Sets.newHashSet();
    for (UserRole userRole : userRoles) {
      grantedAuthorities.addAll(userRole.getRole().getAuthorities());
    }

    return grantedAuthorities.containsAll(requiredAuthorities);
  }
Ejemplo n.º 3
0
 public User getUserWithRole(za.org.rfm.utils.Role role) {
   for (User user : getUsers()) {
     for (UserRole userRole : user.getUserRoles()) {
       if (userRole.getRole().getName().equalsIgnoreCase(role.name())) {
         return user;
       }
     }
   }
   return null;
 }
Ejemplo n.º 4
0
 public List<User> getUsersWithRole(za.org.rfm.utils.Role role) {
   List<User> userList = new ArrayList<User>();
   for (User user : getUsers()) {
     for (UserRole userRole : user.getUserRoles()) {
       if (userRole.getRole().getName().equalsIgnoreCase(role.name())) {
         userList.add(user);
       }
     }
   }
   return userList;
 }
Ejemplo n.º 5
0
  public UserRole removeUserRole(UserRole userRole) {
    getUserRoles().remove(userRole);
    userRole.setUser(null);

    return userRole;
  }
Ejemplo n.º 6
0
  public UserRole addUserRole(UserRole userRole) {
    getUserRoles().add(userRole);
    userRole.setUser(this);

    return userRole;
  }