Skip to content

Commit 91d0f6e

Browse files
Merge pull request #138 from rhoerbe/rh_errhandling
Improve logging and exception handling
2 parents cbb6d4a + 9b87384 commit 91d0f6e

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
**/.DS_Store
12
_build
23
.idea
34
*.pyc

src/satosa/attribute_mapping.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ def to_internal(self, attribute_profile, external_dict):
8888

8989
for internal_attribute_name, mapping in self.from_internal_attributes.items():
9090
if attribute_profile not in mapping:
91-
logger.debug("no attribute mapping found for the attribute profile '%s'", attribute_profile)
91+
logger.debug("no attribute mapping found for internal attribute '%s' the attribute profile '%s'" % (
92+
internal_attribute_name, attribute_profile))
9293
# skip this internal attribute if we have no mapping in the specified profile
9394
continue
9495

9596
external_attribute_name = mapping[attribute_profile]
9697
attribute_values = self._collate_attribute_values_by_priority_order(external_attribute_name,
9798
external_dict)
9899
if attribute_values: # Only insert key if it has some values
100+
logger.debug("backend attribute '%s' mapped to %s" % (external_attribute_name,
101+
internal_attribute_name))
99102
internal_dict[internal_attribute_name] = attribute_values
103+
else:
104+
logger.debug("skipped backend attribute '%s': no value found", external_attribute_name)
100105

101106
internal_dict = self._handle_template_attributes(attribute_profile, internal_dict)
102107
return internal_dict
@@ -181,12 +186,16 @@ def from_internal(self, attribute_profile, internal_dict):
181186

182187
if attribute_profile not in attribute_mapping:
183188
# skip this internal attribute if we have no mapping in the specified profile
184-
logger.debug("no attribute mapping found for the attribute profile '%s'", attribute_profile)
189+
logger.debug("no mapping found for '%s' in attribute profile '%s'" %
190+
(internal_attribute_name,
191+
attribute_profile))
185192
continue
186193

187194
external_attribute_names = self.from_internal_attributes[internal_attribute_name][attribute_profile]
188195
# select the first attribute name
189196
external_attribute_name = external_attribute_names[0]
197+
logger.debug("frontend attribute %s mapped from %s" % (external_attribute_name,
198+
internal_attribute_name))
190199

191200
if self.separator in external_attribute_name:
192201
nested_attribute_names = external_attribute_name.split(self.separator)

src/satosa/backends/saml2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def _translate_response(self, response, state):
273273
except AttributeError:
274274
pass
275275

276-
satosa_logging(logger, logging.DEBUG, "received attributes:\n%s" % json.dumps(response.ava, indent=4), state)
276+
satosa_logging(logger, logging.DEBUG, "backend received attributes:\n%s" % json.dumps(response.ava, indent=4), state)
277277
return internal_resp
278278

279279
def _metadata_endpoint(self, context):

src/satosa/base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .plugin_loader import load_request_microservices, load_response_microservices
1818
from .routing import ModuleRouter, SATOSANoBoundEndpointError
1919
from .state import cookie_to_state, SATOSAStateError, State, state_to_cookie
20+
from saml2.s_utils import UnknownSystemEntity
2021

2122

2223
logger = logging.getLogger(__name__)
@@ -138,7 +139,7 @@ def _auth_resp_finish(self, context, internal_response):
138139
if user_id_to_attr:
139140
internal_response.attributes[user_id_to_attr] = [internal_response.user_id]
140141

141-
# Hash all attributes specified in INTERNAL_ATTRIBUTES["hash]
142+
# Hash all attributes specified in INTERNAL_ATTRIBUTES["hash"]
142143
hash_attributes = self.config["INTERNAL_ATTRIBUTES"].get("hash", [])
143144
internal_attributes = internal_response.attributes
144145
for attribute in hash_attributes:
@@ -266,9 +267,14 @@ def run(self, context):
266267
except SATOSANoBoundEndpointError:
267268
raise
268269
except SATOSAError:
269-
satosa_logging(logger, logging.ERROR, "Uncaught SATOSA error", context.state,
270+
satosa_logging(logger, logging.ERROR, "Uncaught SATOSA error ", context.state,
270271
exc_info=True)
271272
raise
273+
except UnknownSystemEntity as err:
274+
satosa_logging(logger, logging.ERROR,
275+
"configuration error: unknown system entity " + str(err),
276+
context.state, exc_info=False)
277+
raise
272278
except Exception as err:
273279
satosa_logging(logger, logging.ERROR, "Uncaught exception", context.state,
274280
exc_info=True)

src/satosa/proxy_server.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from .context import Context
1212
from .response import ServiceError, NotFound
1313
from .routing import SATOSANoBoundEndpointError
14+
from saml2.s_utils import UnknownSystemEntity
1415

1516
logger = logging.getLogger(__name__)
1617

@@ -117,7 +118,8 @@ def __call__(self, environ, start_response, debug=False):
117118
resp = NotFound("Couldn't find the page you asked for!")
118119
return resp(environ, start_response)
119120
except Exception as err:
120-
logger.exception("%s" % err)
121+
if type(err) != UnknownSystemEntity:
122+
logger.exception("%s" % err)
121123
if debug:
122124
raise
123125

@@ -137,7 +139,12 @@ def make_app(satosa_config):
137139
root_logger.addHandler(stderr_handler)
138140
root_logger.setLevel(logging.DEBUG)
139141

140-
logger.info("Running SATOSA version %s", pkg_resources.get_distribution("SATOSA").version)
142+
try:
143+
pkg = pkg_resources.get_distribution(module.__name__)
144+
logger.info("Running SATOSA version %s",
145+
pkg_resources.get_distribution("SATOSA").version)
146+
except (NameError, pkg_resources.DistributionNotFound):
147+
pass
141148
return ToBytesMiddleware(WsgiApplication(satosa_config))
142149
except Exception:
143150
logger.exception("Failed to create WSGI app.")

0 commit comments

Comments
 (0)