Checks that a basis set role exists and if not, raises a helpful exception
181333
def _cli_check_role(role):
    ''''''

    if role is None:
        return None

    role = role.lower()
    if not role in api.get_roles():
        errstr = "Role format '" + role + "' does not exist.\n"
        errstr += "For a complete list of roles, use the 'bse list-roles' command"
        raise RuntimeError(errstr)

    return role
36969
def role_exists(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    try:
        conn.get_role(name)
        return True
    except boto.exception.BotoServerError:
        return False
1071589
def __raise_file_system_exception(self, item, directory):
        

        path = os.path.join(directory, item)
        if os.path.isfile(path):
            raise foundations.exceptions.FileExistsError(
                "{0} | A file with '{1}' name already exists in '{2}' directory!".format(self.__class__.__name__,
                                                                                         item,
                                                                                         directory))
        else:
            raise foundations.exceptions.DirectoryExistsError(
                "{0} | A directory with '{1}' name already exists in '{2}' directory!".format(self.__class__.__name__,
                                                                                              item,
                                                                                              directory))
148891
def check_permission(cls, role, permission):
        
        result = permission in settings.ARCTIC_ROLES[role]
        # will try to call a method with the same name as the permission
        # to enable an object level permission check.
        if result:
            try:
                return getattr(cls, permission)(role)
            except AttributeError:
                pass
        return result
750095
def has_role(self, role):
        
        if isinstance(role, str):
            return role in (role.name for role in self.roles)
        else:
            return role in self.roles
54429
def roles_required(*required_rolenames):
    
    def decorator(method):
        @functools.wraps(method)
        def wrapper(*args, **kwargs):
            role_set = set([str(n) for n in required_rolenames])
            _verify_and_add_jwt()
            try:
                MissingRoleError.require_condition(
                    current_rolenames().issuperset(role_set),
                    "This endpoint requires all the following roles: {}",
                    [', '.join(role_set)],
                )
                return method(*args, **kwargs)
            finally:
                remove_jwt_data_from_app_context()
        return wrapper
    return decorator
1284947
def assert_or_raise(stmt: bool, exception: Exception,
                    *exception_args, **exception_kwargs) -> None:
  
  if not stmt:
    raise exception(*exception_args, **exception_kwargs)
530674
public static boolean hasRole(String roleName) {
        return getSubject() != null && roleName != null
                && roleName.length() > 0 && getSubject().hasRole(roleName);
    }
896112
def _check_role(self):
        
        role = u'any'
        if 'role' in self.lti_kwargs:
            role = self.lti_kwargs['role']
        log.debug(
            "check_role lti_role=%s decorator_role=%s", self.role, role
        )
        if not (role == u'any' or self.is_role(self, role)):
            raise LTIRoleException('Not authorized.')
1374301
private void verifyPermissionToGrantRoles(Subject subject, Iterable<RoleIdentifier> roleIds) {
        Set<RoleIdentifier> unauthorizedIds = Sets.newTreeSet();
        boolean anyAuthorized = false;

        for (RoleIdentifier roleId : roleIds) {
            // Verify the caller has permission to grant this role
            if (subject.hasPermission(Permissions.grantRole(roleId))) {
                anyAuthorized = true;
            } else {
                unauthorizedIds.add(roleId);
            }
        }

        if (!unauthorizedIds.isEmpty()) {
            // If the caller was not authorized to assign any of the provided roles raise a generic exception, otherwise
            // the exception provides insight as to which roles were unauthorized.  This provides some helpful feedback
            // where appropriate without exposing potentially exploitable information about whether the subject's API key
            // is valid.
            if (!anyAuthorized) {
                throw new UnauthorizedException();
            } else {
                throw new UnauthorizedException("Not authorized for roles: " + Joiner.on(", ").join(unauthorizedIds));
            }
        }
    }
825337
@Override
	public boolean isUserInRole(String role) {
		boolean inRole = false;

		Authentication authentication = getAuthentication();
		if (authentication != null) {
			Collection<? extends GrantedAuthority> authorities = authentication
					.getAuthorities();
			for (GrantedAuthority authority : authorities) {
				if (role.equals(authority.getAuthority())) {
					inRole = true;
					break;
				}
			}
		}
		return inRole;
	}
1272666
def make_valid_role role
      raise ArgumentError, "Role to set must be a Symbol or String" if !role.kind_of_label?
      check_valid_role? role.to_s.alpha_numeric
    end
1044110
def has_role(self, role_s):
        
        if self.authorized:
            return self.security_manager.has_role(self.identifiers, role_s)
        msg = 'Cannot check permission when identifiers aren\'t set!'
        raise ValueError(msg)
12937
def user_exists(name,
                user=None, host=None, port=None, maintenance_db=None,
                password=None,
                runas=None):
    '''
    
    '''
    return bool(
        role_get(name,
                 user=user,
                 host=host,
                 port=port,
                 maintenance_db=maintenance_db,
                 password=password,
                 runas=runas,
                 return_password=False))
999327
@Override
    public boolean isUserInRole(String role) {
        if (userRoles == null) {
            return false;
        }

        return userRoles.contains(role);
    }
282324
function hasRole(roleRequired) {
  if (!roleRequired) {
    throw new Error('Required role needs to be set');
  }

  return compose()
    .use(isAuthenticated())
    .use(function meetsRequirements(req, res, next) {
      if (roles.hasRole(req.userInfo.role, roleRequired)) {
        next();
      } else {
        res.forbidden();
      }
    });
}
696778
public boolean isUserInRole(String role) {
        for (String assRole : getRoles()) {
            if (assRole.equalsIgnoreCase(role)) {
                return true;
            }
        }
        return false;
    }