Decorator used to check permissions before to call resource manager method
165221
def has_permission(self, *args, **kwargs):
        """"""
        def wrapper(view):
            if getattr(view, '_has_permissions_decorator', False) is True:
                return view

            @wraps(view)
            @jsonapi_exception_formatter
            def decorated(*view_args, **view_kwargs):
                self.check_permissions(view, view_args, view_kwargs, *args, **kwargs)
                return view(*view_args, **view_kwargs)
            decorated._has_permissions_decorator = True
            return decorated
        return wrapper
185031
def _call_resource_method(self, cls, id, method_name, data):
        """"""

        if cls.api_root != "a":
            url_path = "/{name}/{id}/{method}".format(
                name=cls.collection_name, id=id, method=method_name
            )
        else:
            # Management method.
            url_path = "/a/{app_id}/{name}/{id}/{method}".format(
                app_id=self.app_id, name=cls.collection_name, id=id, method=method_name
            )

        url = URLObject(self.api_server).with_path(url_path)
        converted_data = convert_datetimes_to_timestamps(data, cls.datetime_attrs)

        session = self._get_http_session(cls.api_root)
        response = session.post(url, json=converted_data)

        result = _validate(response).json()
        return cls.create(self, **result)
417219
def get_permission(self, service, func):
        
        if self.permission:
            perm = self.permission

        elif self.prefix is False:
            # No permission will be checked
            perm = False

        elif self.prefix:
            perm = build_permission_name(service.model_class, self.prefix)

        else:
            name = func.__name__
            # check if there is a translation between default permission and method name
            action_name = METHOD_PERMISSION_TRANSLATION.get(name, name)

            perm = build_permission_name(service.model_class, action_name)
        return perm
936716
def callwith(context_manager):
    
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwds):
            with context_manager:
                return func(*args, **kwds)
        return wrapper
    return decorator
1319820
def add_permission(self, resource, operation):
        ''''''
        if isclass(resource):
            model_type = resource
            pk = ''
        else:
            model_type = resource.__class__
            pk = resource.pkvalue()
        p = Permission(model_type=model_type, object_pk=pk,
                       operation=operation)
        session = self.session
        if session.transaction:
            session.add(p)
            self.permissions.add(p)
            return p
        else:
            with session.begin() as t:
                t.add(p)
                self.permissions.add(p)
            return t.add_callback(lambda r: p)
851141
def oauth_manager(self, oauth_manager):
        
        @self.app.before_request
        def before_request():
            endpoint = request.endpoint
            resource = self.app.view_functions[endpoint].view_class

            if not getattr(resource, 'disable_oauth'):
                scopes = request.args.get('scopes')

                if getattr(resource, 'schema'):
                    scopes = [self.build_scope(resource, request.method)]
                elif scopes:
                    scopes = scopes.split(',')

                    if scopes:
                        scopes = scopes.split(',')

                valid, req = oauth_manager.verify_request(scopes)

                for func in oauth_manager._after_request_funcs:
                    valid, req = func(valid, req)

                if not valid:
                    if oauth_manager._invalid_response:
                        return oauth_manager._invalid_response(req)
                    return abort(401)

                request.oauth = req
339126
@Override
	public void checkPermission(String resourceName, String action) throws JMSException 
	{
		for (int i = 0; i < privileges.size(); i++)
		{
			Privilege privilege = privileges.get(i);
			if (privilege.matches(resourceName, action))
				return;
		}
		throw new FFMQException("Access denied to resource '"+resourceName+"' for action '"+action+"'","ACCESS_DENIED");
	}
284908
def lock_host(func, *args, **kwargs):
    
    def inner(self, *args, **kwargs):
        self.host_lock.acquire()
        try:
            res = func(self, *args, **kwargs)
            self.host_lock.release()
        except Exception as e:
            self.host_lock.release()
            raise e
        return res
    return inner
1367881
def get_permissions(self):
        """"""
        permissions = set()
        permissions.update(self.resource_manager.get_permissions())
        for f in self.resource_manager.filters:
            permissions.update(f.get_permissions())
        for a in self.resource_manager.actions:
            permissions.update(a.get_permissions())
        return permissions
647394
def authenticated_users(func):
    
    is_object_permission = "has_object" in func.__name__

    @wraps(func)
    def func_wrapper(*args, **kwargs):
        request = args[0]
        # use second parameter if object permission
        if is_object_permission:
            request = args[1]

        if not(request.user and request.user.is_authenticated):
            return False

        return func(*args, **kwargs)

    return func_wrapper
346237
def filer_has_permission(context, item, action):
    
    permission_method_name = 'has_{action}_permission'.format(action=action)
    permission_method = getattr(item, permission_method_name, None)
    request = context.get('request')

    if not permission_method or not request:
        return False
    # Call the permission method.
    # This amounts to calling `item.has_X_permission(request)`
    return permission_method(request)
415653
def check_permission(*permissions, **args_map):
    
    def f1(func, permissions=permissions):
        @wraps(func)
        def f2(*args, **kwargs):
            from uliweb import request, error

            arguments = {}
            for k, v in args_map.items():
                if v in kwargs:
                    arguments[k] = kwargs[v]
            if not has_permission(request.user, *permissions, **arguments):
                error(_("You have no permissions to visit this page."))
            return func(*args, **kwargs)
        return f2
    return f1
1275747
def group_required(self, group):
        

        def decorator(view):
            @functools.wraps(view)
            def decorated(*args, **kwargs):
                log.info("Trying to get access to resource: %s protected by group: %s", view.__name__, group)
                if request.method == 'POST':
                    token = request.form['token']
                    if self.development or self.group_authenticated(token, group):
                        return view(*args, **kwargs)
                    else:
                        log.warning("User has not been authorized to get access to resource: %s", view.__name__)
                else:
                    log.error("Bad request type! Expected 'POST', actual '%s'", request.method)

                return abort(403)

            return decorated
        return decorator
152220
def require(self, lock, guard_func, *guard_args, **guard_kw):
        
        def decorator(f):
            @wraps(f)
            def wrapper(*args, **kw):
                if self.granted(lock):
                    self.msg('Granted {}'.format(lock))
                    return f(*args, **kw)
                if guard_func(*guard_args, **guard_kw) and self.acquire(lock):
                    return f(*args, **kw)
                return None
            return wrapper
        return decorator
740809
def SecurityCheck(func):
  """"""

  def Wrapper(request, *args, **kwargs):
    """Wrapping function."""
    if WEBAUTH_MANAGER is None:
      raise RuntimeError("Attempt to initialize before WEBAUTH_MANAGER set.")
    return WEBAUTH_MANAGER.SecurityCheck(func, request, *args, **kwargs)

  return Wrapper
460407
def permission_set(self, name, func=None):
        
        if func is None:
            return functools.partial(self.predicate, name)
        self.permission_sets[name] = func
        return func
74452
def ensure_permissions(mode_flags=stat.S_IWUSR):
    

    def decorator(f):
        def modify(filename, *args, **kwargs):
            m = chmod_perms(filename) if exists(filename) else mode_flags
            if not m & mode_flags:
                os.chmod(filename, m | mode_flags)
            try:
                return f(filename, *args, **kwargs)
            finally:
                # restore original permissions
                if not m & mode_flags:
                    os.chmod(filename, m)
        return modify

    return decorator