/** * Checks if the user has a given role. Role name comparisons are not case sensitive. * @param roleName the name of the role to check * @return true if the user has the given role, else false * @should return true if the user has the given role * @should return false if the user does not have the given role * @should be case insensitive */ public boolean containsRole(String roleName) { for (Role role : getAllRoles()) { if (role.getRole().equalsIgnoreCase(roleName)) { return true; } } return false; }
/** * Get <i>all</i> privileges this user has. This delves into all of the roles that a person has, * appending unique privileges * * @return Collection of complete Privileges this user has */ public Collection<Privilege> getPrivileges() { Set<Privilege> privileges = new HashSet<>(); Set<Role> tmproles = getAllRoles(); Role role; for (Role tmprole : tmproles) { role = tmprole; Collection<Privilege> privs = role.getPrivileges(); if (privs != null) { privileges.addAll(privs); } } return privileges; }
/** * Checks if this user has the given String role * * @param r String name of a role to check * @param ignoreSuperUser If this is false, then this method will always return true for a * superuser. * @return Returns true if the user has the given role, or if ignoreSuperUser is false and the * user is a superUser */ public boolean hasRole(String r, boolean ignoreSuperUser) { if (!ignoreSuperUser && isSuperUser()) { return true; } if (roles == null) { return false; } Set<Role> tmproles = getAllRoles(); if (log.isDebugEnabled()) { log.debug("User #" + userId + " has roles: " + tmproles); } return containsRole(r); }
Set<Role> tmproles = getAllRoles();
/** * Gets all the roles for a user. Anonymous and Authenticated roles are appended if necessary * * @param user * @return all expanded roles for a user * @should not fail with null user * @should add anonymous role to all users * @should add authenticated role to all authenticated users * @should return same roles as user getAllRoles method */ public Set<Role> getAllRoles(User user) throws Exception { Set<Role> roles = new HashSet<>(); // add the Anonymous Role roles.add(getAnonymousRole()); // add the Authenticated role if (user != null && getAuthenticatedUser() != null && getAuthenticatedUser().equals(user)) { roles.addAll(user.getAllRoles()); roles.add(getAuthenticatedRole()); } return roles; }
Collection<Role> roles = user.getAllRoles(); List<String> requiredPrivs = new ArrayList<>();
if (userToBecome.getAllRoles() != null) { userToBecome.getAllRoles().size();
log.debug("User {}", user); if (user != null) { log.debug("has roles {}", user.getAllRoles());
candidateUser.getAllRoles().size(); candidateUser.getUserProperties().size(); candidateUser.getPrivileges().size();
/** * @param user * @return all roles for user * @see User#getAllRoles() */ public Set<Role> getAllRoles(UserAndPassword1_8 user) { if (user.getUser().getRoles() == null) return null; return RestUtil.removeRetiredData(user.getUser().getAllRoles()); //Get all active roles, including inherited roles }
User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles(); for (Role role : assignedRoles) { for (String testRole : testRoles) { User currentUser = Context.getUserContext().getAuthenticatedUser(); try { Set<Role> assignedRoles = currentUser.getAllRoles(); for (Role role : assignedRoles) { for (String testRole : testRoles) {