Adds roles to the Subject object.

@param subject
the subject that was returned from authentication.
@param userRoles
the set of user roles that were found.
428975
private void addRolesToSubject(Subject subject, Set<String> userRoles) {
        if (userRoles == null) {
            userRoles = Collections.emptySet();
        }

        Map<String, Set<String>> attributes =
                SubjectUtils.getAttributes(subject);

        Set<String> roles = attributes.get(ROLE_KEY);
        if (roles == null) {
            roles = new HashSet<String>(userRoles);
            attributes.put(ROLE_KEY, roles);
        } else {
            roles.addAll(userRoles);
        }
        if (logger.isDebugEnabled()) {
            for (String role : userRoles) {
                logger.debug("added role: {}", role);
            }
        }
    }
605882
public void setRoles(java.util.Collection<PermissionInfo> roles) {
        if (roles == null) {
            this.roles = null;
            return;
        }

        this.roles = new java.util.ArrayList<PermissionInfo>(roles);
    }
515552
@Override
    public void addRoles(final Collection<String> roles) {
        CommonHelper.assertNotNull("roles", roles);
        this.roles.addAll(roles);
    }
784305
private void setSubjectPrincipals() {
        if (null != userPrincipal) {
            this.subject.getPrincipals().add(userPrincipal);
        }
        if (null != rolePrincipals) {
            for (Principal rolePrincipal : rolePrincipals) {
                this.subject.getPrincipals().add(rolePrincipal);
            }
        }
    }
177802
public Set<Role> findRoles(final User user)
    {
        final Set<Role> result = new HashSet<Role>();
        
        Object source;
        for(final RoleMapping mapping : this.getRoleMappings())
        {
            source = mapping.getSource();
            
            if((user != null) && user.equals(source))
            {
                result.add(mapping.getTarget());
            }
        }
        
        return result;
    }
65737
@Override
    public boolean isUserInRole(String role, IExtendedRequest req) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "isUserInRole role = " + role);
        }

        if (role == null)
            return false;
        Subject subject = subjectManager.getCallerSubject();
        if (subject == null) {
            return false;
        }

        return wasch.isUserInRole(role, req, subject);

    }
1139957
public Authorizations setRoles(Set<Role> roles) {
        this.roles.clear();
        this.aggregatePermissions = null;
        addRoles(roles);

        return this;
    }
785975
def add_user_role(self, user, role):
        
        self.service.add_user_role(
            user, role,
            self.url_prefix, self.auth, self.session, self.session_send_opts)
1187929
private Set<String> getUserRoles(Subject subject) {
        Set<String> userRoles = null;

        // get roles from specified classes
        Set<Principal> principals = subject.getPrincipals();
        if (roleClassNames != null && roleClassNames.size() > 0) {
            for (Principal p : principals) {
                if (roleClassNames.contains(p.getClass().getName())) {
                    if (userRoles == null) userRoles = new HashSet<String>();
                    userRoles.add(p.getName());
                }
            }
        }

        // get roles from specified attributes
        Map<String, Set<String>> attributes =
                SubjectUtils.getAttributes(subject);
        for (String key : attributes.keySet()) {
            if (roleAttributeNames.contains(key)) {
                if (userRoles == null) userRoles = new HashSet<String>();
                userRoles.addAll(attributes.get(key));
            }
        }

        if (userRoles == null) userRoles = Collections.emptySet();
        if (logger.isDebugEnabled()) {
            for (String r : userRoles) {
                logger.debug("found role: {}", r);
            }
        }

        return userRoles;
    }
341813
public static void addCommerceAccountUserRels(long commerceAccountId,
		long[] userIds, String[] emailAddresses, long[] roleIds,
		com.liferay.portal.kernel.service.ServiceContext serviceContext)
		throws com.liferay.portal.kernel.exception.PortalException {
		getService()
			.addCommerceAccountUserRels(commerceAccountId, userIds,
			emailAddresses, roleIds, serviceContext);
	}
890171
public ServerUpdater addRolesToUser(User user, Collection<Role> roles) {
        delegate.addRolesToUser(user, roles);
        return this;
    }
602312
@CommandArgument
  public void addroles(
      @OptionArgument("username") String username,
      @OptionArgument("roles") String roles) {

    User user = users.get(username);

    if (user != null) {
      user.roles.addAll(Arrays.asList(roles.split(",")));
    } else {
      System.err.println(String.format("User '%s' does not exist", username));
    }

  }
1308777
protected void addAllUsersToRole(Set<String> users, String role) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            SibTr.entry(tc, CLASS_NAME + "addAllUsersToRole", new Object[] { users, role });
        }
        Set<String> usersForTheRole = roleToUserMap.get(role);
        if (usersForTheRole != null) {
            usersForTheRole.addAll(users);
        } else {
            usersForTheRole = users;
        }
        roleToUserMap.put(role, usersForTheRole);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            SibTr.exit(tc, CLASS_NAME + "addAllUsersToRole");
        }
    }
1127422
def add_role_to_user(self, user, role):
        
        user, role = self._prepare_role_modify_args(user, role)
        if role not in user.roles:
            user.roles.append(role)
            self.put(user)
            return True
        return False
957378
public void addUserToRole(CmsObject cms, CmsRole role, String username) throws CmsException {

        m_securityManager.addUserToGroup(cms.getRequestContext(), username, role.getGroupName(), true);
    }
960266
public void addSubject(String[] subject) {
		XmpArray array = new XmpArray(XmpArray.UNORDERED);
		for (int i = 0; i < subject.length; i++) {
			array.add(subject[i]);
		}
		setProperty(SUBJECT, array);
	}
692908
public function addSubjectPrefix($subjectPrefix, $roles)
    {
        if (!is_array($roles)) {
            $roles = array($roles);
        }
        if (is_array($subjectPrefix)) {
            foreach ($subjectPrefix as $oneSubjectPrefix) {
                $this->addSubjectPrefix($oneSubjectPrefix, $roles);
            }
        } else {
            if (isset($this->subjectPrefixes[$subjectPrefix])) {
                $this->subjectPrefixes[$subjectPrefix] = array_values(array_unique(array_merge(
                            $this->subjectPrefixes[$subjectPrefix], $roles)));
            } else {
                $this->subjectPrefixes[$subjectPrefix] = $roles;
            }
        }
        return $this;
    }