summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheron Luhn <theron@luhn.com>2019-03-02 11:26:37 -0800
committerTheron Luhn <theron@luhn.com>2019-03-03 08:36:31 -0800
commit140fdbb54c467159313ede564dd3ad4077e30f20 (patch)
tree983ff140220feef7df23d48be1555cc8862cd164
parentaae1c513c0a940c1c31c97b4d79fec3d09cbd01e (diff)
downloadpyramid-140fdbb54c467159313ede564dd3ad4077e30f20.tar.gz
pyramid-140fdbb54c467159313ede564dd3ad4077e30f20.tar.bz2
pyramid-140fdbb54c467159313ede564dd3ad4077e30f20.zip
Implement bw-compat authenticated_userid and unauthenticated_userid
-rw-r--r--src/pyramid/request.py4
-rw-r--r--src/pyramid/security.py20
-rw-r--r--tests/test_security.py12
3 files changed, 29 insertions, 7 deletions
diff --git a/src/pyramid/request.py b/src/pyramid/request.py
index 726f485e7..bb0dcaa2b 100644
--- a/src/pyramid/request.py
+++ b/src/pyramid/request.py
@@ -16,7 +16,9 @@ from pyramid.decorator import reify
from pyramid.i18n import LocalizerRequestMixin
from pyramid.response import Response, _get_response_factory
from pyramid.security import (
- SecurityAPIMixin, AuthenticationAPIMixin, AuthorizationAPIMixin,
+ SecurityAPIMixin,
+ AuthenticationAPIMixin,
+ AuthorizationAPIMixin,
)
from pyramid.url import URLMethodsMixin
from pyramid.util import (
diff --git a/src/pyramid/security.py b/src/pyramid/security.py
index efc0c193c..66e314f79 100644
--- a/src/pyramid/security.py
+++ b/src/pyramid/security.py
@@ -312,10 +312,14 @@ class AuthenticationAPIMixin(object):
Use ``request.identity`` instead.
"""
- policy = _get_authentication_policy(self)
- if policy is None:
+ authn = _get_authentication_policy(self)
+ security = _get_security_policy(self)
+ if authn is not None:
+ return authn.authenticated_userid(self)
+ elif security is not None:
+ return security.identify(self)
+ else:
return None
- return policy.authenticated_userid(self)
@property
def unauthenticated_userid(self):
@@ -332,10 +336,14 @@ class AuthenticationAPIMixin(object):
Use ``request.identity`` instead.
"""
- policy = _get_authentication_policy(self)
- if policy is None:
+ authn = _get_authentication_policy(self)
+ security = _get_security_policy(self)
+ if authn is not None:
+ return authn.unauthenticated_userid(self)
+ elif security is not None:
+ return security.identify(self)
+ else:
return None
- return policy.unauthenticated_userid(self)
@property
def effective_principals(self):
diff --git a/tests/test_security.py b/tests/test_security.py
index 514175a92..dd2c225d3 100644
--- a/tests/test_security.py
+++ b/tests/test_security.py
@@ -369,6 +369,12 @@ class TestAuthenticatedUserId(unittest.TestCase):
def test_with_authentication_policy(self):
request = _makeRequest()
_registerAuthenticationPolicy(request.registry, 'yo')
+ _registerSecurityPolicy(request.registry, 'wat')
+ self.assertEqual(request.authenticated_userid, 'yo')
+
+ def test_with_security_policy(self):
+ request = _makeRequest()
+ _registerSecurityPolicy(request.registry, 'yo')
self.assertEqual(request.authenticated_userid, 'yo')
def test_with_authentication_policy_no_reg_on_request(self):
@@ -395,6 +401,12 @@ class TestUnAuthenticatedUserId(unittest.TestCase):
def test_with_authentication_policy(self):
request = _makeRequest()
_registerAuthenticationPolicy(request.registry, 'yo')
+ _registerSecurityPolicy(request.registry, 'wat')
+ self.assertEqual(request.unauthenticated_userid, 'yo')
+
+ def test_with_security_policy(self):
+ request = _makeRequest()
+ _registerSecurityPolicy(request.registry, 'yo')
self.assertEqual(request.unauthenticated_userid, 'yo')
def test_with_authentication_policy_no_reg_on_request(self):