Obtains the authorities for the user who's directory entry is represented by
the supplied LdapUserDetails object.

@param user the user who's authorities are required
@return the set of roles granted to the user.
769501
public Collection<GrantedAuthority> getGrantedAuthorities(DirContextOperations user, String username) {
        String userDn = user.getNameInNamespace();

        if (logger.isDebugEnabled()) {
            logger.debug("Getting authorities for user " + userDn);
        }

        Set<GrantedAuthority> roles = getGroupMembershipRoles(userDn, username);

        Set<GrantedAuthority> extraRoles = getAdditionalRoles(user, username);

        if (extraRoles != null) {
            roles.addAll(extraRoles);
        }

        if (defaultRole != null) {
            roles.add(defaultRole);
        }

        List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(roles.size());
        result.addAll(roles);

        return result;
    }
425927
@Override
    public List<User> findUsers() {
        List<User> userList;
        try {
            userList = createUsers(ldapDao.getDirectChildren(DnFactory.users()));
        } catch (NoSuchNodeException | MissingParentException e) {
            LOGGER.error("LDAP exception", e);
            throw new LdapRuntimeException(e);
        }
        return userList;
    }
1095601
private UserEntity ensureRolesFetched(final UserEntity user)
	{
		if (user != null)
			user.getRoles().stream().map(r -> r.getId()).collect(Collectors.toList());

		return user;
	}
1326576
@Override
    public Node getPrincipal() {
        if (principal == null) {
            principal = new LdapUser();
            LdapUser p = (LdapUser) principal;
            p.setDn(Configuration.getProperty(instanceName + ".principal").trim());
            p.setUid(getUidForDN(p.getDn()));
        }
        return principal;
    }
1201343
public static boolean currentUserHasRole(String... roles) {
    if (roles == null || roles.length == 0) return false;

    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication != null) {
      Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
      if (authorities == null) throw new IllegalStateException("No user currently logged in");

      for (String role : roles) {
        for (GrantedAuthority grantedAuthority : authorities) {
          if (role.equals(grantedAuthority.getAuthority())) return true;
        }
      }
    }
    return false;
  }
1074979
@Override
    public Set<Node> getGroupsForUser(Node user) {
        Set<Node> groups = new TreeSet<>();
        try {
            String query = "(& (objectClass=" + groupObjectClass + ") (" + groupMemberAttribut + "=" + ((LdapUser) user).getDn() + "))";
            SearchResult searchResult;
            Attributes attributes;
            SearchControls controls = new SearchControls();
            controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
            NamingEnumeration<SearchResult> results = ctx.search("", query, controls);
            queryCount++;
            Node group;
            while (results.hasMore()) {
                searchResult = results.next();
                attributes = searchResult.getAttributes();
                group = getGroup(getAttributeOrNa(attributes, groupIdentifyer));
                group.setDn(searchResult.getNameInNamespace());
                groups.add(group);
            }
        } catch (NamingException ex) {
            handleNamingException(user, ex);
        }
        return groups;
    }
1292641
protected List<Principal> createRolePrincipals(UnixUser username) {
        ArrayList<Principal> principals = new ArrayList<Principal>();
        if (null != supplementalRoles) {
            for (String supplementalRole : supplementalRoles) {
                Principal rolePrincipal = createRolePrincipal(supplementalRole);
                if (null != rolePrincipal) {
                    principals.add(rolePrincipal);
                }
            }
        }
        if (useUnixGroups) {
            for (String s : username.getGroups()) {
                Principal rolePrincipal = createRolePrincipal(s);
                if (null != rolePrincipal) {
                    principals.add(rolePrincipal);
                }
            }
        }
        return principals;
    }
907177
private function listUserAuthorizedSubdefs(User $user)
    {
        $acl = $this->getAclForUser($user);
        $ret = [];

        foreach ($acl->get_granted_sbas() as $databox) {
            $databoxId = $databox->get_sbas_id();
            $subdefs = $databox->get_subdef_structure();
            foreach ($subdefs as $subGroup) {
                foreach ($subGroup->getIterator() as $sub) {
                    $opt = [];
                    $data = [
                      'name'             => $sub->get_name(),
                      'databox_id'       => $databoxId,
                      'class'            => $sub->get_class(),
                      'preset'           => $sub->get_preset(),
                      'downloadable'     => $sub->isDownloadable(),
                      'devices'          => $sub->getDevices(),
                      'labels'           => [
                        'fr' => $sub->get_label('fr'),
                        'en' => $sub->get_label('en'),
                        'de' => $sub->get_label('de'),
                        'nl' => $sub->get_label('nl'),
                      ],
                    ];
                    $options = $sub->getOptions();
                    foreach ($options as $option) {
                        $opt[$option->getName()] = $option->getValue();
                    }
                    $data['options'] = $opt;
                    $ret[$subGroup->getName()][$sub->get_name()] = $data;
                }
            }
        }

        return $ret;
    }
1299478
def roles_for_user(request, user, project=None, domain=None):
    """"""
    manager = keystoneclient(request, admin=True).roles
    if VERSIONS.active < 3:
        return manager.roles_for_user(user, project)
    else:
        return manager.list(user=user, domain=domain, project=project)
878596
private function getRoles(ApiUserInterface $user)
    {
        $roles = $user->getRoles();
        if ($user->getApiKeyEnabled()) {
            $roles[] = $this->apiUserRole;
        }

        return $roles;
    }
1234972
public Set<Role> findRoles(final User user)
    {
        final Set<Role> result = new HashSet<Role>();
        
        for(final RoleMapping mapping : this.getRoleMappings())
        {
            final Object source = mapping.getSource();
            
            if((user != null) && user.equals(source))
            {
                // TODO: Fix this hardcoding when Restlet implements equals for Role objects again
                RestletUtilRole standardRole = this.getRoleByName(mapping.getTarget().getName());
                if(standardRole != null)
                {
                    result.add(standardRole.getRole());
                }
                else
                {
                    result.add(mapping.getTarget());
                }
            }
        }
        
        return result;
    }
1283261
public static List<Entry> userStructure(User user) {
        List<Entry> entryList = new LinkedList<>();
        entryList.add(namedObject(user.getUsername(), DnFactory.users()));
        entryList.addAll(createCredentialsEntries(user));
        entryList.addAll(createUserAttributesEntries(user));
        return entryList;
    }
121086
private function getUserRolesAsObjects(UserInterface $user)
    {
        $userRoles = array();
        foreach ($user->getRoles() as $userRole) {
            $userRoles[] = $userRole instanceof Role ? $userRole : new Role($userRole);
        }

        return $userRoles;
    }
1215485
public CmsPermissionSetCustom getPermissions(CmsUser user, List<CmsGroup> groups, List<CmsRole> roles) {

        CmsPermissionSetCustom sum = new CmsPermissionSetCustom();
        boolean hasPermissions = false;
        CmsPermissionSet p = m_permissions.get(user.getId());
        if (p != null) {
            sum.addPermissions(p);
            hasPermissions = true;
        }
        if (groups != null) {
            int size = groups.size();
            for (int i = 0; i < size; i++) {
                I_CmsPrincipal principal = groups.get(i);
                p = m_permissions.get(principal.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (roles != null) {
            int size = roles.size();
            for (int i = 0; i < size; i++) {
                CmsRole role = roles.get(i);
                p = m_permissions.get(role.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (!hasPermissions) {
            // if no applicable entry is found check the 'all others' entry
            p = m_permissions.get(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID);
            if (p != null) {
                sum.addPermissions(p);
            }
        }
        return sum;
    }
808701
private List<String> getUsersFor(Collection<String> roles){
		List<String> users = new HashList<>();
		for(String role: roles){
			if(roleMembershipRU.containsKey(role))
				users.addAll(roleMembershipRU.get(role));
		}
		return users;
	}
858226
@Override
	public String[] getUsersInRole(String role) {
		if (role_list.containsKey(role)) {
			return role_list.get(role).toArray(new String[0]);
		} else {
			return new String[0];
		}
	}
326379
public function getAllPermissionsForUser($user)
    {
        $user = $this->resolveUser($user);

        if ( ! $user) {
            return [];
        }

        $permissions = [];

        // Get all permissions for the roles this user belongs to
        foreach ($user->getRoles() as $role) {
            /** @var EloquentRole $role */
            $permissions = array_merge(
                $permissions,
                array_keys(array_filter($role->getPermissions()))
            );
        }

        // Add permissions set specifically for the user
        $permissions = array_merge(
            $permissions,
            array_keys(array_filter($user->getPermissions()))
        );

        sort($permissions);

        return array_unique($permissions);
    }