diff options
| author | Michael Merickel <michael@merickel.org> | 2020-01-07 23:48:51 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2020-01-09 23:43:19 -0600 |
| commit | 7adc44fa2b4bfa5b4230d8646e734ba262ec1ce2 (patch) | |
| tree | d3859ecceb465c41433197e0deaebe9b712a982e /docs/tutorials/wiki2/src/authorization | |
| parent | 68c1929bbfec92f3fff1985226d88f41b02e5a4f (diff) | |
| download | pyramid-7adc44fa2b4bfa5b4230d8646e734ba262ec1ce2.tar.gz pyramid-7adc44fa2b4bfa5b4230d8646e734ba262ec1ce2.tar.bz2 pyramid-7adc44fa2b4bfa5b4230d8646e734ba262ec1ce2.zip | |
demonstrate an identity_cache
Diffstat (limited to 'docs/tutorials/wiki2/src/authorization')
| -rw-r--r-- | docs/tutorials/wiki2/src/authorization/tutorial/security.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/docs/tutorials/wiki2/src/authorization/tutorial/security.py b/docs/tutorials/wiki2/src/authorization/tutorial/security.py index 448183c95..7a99fb9e9 100644 --- a/docs/tutorials/wiki2/src/authorization/tutorial/security.py +++ b/docs/tutorials/wiki2/src/authorization/tutorial/security.py @@ -1,6 +1,7 @@ from pyramid.authentication import AuthTktCookieHelper from pyramid.authorization import ACLHelper from pyramid.csrf import CookieCSRFStoragePolicy +from pyramid.request import RequestLocalCache from pyramid.security import ( Authenticated, Everyone, @@ -12,9 +13,10 @@ from . import models class MySecurityPolicy: def __init__(self, secret): self.authtkt = AuthTktCookieHelper(secret) + self.identity_cache = RequestLocalCache(self.load_identity) self.acl = ACLHelper() - def authenticated_identity(self, request): + def load_identity(self, request): identity = self.authtkt.identify(request) if identity is None: return None @@ -23,6 +25,9 @@ class MySecurityPolicy: user = request.dbsession.query(models.User).get(userid) return user + def authenticated_identity(self, request): + return self.identity_cache.get_or_create(request) + def authenticated_userid(self, request): user = self.authenticated_identity(request) if user is not None: |
