Skip to content

Commit 86fc56d

Browse files
committed
ACS custom_validation method for additional checks
1 parent 37a095f commit 86fc56d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

djangosaml2/views.py

+9
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ class AssertionConsumerServiceView(SPConfigMixin, View):
302302
though some implementations may instead register their own subclasses of Saml2Backend.
303303
"""
304304

305+
def custom_validation(self, response):
306+
pass
307+
305308
def handle_acs_failure(self, request, exception=None, status=403, **kwargs):
306309
""" Error handler if the login attempt fails. Override this to customize the error response.
307310
"""
@@ -384,6 +387,12 @@ def post(self, request, attribute_mapping=None, create_unknown_user=None):
384387
logger.warning("Invalid SAML Assertion received (unknown error).")
385388
return self.handle_acs_failure(request, status=400, exception=SuspiciousOperation('Unknown SAML2 error'))
386389

390+
try:
391+
self.custom_validation(response)
392+
except Exception as e:
393+
logger.warning("SAML Response validation error: {e}")
394+
return self.handle_acs_failure(request, status=400, exception=SuspiciousOperation('SAML2 validation error'))
395+
387396
session_id = response.session_id()
388397
oq_cache.delete(session_id)
389398

0 commit comments

Comments
 (0)