Middleware the ensures that the user either has a good enough role or is trying to get information
about themselves.
@param role
@returns {Function}
485695
function roleOrSelf (role) {
        if (!_.isNumber(role)) {
            role = roles[role.toUpperCase()];
        }

        return function validateRoleOrSelf (kontx, next) {
            var userPrivLevel = roles[kontx.user.role.toUpperCase()],
                passedInUserId = kontx.args[0],
                err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);

            //If user object passed in instead of a string then parse.
            if (!_.isUndefined(kontx.args[0]._id)) {
                passedInUserId = kontx.args[0]._id;
            }

            //If user has enough priviliges then keep going
            if (userPrivLevel <= parseInt(role, 10) || kontx.user._id.toString() === passedInUserId.toString()) {
                next();
                return;
            }

            next(err);
        };
    }
19629
public boolean isUserInRole(String role)
    {
        if (_servletHolder!=null)
            role=_servletHolder.getUserRoleLink(role);
        return _httpRequest.isUserInRole(role);
    }
410981
def get_role(self, role):
        
        role = AuthGroup.objects(role=role, creator=self.client).first()
        return role
116018
function authorize(req, res, next) {
  const role = findRoleFromRequest(
    req,
    options.roleSearchPath,
    options.defaultRole,
    options.decodedObjectName
  );

  if (req.originalUrl === '/') {
    return next();
  }

  const policy = options.policies.get(role);

  if (!policy) {
    return res.status(403).json({
      status: 'Access denied',
      success: false,
      message: `REQUIRED: Policy for role ${role} is not defined`
    });
  }

  const permission = findPermissionForRoute(
    req.originalUrl,
    req.method,
    options.baseUrl,
    policy
  );

  if (!permission) {
    if (typeof options.denyCallback === 'function') {
      return options.denyCallback(res);
    }
    return res.status(403).json(deny(options.customMessage, options.response));
  }

  return checkIfHasAccess(
    req.method,
    res,
    next,
    permission,
    options.customMessage,
    options.response,
    options.denyCallback
  );
}
224049
def get_single_role(self, id, role_id, account_id, role=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - id
        """ID"""
        path["id"] = id

        # REQUIRED - PATH - account_id
        """The id of the account containing the role"""
        path["account_id"] = account_id

        # REQUIRED - role_id
        """The unique identifier for the role"""
        params["role_id"] = role_id

        # OPTIONAL - role
        """The name for the role"""
        if role is not None:
            params["role"] = role

        self.logger.debug("GET /api/v1/accounts/{account_id}/roles/{id} with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("GET", "/api/v1/accounts/{account_id}/roles/{id}".format(**path), data=data, params=params, single_item=True)
713193
def role_search(auth=None, **kwargs):
    '''
    
    '''
    cloud = get_operator_cloud(auth)
    kwargs = _clean_kwargs(**kwargs)
    return cloud.search_roles(**kwargs)
901487
function translateRole(role) {
    switch (role) {
        case "5615fa9ae596154a5c000000":
            return Types.UserRole.COOWNER;
        case "5615fd84e596150061000003":
            return Types.UserRole.MANAGER;
        case "52d1ce33c38a06510c000001":
            return Types.UserRole.MOD;
        case "5615fe1ee596154fc2000001":
            return Types.UserRole.VIP;
        case "5615feb8e596154fc2000002":
            return Types.UserRole.RESIDENT_DJ;
        case "564435423f6ba174d2000001":
            return Types.UserRole.DJ;
        default:
            return Types.UserRole.NONE;
    }
}
244512
def get_role_policy(role_name, policy_name, region=None, key=None,
                    keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        _policy = conn.get_role_policy(role_name, policy_name)
        # I _hate_ you for not giving me an object boto.
        _policy = _policy.get_role_policy_response.policy_document
        # Policy is url encoded
        _policy = _unquote(_policy)
        _policy = salt.utils.json.loads(_policy, object_pairs_hook=odict.OrderedDict)
        return _policy
    except boto.exception.BotoServerError:
        return {}
333529
function hasRole(role) {
    role = isArray(role) ? role : [role];
    return 0 < intersection(role, userBuiltInStore.getRoles()).length;
}
999327
@Override
    public boolean isUserInRole(String role) {
        if (userRoles == null) {
            return false;
        }

        return userRoles.contains(role);
    }
696778
public boolean isUserInRole(String role) {
        for (String assRole : getRoles()) {
            if (assRole.equalsIgnoreCase(role)) {
                return true;
            }
        }
        return false;
    }
933986
def get_role(self, key):
        """"""

        json_resp = self.get_roles()
        for item in json_resp:
            if key in item["name"]:
                return item["id"]
        raise CerberusClientException("Key '%s' not found" % key)
1023868
def role(id)
      id = id.resolve_id
      @roles.find { |e| e.id == id }
    end
505524
def role_present(name, profile=None, **connection_args):
    ''''
    
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': 'Role "{0}" already exists'.format(name)}

    # Check if role is already present
    role = __salt__['keystone.role_get'](name=name, profile=profile,
                                         **connection_args)

    if 'Error' not in role:
        return ret
    else:
        if __opts__.get('test'):
            ret['result'] = None
            ret['comment'] = 'Role "{0}" will be added'.format(name)
            return ret
        # Create role
        __salt__['keystone.role_create'](name, profile=profile,
                                         **connection_args)
        ret['comment'] = 'Role "{0}" has been added'.format(name)
        ret['changes']['Role'] = 'Created'
    return ret
912769
public java.lang.String getRole() {
    java.lang.Object ref = role_;
    if (ref instanceof java.lang.String) {
      return (java.lang.String) ref;
    } else {
      com.google.protobuf.ByteString bs = 
          (com.google.protobuf.ByteString) ref;
      java.lang.String s = bs.toStringUtf8();
      role_ = s;
      return s;
    }
  }
1181594
function(session) {
        if (session && session.user) {
            if (session.user.roles)
                return { roles: session.user.roles };
            return { roles: "user" };
        }
        return { roles: "public" };
    }
624041
def do_start_role(self, role):
        
        if not role:
            return None

        if not self.has_cluster():
            return None

        if '-' not in role:
            print("Please enter a valid role name")
            return None

        try:
            service = api.get_cluster(self.cluster).get_service(role.split('-')[0])
            service.start_roles(role)
            print("Starting Role")
        except ApiException:
            print("Error: Role or Service Not Found")