Skip to content

Commit 1cd3275

Browse files
Andreas RichterAndreas Richter
authored andcommitted
Prevent errors when saml authenticator is used along side of another authenticator.
For example basic/sample using an ldap auth for the basic part. This was causing problems since this identifier was assuming a certain userid string and not forgiving when parsing it.
1 parent 64afc6f commit 1cd3275

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/s2repoze/plugins/sp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,11 @@ def add_metadata(self, environ, identity):
597597
""" Add information to the knowledge I have about the user """
598598
name_id = identity['repoze.who.userid']
599599
if isinstance(name_id, basestring):
600-
name_id = decode(name_id)
600+
try:
601+
# Make sure that userids authenticated by another plugin don't cause problems here.
602+
name_id = decode(name_id)
603+
except:
604+
pass
601605

602606
_cli = self.saml_client
603607
logger.debug("[add_metadata] for %s" % name_id)
@@ -651,7 +655,7 @@ def authenticate(self, environ, identity=None):
651655
tktuser = identity.get('repoze.who.plugins.auth_tkt.userid', None)
652656
if tktuser and self.saml_client.is_logged_in(decode(tktuser)):
653657
return tktuser
654-
return identity.get('login', None)
658+
return None
655659
else:
656660
return None
657661

src/saml2/ident.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ def code(item):
3939
def decode(txt):
4040
_nid = NameID()
4141
for part in txt.split(","):
42-
i, val = part.split("=")
43-
setattr(_nid, ATTR[int(i)], unquote(val))
42+
if part.find("=") != -1:
43+
i, val = part.split("=")
44+
try:
45+
setattr(_nid, ATTR[int(i)], unquote(val))
46+
except:
47+
pass
4448
return _nid
4549

4650

0 commit comments

Comments
 (0)