adapters: ease custom lookup through inheritance (#40833)

This commit is contained in:
Emmanuel Cazenave 2020-03-31 15:10:50 +02:00
parent 74230b51ec
commit f16d316cef
1 changed files with 7 additions and 4 deletions

View File

@ -314,10 +314,7 @@ class DefaultAdapter(object):
except User.DoesNotExist:
pass
user = None
lookup_by_attributes = utils.get_setting(idp, 'LOOKUP_BY_ATTRIBUTES')
if lookup_by_attributes:
user = self._lookup_by_attributes(idp, saml_attributes, lookup_by_attributes)
user = self.lookup_by_attributes(idp, saml_attributes)
created = False
if not user:
@ -343,6 +340,12 @@ class DefaultAdapter(object):
logger.info('created new user %s with name_id %s from issuer %s', nameid_user, name_id, issuer)
return nameid_user
def lookup_by_attributes(self, idp, saml_attributes):
rules = utils.get_setting(idp, 'LOOKUP_BY_ATTRIBUTES')
if rules:
return self._lookup_by_attributes(idp, saml_attributes, rules)
return None
def _lookup_by_attributes(self, idp, saml_attributes, lookup_by_attributes):
if not isinstance(lookup_by_attributes, list):
logger.error('invalid LOOKUP_BY_ATTRIBUTES configuration %r: it must be a list', lookup_by_attributes)