diff options
| author | Theron Luhn <theron@luhn.com> | 2019-12-16 17:30:43 -0800 |
|---|---|---|
| committer | Theron Luhn <theron@luhn.com> | 2019-12-16 17:30:43 -0800 |
| commit | 918155824ec9bdd8f7a08c1b0a3e0c56720e9f41 (patch) | |
| tree | 6298cb169941a97f5ccf74d13105a964eab083cd /docs/narr | |
| parent | 03069ff0845c1b85c21119985e8157d54e7ce71c (diff) | |
| download | pyramid-918155824ec9bdd8f7a08c1b0a3e0c56720e9f41.tar.gz pyramid-918155824ec9bdd8f7a08c1b0a3e0c56720e9f41.tar.bz2 pyramid-918155824ec9bdd8f7a08c1b0a3e0c56720e9f41.zip | |
Update docs/narr/security.rst code examples.
Diffstat (limited to 'docs/narr')
| -rw-r--r-- | docs/narr/security.rst | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/docs/narr/security.rst b/docs/narr/security.rst index 60be067bf..50eeab27b 100644 --- a/docs/narr/security.rst +++ b/docs/narr/security.rst @@ -69,21 +69,20 @@ A simple security policy might look like the following: from pyramid.security import Allowed, Denied class SessionSecurityPolicy: - def authenticated_userid(self, request): - """ Return a string ID for the user. """ - userid = self.identify(request).id - if validate_userid(request, userid): - return userid - else: - return None - def identify(self, request): """ Return app-specific user object. """ - userid = self.authenticated_userid + userid = request.session.get('userid') if userid is None: return None return load_identity_from_db(request, userid) + def authenticated_userid(self, request): + """ Return a string ID for the user. """ + identity = request.authenticated_identity + if identity is None: + return None + return string(identity.id) + def permits(self, request, context, permission): """ Allow access to everything if signed in. """ identity = self.identify(request) @@ -145,19 +144,20 @@ For example, our above security policy can leverage these helpers like so: def __init__(self): self.helper = SessionAuthenticationHelper() - def authenticated_userid(self, request): - userid = self.helper.authenticated_userid(request) - if validate_userid(request, userid): - return userid - else: - return None - def identify(self, request): - userid = self.authenticated_userid + """ Return app-specific user object. """ + userid = self.helper.authenticated_userid(request) if userid is None: return None return load_identity_from_db(request, userid) + def authenticated_userid(self, request): + """ Return a string ID for the user. """ + identity = request.authenticated_identity + if identity is None: + return None + return str(identity.id) + def permits(self, request, context, permission): """ Allow access to everything if signed in. """ identity = self.identify(request) |
