From d2d20b92158088e7d646393733092e67120058f0 Mon Sep 17 00:00:00 2001 From: Theron Luhn Date: Sun, 21 Jul 2019 09:20:44 -0700 Subject: Un-deprecate authenticated_userid. --- src/pyramid/interfaces.py | 4 ++-- src/pyramid/security.py | 52 +++++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/pyramid/interfaces.py b/src/pyramid/interfaces.py index 06ab1c32e..d97c3811b 100644 --- a/src/pyramid/interfaces.py +++ b/src/pyramid/interfaces.py @@ -485,8 +485,8 @@ class IViewMapperFactory(Interface): class ISecurityPolicy(Interface): def identify(request): """ Return an object identifying a trusted and verified user. This - object may be anything, but should implement a ``__str__`` method for - logging and debugging purposes. + object may be anything, but should implement a ``__str__`` method that + outputs a corresponding :term:`userid`. """ diff --git a/src/pyramid/security.py b/src/pyramid/security.py index 64e840801..08c36b457 100644 --- a/src/pyramid/security.py +++ b/src/pyramid/security.py @@ -306,6 +306,28 @@ class SecurityAPIMixin(object): return None return policy.identify(self) + @property + def authenticated_userid(self): + """ + Return the :term:`userid` of the currently authenticated user or + ``None`` if there is no :term:`security policy` in effect or there is + no currently authenticated user. + + .. versionchanged:: 2.0 + + When using the new security system, this property outputs the + string representation of the :term:`identity`. + + """ + 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 str(security.identify(self)) + else: + return None + def has_permission(self, permission, context=None): """ Given a permission and an optional context, returns an instance of :data:`pyramid.security.Allowed` if the permission is granted to this @@ -336,37 +358,15 @@ class SecurityAPIMixin(object): class AuthenticationAPIMixin(object): - @property - def authenticated_userid(self): - """ - .. deprecated:: 2.0 - - ``authenticated_userid`` has been replaced by - :attr:`authenticated_identity` in the new security system. See - :ref:`upgrading_auth` for more information. - - Return the userid of the currently authenticated user or - ``None`` if there is no :term:`authentication policy` in effect or - there is no currently authenticated user. - - """ - 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 str(security.identify(self)) - else: - return None - @property def unauthenticated_userid(self): """ .. deprecated:: 2.0 - ``unauthenticated_userid`` has been replaced by - :attr:`authenticated_identity` in the new security system. See - :ref:`upgrading_auth` for more information. + ``unauthenticated_userid`` does not have an equivalent in the new + security system. Use :attr:`.authenticated_userid` or + :attr:`.identity` instead. See :ref:`upgrading_auth` for more + information. Return an object which represents the *claimed* (not verified) user id of the credentials present in the request. ``None`` if there is no -- cgit v1.2.3