|
8 | 8 | from saml2.s_utils import UnknownSystemEntity
|
9 | 9 |
|
10 | 10 | from satosa import util
|
11 |
| -from satosa.response import Redirect |
12 | 11 | from satosa.response import BadRequest
|
13 | 12 | from satosa.response import NotFound
|
| 13 | +from satosa.response import Redirect |
14 | 14 | from .context import Context
|
15 |
| -from .exception import SATOSAError |
16 | 15 | from .exception import SATOSAAuthenticationError
|
17 |
| -from .exception import SATOSAUnknownError |
18 |
| -from .exception import SATOSAMissingStateError |
19 | 16 | from .exception import SATOSAAuthenticationFlowError
|
20 | 17 | from .exception import SATOSABadRequestError
|
21 |
| -from .plugin_loader import load_backends, load_frontends |
22 |
| -from .plugin_loader import load_request_microservices, load_response_microservices |
23 |
| -from .routing import ModuleRouter, SATOSANoBoundEndpointError |
24 |
| -from .state import cookie_to_state, SATOSAStateError, State, state_to_cookie |
| 18 | +from .exception import SATOSAError |
| 19 | +from .exception import SATOSAMissingStateError |
| 20 | +from .exception import SATOSANoBoundEndpointError |
| 21 | +from .exception import SATOSAUnknownError |
| 22 | +from .exception import SATOSAStateError |
| 23 | +from .plugin_loader import load_backends |
| 24 | +from .plugin_loader import load_frontends |
| 25 | +from .plugin_loader import load_request_microservices |
| 26 | +from .plugin_loader import load_response_microservices |
| 27 | +from .routing import ModuleRouter |
| 28 | +from .state import State |
| 29 | +from .state import cookie_to_state |
| 30 | +from .state import state_to_cookie |
25 | 31 |
|
26 | 32 | import satosa.logging_util as lu
|
27 | 33 |
|
@@ -262,77 +268,104 @@ def run(self, context):
|
262 | 268 | resp = self._run_bound_endpoint(context, spec)
|
263 | 269 | self._save_state(resp, context)
|
264 | 270 | except SATOSABadRequestError as e:
|
| 271 | + error_id = uuid.uuid4().urn |
265 | 272 | msg = {
|
266 | 273 | "message": "Bad Request",
|
267 |
| - "error": e.error, |
268 |
| - "error_id": uuid.uuid4().urn |
| 274 | + "error": str(e), |
| 275 | + "error_id": error_id, |
269 | 276 | }
|
270 | 277 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
271 | 278 | logger.error(logline)
|
272 | 279 | generic_error_url = self.config.get("ERROR_URL")
|
273 | 280 | if generic_error_url:
|
| 281 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
274 | 282 | return Redirect(generic_error_url)
|
275 |
| - else: |
276 |
| - return BadRequest(e.error) |
| 283 | + return BadRequest(error) |
277 | 284 | except SATOSAMissingStateError as e:
|
| 285 | + error_id = uuid.uuid4().urn |
278 | 286 | msg = {
|
279 | 287 | "message": "Missing SATOSA State",
|
280 |
| - "error": e.error, |
281 |
| - "error_id": uuid.uuid4().urn |
| 288 | + "error": str(e), |
| 289 | + "error_id": error_id, |
282 | 290 | }
|
283 | 291 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
284 | 292 | logger.error(logline)
|
285 | 293 | generic_error_url = self.config.get("ERROR_URL")
|
286 | 294 | if generic_error_url:
|
| 295 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
287 | 296 | return Redirect(generic_error_url)
|
288 |
| - else: |
289 |
| - raise |
| 297 | + raise |
290 | 298 | except SATOSAAuthenticationFlowError as e:
|
| 299 | + error_id = uuid.uuid4().urn |
291 | 300 | msg = {
|
292 | 301 | "message": "SATOSA Authentication Flow Error",
|
293 |
| - "error": e.error, |
294 |
| - "error_id": uuid.uuid4().urn |
| 302 | + "error": str(e), |
| 303 | + "error_id": error_id, |
295 | 304 | }
|
296 | 305 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
297 | 306 | logger.error(logline)
|
298 | 307 | generic_error_url = self.config.get("ERROR_URL")
|
299 | 308 | if generic_error_url:
|
| 309 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
300 | 310 | return Redirect(generic_error_url)
|
301 |
| - else: |
302 |
| - raise |
| 311 | + raise |
303 | 312 | except SATOSANoBoundEndpointError as e:
|
304 |
| - msg = str(e) |
| 313 | + error_id = uuid.uuid4().urn |
| 314 | + msg = { |
| 315 | + "message": "URL-path is not bound to any endpoint function", |
| 316 | + "error": str(e), |
| 317 | + "error_id": error_id, |
| 318 | + } |
305 | 319 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
306 | 320 | logger.error(logline)
|
| 321 | + generic_error_url = self.config.get("ERROR_URL") |
| 322 | + if generic_error_url: |
| 323 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
| 324 | + return Redirect(generic_error_url) |
307 | 325 | return NotFound("The Service or Identity Provider you requested could not be found.")
|
308 |
| - except SATOSAError: |
309 |
| - msg = "Uncaught SATOSA error" |
| 326 | + except SATOSAError as e: |
| 327 | + error_id = uuid.uuid4().urn |
| 328 | + msg = { |
| 329 | + "message": "Uncaught SATOSA error", |
| 330 | + "error": str(e), |
| 331 | + "error_id": error_id, |
| 332 | + } |
310 | 333 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
311 | 334 | logger.error(logline)
|
312 | 335 | generic_error_url = self.config.get("ERROR_URL")
|
313 | 336 | if generic_error_url:
|
| 337 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
314 | 338 | return Redirect(generic_error_url)
|
315 |
| - else: |
316 |
| - raise |
| 339 | + raise |
317 | 340 | except UnknownSystemEntity as e:
|
318 |
| - msg = f"Configuration error: unknown system entity: {e}" |
| 341 | + error_id = uuid.uuid4().urn |
| 342 | + msg = { |
| 343 | + "message": "Configuration error: unknown system entity", |
| 344 | + "error": str(e), |
| 345 | + "error_id": error_id, |
| 346 | + } |
319 | 347 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
320 | 348 | logger.error(logline)
|
321 | 349 | generic_error_url = self.config.get("ERROR_URL")
|
322 | 350 | if generic_error_url:
|
| 351 | + redirect_url = f"{generic_error_url}?errorid={error_id}" |
323 | 352 | return Redirect(generic_error_url)
|
324 |
| - else: |
325 |
| - raise |
| 353 | + raise |
326 | 354 | except Exception as e:
|
327 |
| - msg = "Uncaught exception" |
| 355 | + error_id = uuid.uuid4().urn |
| 356 | + msg = { |
| 357 | + "message": "Uncaught exception", |
| 358 | + "error": str(e), |
| 359 | + "error_id": error_id, |
| 360 | + } |
328 | 361 | logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
|
329 | 362 | logger.error(logline)
|
330 | 363 | generic_error_url = self.config.get("ERROR_URL")
|
331 | 364 | if generic_error_url:
|
332 | 365 | return Redirect(generic_error_url)
|
333 |
| - else: |
334 |
| - raise SATOSAUnknownError("Unknown error") from e |
335 |
| - return resp |
| 366 | + raise SATOSAUnknownError("Unknown error") from e |
| 367 | + else: |
| 368 | + return resp |
336 | 369 |
|
337 | 370 |
|
338 | 371 | class SAMLBaseModule(object):
|
|
0 commit comments