python - Pyramid :ACL 中的 ACE 顺序

标签 python pyramid

我想允许未经过身份验证的用户获得权限,但拒绝经过身份验证的用户。

# works
__acl__ = [
    (Deny, Authenticated, 'something'),
    (Allow, Everyone, 'something'),
]

# order changed -- DOES NOT WORK
__acl__ = [
    (Allow, Everyone, 'something'),
    (Deny, Authenticated, 'something'),
]

我的问题是:这是从经过身份验证的用户中过滤掉未经身份验证的用户的正确方法吗?在 Pyramid 中是否有更明确的方法来做到这一点?我如何通过说 NonAuthenticated(即 Everyone - Authenticated)来描述未经身份验证的用户。

一个更一般的问题是:我们应该如何过滤属于一组但不属于另一组的用户?

最佳答案

AuthenticatedEveryone 是主体(实际上,它们只是字符串)。每个用户都有一个主体列表(默认情况下,[username, Authenticated, Everyone] 用于经过身份验证的用户,[Everyone] 用于其他用户)。您不能对主体执行集成操作,因此无法定义从 EveryoneAuthenticated 计算的 NonAuthenticated

您可以做的是使用 ACL 的顺序来说明您想要的内容。 documentation提到ACL是按顺序处理的,第一个匹配到用户principal的就是user。因此,如果您想要授予 A 组中的用户访问权限,除非他们在 B 组中(主体是“group:A”,但不是“group:B”),您可以这样写。

__acl__ = [
    (Deny, 'group:B', 'something'),   # If user in B, deny
    (Allow, 'group:A', 'something'),  # Else (=if user not in B), if user in A, allow
    (Deny, Everyone, 'something'),    # Else, Deny
]

关于python - Pyramid :ACL 中的 ACE 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15565024/

相关文章:

Python - 没有名为“fabric.api”的模块 - Windows 10

Python:在for循环中写入CSV,有条件地在特定列中添加值

python - 具有多个 GPU 的 MNIST CNN 精度较低

timeout - 覆盖 Pyramid/gunicorn 中的请求超时

python - 使用 Pyramid、nginx、X-Accel-Redirect Header 提供 pdf 作为下载

python - 使用 time.sleep() 时可以在 python 中执行其他任务吗?

python - 可以从 Python 列表理解中捕获返回值以使用条件吗?

python - Pyramid 插件(主题、 View 等)

python - 使用 pystache 渲染多个文件

python - iOS分块上传