summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-06-06 08:12:14 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2019-06-11 14:46:02 (GMT)
commite0c1f5b43cbcd5c2dfe6c73ad4cab65a715d6988 (patch)
tree954e72f619ed0f73f7d96aef4af5b975fd6c13f1
parente1fa70d28db7bbb8cc04dd03f748382ab2657392 (diff)
downloaddjango-mellon-e0c1f5b43cbcd5c2dfe6c73ad4cab65a715d6988.zip
django-mellon-e0c1f5b43cbcd5c2dfe6c73ad4cab65a715d6988.tar.gz
django-mellon-e0c1f5b43cbcd5c2dfe6c73ad4cab65a715d6988.tar.bz2
simplify workflow in DefaultAdapter.lookup_user() (#33739)
-rw-r--r--mellon/adapters.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/mellon/adapters.py b/mellon/adapters.py
index 460d1a6..44f2fd0 100644
--- a/mellon/adapters.py
+++ b/mellon/adapters.py
@@ -130,25 +130,28 @@ class DefaultAdapter(object):
return User.objects.get(saml_identifiers__name_id=name_id,
saml_identifiers__issuer=issuer)
except User.DoesNotExist:
- if not utils.get_setting(idp, 'PROVISION'):
- self.logger.warning('provisionning disabled, login refused')
- return None
- user = self.create_user(User)
- saml_id, created = models.UserSAMLIdentifier.objects.get_or_create(
- name_id=name_id, issuer=issuer, defaults={'user': user})
- if created:
- try:
- self.finish_create_user(idp, saml_attributes, user)
- except UserCreationError:
- user.delete()
- return None
- self.logger.info('created new user %s with name_id %s from issuer %s',
- user, name_id, issuer)
- else:
+ pass
+
+ if not utils.get_setting(idp, 'PROVISION'):
+ self.logger.warning('provisionning disabled, login refused')
+ return None
+
+ user = self.create_user(User)
+ saml_id, created = models.UserSAMLIdentifier.objects.get_or_create(
+ name_id=name_id, issuer=issuer, defaults={'user': user})
+ if created:
+ try:
+ self.finish_create_user(idp, saml_attributes, user)
+ except UserCreationError:
user.delete()
- user = saml_id.user
- self.logger.info('looked up user %s with name_id %s from issuer %s',
- user, name_id, issuer)
+ return None
+ self.logger.info('created new user %s with name_id %s from issuer %s',
+ user, name_id, issuer)
+ else:
+ user.delete()
+ user = saml_id.user
+ self.logger.info('looked up user %s with name_id %s from issuer %s',
+ user, name_id, issuer)
return user
def provision(self, user, idp, saml_attributes):