Skip to content

Commit 5710b8b

Browse files
committed
Allow process_response and process_slo to raise is_valid exceptions
1 parent 52d2ac8 commit 5710b8b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/onelogin/saml2/auth.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,16 @@ def store_valid_response(self, response):
111111
self._last_response_in_response_to = response.get_in_response_to()
112112
self._last_assertion_not_on_or_after = response.get_assertion_not_on_or_after()
113113

114-
def process_response(self, request_id=None):
114+
def process_response(self, request_id=None, raise_exceptions=False):
115115
"""
116116
Process the SAML Response sent by the IdP.
117117
118118
:param request_id: Is an optional argument. Is the ID of the AuthNRequest sent by this SP to the IdP.
119119
:type request_id: string
120120
121+
:param raise_exceptions: Whether to return raise an exception during is_valid check
122+
:type raise_exceptions: Boolean
123+
121124
:raises: OneLogin_Saml2_Error.SAML_RESPONSE_NOT_FOUND, when a POST with a SAMLResponse is not found
122125
"""
123126
self._errors = []
@@ -128,7 +131,7 @@ def process_response(self, request_id=None):
128131
response = self.response_class(self._settings, self._request_data["post_data"]["SAMLResponse"])
129132
self._last_response = response.get_xml_document()
130133

131-
if response.is_valid(self._request_data, request_id):
134+
if response.is_valid(self._request_data, request_id, raise_exceptions=raise_exceptions):
132135
self.store_valid_response(response)
133136
else:
134137
self._errors.append("invalid_response")
@@ -138,7 +141,7 @@ def process_response(self, request_id=None):
138141
self._errors.append("invalid_binding")
139142
raise OneLogin_Saml2_Error("SAML Response not found, Only supported HTTP_POST Binding", OneLogin_Saml2_Error.SAML_RESPONSE_NOT_FOUND)
140143

141-
def process_slo(self, keep_local_session=False, request_id=None, delete_session_cb=None):
144+
def process_slo(self, keep_local_session=False, request_id=None, delete_session_cb=None, raise_exceptions=False):
142145
"""
143146
Process the SAML Logout Response / Logout Request sent by the IdP.
144147
@@ -148,6 +151,9 @@ def process_slo(self, keep_local_session=False, request_id=None, delete_session_
148151
:param request_id: The ID of the LogoutRequest sent by this SP to the IdP
149152
:type request_id: string
150153
154+
:param raise_exceptions: Whether to return raise an exception during is_valid check
155+
:type raise_exceptions: Boolean
156+
151157
:returns: Redirection url
152158
"""
153159
self._errors = []
@@ -160,7 +166,7 @@ def process_slo(self, keep_local_session=False, request_id=None, delete_session_
160166
if not self.validate_response_signature(get_data):
161167
self._errors.append("invalid_logout_response_signature")
162168
self._errors.append("Signature validation failed. Logout Response rejected")
163-
elif not logout_response.is_valid(self._request_data, request_id):
169+
elif not logout_response.is_valid(self._request_data, request_id, raise_exceptions=raise_exceptions):
164170
self._errors.append("invalid_logout_response")
165171
elif logout_response.get_status() != OneLogin_Saml2_Constants.STATUS_SUCCESS:
166172
self._errors.append("logout_not_success")
@@ -175,7 +181,7 @@ def process_slo(self, keep_local_session=False, request_id=None, delete_session_
175181
if not self.validate_request_signature(get_data):
176182
self._errors.append("invalid_logout_request_signature")
177183
self._errors.append("Signature validation failed. Logout Request rejected")
178-
elif not logout_request.is_valid(self._request_data):
184+
elif not logout_request.is_valid(self._request_data, raise_exceptions=raise_exceptions):
179185
self._errors.append("invalid_logout_request")
180186
else:
181187
if not keep_local_session:

0 commit comments

Comments
 (0)