57. PYRAMID.SECURITY
from pyramid.security import forget headers = forget(request) response.headerlist.extend(headers) return response
If no authentication policy is in use, this function will always return an empty sequence.
remember(request, principal, **kw)
Return a sequence of header tuples (e.g. [(’Set-Cookie’, ’foo=abc’)]) suitable for ‘remembering’ a set of credentials implied by the data passed as principal and *kw using the current authentication policy. Common usage might look like so within the body of a view function (response is assumed to be a WebOb -style response object computed previously by the view code):
from pyramid.security import remember
headers = remember(request, ’chrism’, password=’123’, max_age=’86400’) response.headerlist.extend(headers)
return response
If no authentication policy is in use, this function will always return an empty sequence. If used, the composition and meaning of **kw must be agreed upon by the calling code and the effective authentication policy.
57.2 Authorization API Functions
has_permission(permission, context, request)
Provided a permission (a string or unicode object), a context (a resource instance) and a request object, return an instance of pyramid.security.Allowed if the permission is granted in this context to the user implied by the request. Return an instance of pyramid.security.Denied if this permission is not granted in this context to this user. This function delegates to the current authentication and authorization policies. Return pyramid.security.Allowed unconditionally if no authentication policy has been configured in this application.
principals_allowed_by_permission(context, permission)
Provided a context (a resource object), and a permission (a string or unicode object), if a authorization policy is in effect, return a sequence of principal ids that possess the permission in the context. If no authorization policy is in effect, this will return a sequence with the single value pyramid.security.Everyone (the special principal identifier representing all principals).