Created
October 29, 2013 04:02
-
-
Save digitalresistor/7209017 to your computer and use it in GitHub Desktop.
Mah auth policy for Pyramid =)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let it be known that this code was written by the very awesome and talented @mmerickel | |
# | |
# Thanks! Much appreciated. | |
class BertsAuthPolicyMakerFactoryConfig(object): | |
def __init__(self, policy_factory, attr='auth_policy'): | |
self.policy_factory = policy_factory | |
self.attr = attr | |
def _get_policy(self, request): | |
policy = getattr(request, self.attr, None) | |
if policy is None: | |
policy = self.policy_factory(request) | |
setattr(request, self.attr, policy) | |
return policy | |
def unauthenticated_userid(self, request): | |
return self._get_policy(request).unauthenticated_userid | |
def authenticated_userid(self, request): | |
return self._get_policy(request).authenticated_userid | |
def effective_principals(self, request): | |
return self._get_policy(request).effective_principals | |
def BertsSuperCoolAuthPolicyFactory(object): | |
def __init__(self, request): | |
self.request = request | |
@property | |
def unauthenticated_userid(self): | |
return 42 | |
@property | |
def authenticated_userid(self): | |
return self.unauthenticated_userid | |
@property | |
def effective_principals(self): | |
return [Everyone] | |
auth_policy = BertsAuthPolicyMakerFactoryConfig(BertsSuperCoolAuthPolicyFactory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment