Skip to content

Commit 1f75792

Browse files
committed
Make backchannel SLO a configurable feature
Backchannel SLO introduces new dependencies and is perhaps not needed / wanted by everyone. Disable it by default.
1 parent c885a56 commit 1f75792

File tree

4 files changed

+20
-50
lines changed

4 files changed

+20
-50
lines changed

shibboleth/app_settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@
2626
#LOGOUT_REDIRECT_URL specifies a default logout page that will always be used when
2727
#users logout from Shibboleth.
2828
LOGOUT_REDIRECT_URL = getattr(settings, 'SHIBBOLETH_LOGOUT_REDIRECT_URL', None)
29+
30+
# back-channel SLO
31+
SINGLE_LOGOUT_BACKCHANNEL = getattr(settings, 'SHIBBOLETH_SINGLE_LOGOUT_BACKCHANNEL', False)

shibboleth/tests/test_shib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
settings.SHIBBOLETH_LOGOUT_URL = 'https://sso.school.edu/logout?next=%s'
6262
settings.SHIBBOLETH_LOGOUT_REDIRECT_URL = 'http://school.edu/'
63+
settings.SHIBBOLETH_SINGLE_LOGOUT_BACKCHANNEL = True
6364

6465
# MUST be imported after the settings above
6566
from shibboleth import app_settings

shibboleth/urls.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import django
22
from django.conf.urls import url
3-
from spyne.protocol.soap import Soap11
4-
from spyne.server.django import DjangoView
3+
from shibboleth.app_settings import SINGLE_LOGOUT_BACKCHANNEL
54

6-
from .views import ShibbolethView, ShibbolethLogoutView, ShibbolethLoginView, LogoutNotificationService
5+
from .views import ShibbolethView, ShibbolethLogoutView, ShibbolethLoginView
76

87
urlpatterns = [
98
url(r'^login/$', ShibbolethLoginView.as_view(), name='login'),
109
url(r'^logout/$', ShibbolethLogoutView.as_view(), name='logout'),
1110
url(r'^$', ShibbolethView.as_view(), name='info'),
12-
url(r'^logoutNotification/', DjangoView.as_view(
13-
services=[LogoutNotificationService], tns='urn:mace:shibboleth:2.0:sp:notify',
14-
in_protocol=Soap11(), out_protocol=Soap11())),
15-
#cache_wsdl=False)),
16-
#FIXME Soap11(validator='lxml') - validation would be nice, but needs adjusted model to support logout type attribute
1711
]
12+
13+
if SINGLE_LOGOUT_BACKCHANNEL:
14+
from spyne.protocol.soap import Soap11
15+
from spyne.server.django import DjangoView
16+
from .slo_view import LogoutNotificationService
17+
18+
urlpatterns += [
19+
url(r'^logoutNotification/', DjangoView.as_view(
20+
services=[LogoutNotificationService],
21+
tns='urn:mace:shibboleth:2.0:sp:notify',
22+
in_protocol=Soap11(), out_protocol=Soap11())),
23+
#FIXME Soap11(validator='lxml') - validation would be nice,
24+
# but needs adjusted model to support logout type attribute
25+
]

shibboleth/views.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
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
109

1110
try:
1211
from django.utils.six.moves.urllib.parse import quote
@@ -15,19 +14,6 @@
1514

1615
#Logout settings.
1716
from shibboleth.app_settings import LOGOUT_URL, LOGOUT_REDIRECT_URL
18-
from shibboleth.models import ShibSession
19-
20-
#SLO (back-channel) / spyne stuff
21-
from spyne.model.primitive import Unicode
22-
#from spyne.model import XmlAttribute
23-
try:
24-
from spyne.service import Service
25-
except ImportError:
26-
from spyne.service import ServiceBase as Service
27-
28-
from spyne.decorator import rpc
29-
from spyne import ComplexModel
30-
from spyne.model.fault import Fault
3117

3218

3319
class ShibbolethView(TemplateView):
@@ -90,31 +76,3 @@ def get(self, request, *args, **kwargs):
9076
quote(request.build_absolute_uri())
9177
logout = LOGOUT_URL % target
9278
return redirect(logout)
93-
94-
95-
class OKType(ComplexModel):
96-
pass
97-
98-
99-
class MandatoryUnicode(Unicode):
100-
class Attributes(Unicode.Attributes):
101-
nullable = False
102-
min_occurs = 1
103-
104-
105-
class LogoutNotificationService(Service):
106-
@rpc(MandatoryUnicode, _returns=OKType,
107-
_in_variable_names={'sessionid': 'SessionID'},
108-
_out_variable_name='OK',
109-
)
110-
def LogoutNotification(ctx, sessionid):
111-
# delete user session based on shib session
112-
try:
113-
session_mapping = ShibSession.objects.get(shib=sessionid)
114-
except:
115-
# Can't delete session
116-
raise Fault(faultcode='Client', faultstring='Invalid session id')
117-
else:
118-
# Deleting session
119-
Session.objects.filter(session_key=session_mapping.session_id).delete()
120-
return True

0 commit comments

Comments
 (0)