金字塔中的授权失败(Python)
authorisation failure in Pyramid (Python)
所以我正在尝试将一些旧的 Pylons 代码移植到 Pyramid,我希望能够改进 Auth 设置——特别是支持更好的 RBAC,而 Pyramid 对此有很好的支持。
但是,当未经授权的用户尝试访问非法页面时,我想为他们提供更好的信息:
“抱歉,您([用户])需要[组]权限才能查看[页面] - 请联系[管理员]”
但是我看不出这在 Pyramid 中如何实用 - 我可以在 forbidden_view_config 页面中做一些事情,但是我无法从尝试的页面中轻松找到所需的所有信息 - 是吗可能会得到异常或与未授予权限的实际原因类似的异常?
request 对象本身应具有您需要的所有位。
具体来说,security-related pieces lists some of the request attributes that you can retrieve. Also the request.exception
attribute will be available when an exception is raised. There are several URL-related pieces available to get the "page", including application_url
.
所以我正在尝试将一些旧的 Pylons 代码移植到 Pyramid,我希望能够改进 Auth 设置——特别是支持更好的 RBAC,而 Pyramid 对此有很好的支持。 但是,当未经授权的用户尝试访问非法页面时,我想为他们提供更好的信息:
“抱歉,您([用户])需要[组]权限才能查看[页面] - 请联系[管理员]”
但是我看不出这在 Pyramid 中如何实用 - 我可以在 forbidden_view_config 页面中做一些事情,但是我无法从尝试的页面中轻松找到所需的所有信息 - 是吗可能会得到异常或与未授予权限的实际原因类似的异常?
request 对象本身应具有您需要的所有位。
具体来说,security-related pieces lists some of the request attributes that you can retrieve. Also the request.exception
attribute will be available when an exception is raised. There are several URL-related pieces available to get the "page", including application_url
.