Skip to content

Commit c019d99

Browse files
committed
Store session mapping and do logout
In Django dashes in headers are replaced by underscores. We have to respect that. Otherwise we will get a KeyError (as I did at first in my test env). See https://stackoverflow.com/a/24355709/1381638
1 parent 045777c commit c019d99

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

shibboleth/middleware.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.core.exceptions import ImproperlyConfigured
55

66
from shibboleth.app_settings import SHIB_ATTRIBUTE_MAP, GROUP_ATTRIBUTES
7+
from shibboleth.models import ShibSession
78

89

910
class ShibbolethRemoteUserMiddleware(RemoteUserMiddleware):
@@ -56,7 +57,10 @@ def process_request(self, request):
5657
# by logging the user in.
5758
request.user = user
5859
auth.login(request, user)
59-
60+
61+
# store session mapping
62+
ShibSession.objects.get_or_create(shib=request.META['Shib_Session_ID'], session_id=request.session.session_key)
63+
6064
# Upgrade user groups if configured in the settings.py
6165
# If activated, the user will be associated with those groups.
6266
if GROUP_ATTRIBUTES:

shibboleth/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
#intentionally left blank
1+
from django.db import models
2+
from django.contrib.sessions.models import Session
3+
4+
5+
class ShibSession(models.Model):
6+
shib = models.CharField(max_length=100, primary_key=True)
7+
session = models.ForeignKey(Session, on_delete=models.CASCADE)

shibboleth/views.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.shortcuts import redirect
77
from django.utils.decorators import method_decorator
88
from django.views.generic import TemplateView
9+
from django.contrib.sessions.models import Session
910

1011
try:
1112
from django.utils.six.moves.urllib.parse import quote
@@ -14,6 +15,7 @@
1415

1516
#Logout settings.
1617
from shibboleth.app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL
18+
from shibboleth.models import ShibSession
1719

1820
#SLO (back-channel) / spyne stuff
1921
from spyne.model.primitive import Unicode
@@ -101,6 +103,13 @@ class LogoutNotificationService(Service):
101103
_out_variable_name='OK',
102104
)
103105
def LogoutNotification(ctx, sessionid):
104-
#return 'Session: %s' % sessionid
105-
#TODO Do logout stuff here - delete user session based on shib session
106-
return True
106+
# delete user session based on shib session
107+
try:
108+
session_mapping = ShibSession.objects.get(shib=sessionid)
109+
except:
110+
# Can't delete session
111+
raise
112+
else:
113+
# Deleting session
114+
Session.objects.filter(session_key=session_mapping.session_id).delete()
115+
return True

0 commit comments

Comments
 (0)