Skip to content

Commit 4af640c

Browse files
committed
parse_authn_request_response minor refactor
1 parent 0a0ce57 commit 4af640c

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ tags
1616
build/
1717
dist/
1818
*__pycache__*
19+
*.coverage

CHANGES

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Changes
22
=======
33

4-
0.X.X (to-be-released)
4+
0.40.0 (2020-08-X)
55
-------------------
66
- Allow a SSO request without any attributes besides the NameID info. Backwards-incompatible changes to allow easier behaviour differentiation, two methods now receive the idp identifier (+ **kwargs were added to introduce possible similar changes in the future with less breaking effect):
77
- Method signature changed on Saml2Backend.clean_attributes: from `clean_attributes(self, attributes: dict)` to `clean_attributes(self, attributes: dict, idp_entityid: str, **kwargs)`
88
- Methodignature changed on Saml2Backend.is_authorized: from `is_authorized(self, attributes: dict, attribute_mapping: dict)` to `is_authorized(self, attributes: dict, attribute_mapping: dict, idp_entityid: str, **kwargs)`
9+
- SAML session refactor and minor changes in README file
910

1011
0.30.0 (2020-07-30)
1112
-------------------

djangosaml2/views.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,39 +294,43 @@ def post(self,
294294
oq_cache.sync()
295295
outstanding_queries = oq_cache.outstanding_queries()
296296

297+
_exception = None
297298
try:
298299
response = client.parse_authn_request_response(xmlstr,
299300
BINDING_HTTP_POST,
300301
outstanding_queries)
301302
except (StatusError, ToEarly) as e:
303+
_exception = e
302304
logger.exception("Error processing SAML Assertion.")
303-
return fail_acs_response(request, exception=e)
304305
except ResponseLifetimeExceed as e:
306+
_exception = e
305307
logger.info(("SAML Assertion is no longer valid. "
306308
"Possibly caused by network delay or replay attack."),
307309
exc_info=True)
308-
return fail_acs_response(request, exception=e)
309310
except SignatureError as e:
311+
_exception = e
310312
logger.info("Invalid or malformed SAML Assertion.", exc_info=True)
311-
return fail_acs_response(request, exception=e)
312313
except StatusAuthnFailed as e:
314+
_exception = e
313315
logger.info("Authentication denied for user by IdP.", exc_info=True)
314-
return fail_acs_response(request, exception=e)
315316
except StatusRequestDenied as e:
317+
_exception = e
316318
logger.warning("Authentication interrupted at IdP.", exc_info=True)
317-
return fail_acs_response(request, exception=e)
318319
except StatusNoAuthnContext as e:
320+
_exception = e
319321
logger.warning("Missing Authentication Context from IdP.", exc_info=True)
320-
return fail_acs_response(request, exception=e)
321322
except MissingKey as e:
323+
_exception = e
322324
logger.exception("SAML Identity Provider is not configured correctly: "
323325
"certificate key is missing!")
324-
return fail_acs_response(request, exception=e)
325326
except UnsolicitedResponse as e:
327+
_exception = e
326328
logger.exception("Received SAMLResponse when no request has been made.")
327-
return fail_acs_response(request, exception=e)
328329

329-
if response is None:
330+
331+
if _exception:
332+
return fail_acs_response(request, exception=_exception)
333+
elif response is None:
330334
logger.warning("Invalid SAML Assertion received (unknown error).")
331335
return fail_acs_response(request, status=400,
332336
exception=SuspiciousOperation('Unknown SAML2 error'))

tests/.coverage

-52 KB
Binary file not shown.

0 commit comments

Comments
 (0)