Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#112 FIX: Prevent KeyError during logout by using singleton SAML2 client. #113

Open
wants to merge 1 commit into
base: link-master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ckanext/saml2/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,21 @@ def user_delete(context, data_dict):
return _no_permissions(context, msg)

rememberer_name = None
# Singleton SAML client. Avoids a KeyError during Logout.
# See https://github.com/DataShades/ckanext-saml2/issues/112
client = None


def delete_cookies():
"""Logout."""
global rememberer_name
global client
if rememberer_name is None:
plugins = p.toolkit.request.environ['repoze.who.plugins']
saml_plugin = plugins.get('saml2auth')
rememberer_name = saml_plugin.rememberer_name
if client is None:
client = plugins.get('saml2auth')
rememberer_name = client.rememberer_name
base.response.delete_cookie(rememberer_name)
# We seem to end up with an extra cookie so kill this too
domain = p.toolkit.request.environ['HTTP_HOST']
Expand Down Expand Up @@ -576,6 +582,7 @@ def login(self):

def logout(self):
"""Logout definition."""
global client
environ = p.toolkit.request.environ

userobj = p.toolkit.c.userobj
Expand All @@ -591,7 +598,8 @@ def logout(self):

subject_id = environ["repoze.who.identity"]['repoze.who.userid']
name_id = unserialise_nameid(subject_id)
client = environ['repoze.who.plugins']["saml2auth"]
if client is None:
client = environ['repoze.who.plugins']["saml2auth"]

# Taken from saml2.client:global_logout but forces
# HTTP-Redirect binding.
Expand Down