Commit 9b7bb0dc by Omar Khan

Make SAMLAuthBackend._config a cached_property

Cleaner, and keeps pylint happy
parent 2c4e97eb
...@@ -3,6 +3,7 @@ Slightly customized python-social-auth backend for SAML 2.0 support ...@@ -3,6 +3,7 @@ Slightly customized python-social-auth backend for SAML 2.0 support
""" """
import logging import logging
from django.http import Http404 from django.http import Http404
from django.utils.functional import cached_property
from social.backends.saml import SAMLAuth, OID_EDU_PERSON_ENTITLEMENT from social.backends.saml import SAMLAuth, OID_EDU_PERSON_ENTITLEMENT
from social.exceptions import AuthForbidden, AuthMissingParameter from social.exceptions import AuthForbidden, AuthMissingParameter
...@@ -23,9 +24,6 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method ...@@ -23,9 +24,6 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
def setting(self, name, default=None): def setting(self, name, default=None):
""" Get a setting, from SAMLConfiguration """ """ Get a setting, from SAMLConfiguration """
if not hasattr(self, '_config'):
from .models import SAMLConfiguration
self._config = SAMLConfiguration.current() # pylint: disable=attribute-defined-outside-init
try: try:
return self._config.get_setting(name) return self._config.get_setting(name)
except KeyError: except KeyError:
...@@ -62,3 +60,8 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method ...@@ -62,3 +60,8 @@ class SAMLAuthBackend(SAMLAuth): # pylint: disable=abstract-method
log.warning( log.warning(
"SAML user from IdP %s rejected due to missing eduPersonEntitlement %s", idp.name, expected) "SAML user from IdP %s rejected due to missing eduPersonEntitlement %s", idp.name, expected)
raise AuthForbidden(self) raise AuthForbidden(self)
@cached_property
def _config(self):
from .models import SAMLConfiguration
return SAMLConfiguration.current()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment