Skip to content

HTTP Redirect page on UnknowError Exception #325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/satosa/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from satosa import util
from .context import Context
from .exception import SATOSAConfigurationError
from .exception import SATOSAError, SATOSAAuthenticationError, SATOSAUnknownError
from .exception import SATOSAError, SATOSAAuthenticationError, SATOSAUnknownError, SATOSAUnknownErrorRedirectUrl
from .plugin_loader import load_backends, load_frontends
from .plugin_loader import load_request_microservices, load_response_microservices
from .routing import ModuleRouter, SATOSANoBoundEndpointError
Expand Down Expand Up @@ -250,12 +250,21 @@ def run(self, context):
msg = "configuration error: unknown system entity " + str(err)
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
logger.error(logline, exc_info=False)
raise
raise UnknownSystemEntity(("Unknown System Entity ID - please check "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@c00kiemon5ter Would you prefer that this code would be committed in a separate PR?

"requester entity ID, "
"AssertionConsumerService definitions "
"and other possible mismatches between "
"Service Provider Metadata and its AuthnRequest."))
except Exception as err:
msg = "Uncaught exception"
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
logger.error(logline, exc_info=True)
raise SATOSAUnknownError("Unknown error") from err
redirect_url = self.config.get("UNKNOW_ERROR_REDIRECT_PAGE")
if redirect_url:
raise SATOSAUnknownErrorRedirectUrl((redirect_url, logline))
else:
raise SATOSAUnknownError("Unknown error") from err

return resp


Expand Down
7 changes: 7 additions & 0 deletions src/satosa/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class SATOSAUnknownError(SATOSAError):
pass


class SATOSAUnknownErrorRedirectUrl(SATOSAError):
"""
SATOSA unknown error redirect page
"""
pass


class SATOSAAuthenticationError(SATOSAError):
"""
SATOSA authentication error.
Expand Down
8 changes: 6 additions & 2 deletions src/satosa/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import satosa.logging_util as lu
from .base import SATOSABase
from .context import Context
from .response import ServiceError, NotFound
from .exception import SATOSAUnknownErrorRedirectUrl
from .response import ServiceError, NotFound, Redirect
from .routing import SATOSANoBoundEndpointError
from saml2.s_utils import UnknownSystemEntity

Expand Down Expand Up @@ -125,13 +126,16 @@ def __call__(self, environ, start_response, debug=False):
logger.debug(logline)
resp = NotFound("The Service or Identity Provider you requested could not be found.")
return resp(environ, start_response)
except SATOSAUnknownErrorRedirectUrl as e:
redirect_url, error_log = e.args[0][0], e.args[0][1]
logger.debug('{}: Redirecting to "{}"'.format(error_log, redirect_url))
return Redirect(redirect_url)(environ, start_response)
except Exception as e:
if type(e) != UnknownSystemEntity:
logline = "{}".format(e)
logger.exception(logline)
if debug:
raise

resp = ServiceError("%s" % e)
return resp(environ, start_response)

Expand Down