summaryrefslogtreecommitdiff
path: root/openstack_auth
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-09-17 08:47:22 +0000
committerGerrit Code Review <review@openstack.org>2016-09-17 08:47:22 +0000
commit7cfe929ece92a277db1c0c5f7900d60eeea28a58 (patch)
tree6d6c2728e734397f15040f28e68a6cbe8fcda7df /openstack_auth
parentbba6c3859bab6d52969dc6e8131a3c6579d2508c (diff)
parent00346889c99c26f1bbdaf3c392bac6dfefb509c7 (diff)
downloaddjango_openstack_auth-7cfe929ece92a277db1c0c5f7900d60eeea28a58.tar.gz
Merge "Add is_authenticated and is_anonymous properties"
Diffstat (limited to 'openstack_auth')
-rw-r--r--openstack_auth/user.py75
1 files changed, 46 insertions, 29 deletions
diff --git a/openstack_auth/user.py b/openstack_auth/user.py
index c9200f4..fba75e7 100644
--- a/openstack_auth/user.py
+++ b/openstack_auth/user.py
@@ -14,9 +14,11 @@
import hashlib
import logging
+import django
from django.conf import settings
from django.contrib.auth import models
from django.db import models as db_models
+from django.utils import deprecation
from keystoneauth1 import exceptions as keystone_exceptions
from keystoneclient.common import cms as keystone_cms
import six
@@ -261,35 +263,50 @@ class User(models.AbstractBaseUser, models.AnonymousUser):
return None
return not utils.is_token_valid(self.token, margin)
- def is_authenticated(self, margin=None):
- """Checks for a valid authentication.
-
- :param margin:
- A security time margin in seconds before end of authentication.
- Will return ``False`` if authentication ends in less than ``margin``
- seconds of time.
- A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
- django settings.
-
- """
- return (self.token is not None and
- utils.is_token_valid(self.token, margin))
-
- def is_anonymous(self, margin=None):
- """Return if the user is not authenticated.
-
- Returns ``True`` if not authenticated,``False`` otherwise.
-
- :param margin:
- A security time margin in seconds before end of an eventual
- authentication.
- Will return ``True`` even if authenticated but that authentication
- ends in less than ``margin`` seconds of time.
- A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
- django settings.
-
- """
- return not self.is_authenticated(margin)
+ if django.VERSION >= (1, 10):
+ @property
+ def is_authenticated(self):
+ """Checks for a valid authentication."""
+ if (self.token is not None and utils.is_token_valid(self.token)):
+ return deprecation.CallableTrue
+ else:
+ return deprecation.CallableFalse
+
+ @property
+ def is_anonymous(self):
+ """Return if the user is not authenticated.
+
+ Returns ``True`` if not authenticated,``False`` otherwise.
+ """
+ return deprecation.CallableBool(not self.is_authenticated)
+ else:
+ def is_authenticated(self, margin=None):
+ """Checks for a valid authentication.
+
+ :param margin:
+ A security time margin in seconds before end of authentication.
+ Will return ``False`` if authentication ends in less than
+ ``margin`` seconds of time.
+ A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
+ django settings.
+ """
+ return (self.token is not None and
+ utils.is_token_valid(self.token, margin))
+
+ def is_anonymous(self, margin=None):
+ """Return if the user is not authenticated.
+
+ Returns ``True`` if not authenticated,``False`` otherwise.
+
+ :param margin:
+ A security time margin in seconds before end of an eventual
+ authentication.
+ Will return ``True`` even if authenticated but that
+ authentication ends in less than ``margin`` seconds of time.
+ A default margin can be set by the TOKEN_TIMEOUT_MARGIN in the
+ django settings.
+ """
+ return not self.is_authenticated(margin)
@property
def is_active(self):