Skip to content

Commit 11b777f

Browse files
committed
Allow graceful handling of auth_tkt cookies outliving saml clients cache
If for some reason the session cookie outlives the saml clients cache, for instance if the webservice is restarted there could be an inconsistent state where the user is authenticated but saml attributes are missing and saml logout requests will fail. By using only saml2sp as authenticator plugin and repoze.who 2.0 this little check will work around that and require a new login in this case
1 parent f3ec1cd commit 11b777f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/s2repoze/plugins/sp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ def _service_url(self, environ, qstr=None):
560560
#noinspection PyUnusedLocal
561561
def authenticate(self, environ, identity=None):
562562
if identity:
563+
tktuser = identity.get('repoze.who.plugins.auth_tkt.userid', None)
564+
if tktuser and self.saml_client.is_logged_in(decode(tktuser)):
565+
return tktuser
563566
return identity.get('login', None)
564567
else:
565568
return None

src/saml2/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ def local_logout(self, name_id):
216216
self.users.remove_person(name_id)
217217
return True
218218

219+
def is_logged_in(self, name_id):
220+
""" Check if user is in the cache
221+
222+
:param name_id: The identifier of the subject
223+
"""
224+
identity = self.users.get_identity(name_id)[0]
225+
return bool(identity)
226+
219227
def handle_logout_response(self, response):
220228
""" handles a Logout response
221229

0 commit comments

Comments
 (0)