30
30
from satosa .base import SAMLBaseModule
31
31
from satosa .context import Context
32
32
from .base import FrontendModule
33
- from ..logging_util import satosa_logging
34
33
from ..response import Response
35
34
from ..response import ServiceError
36
35
from ..saml_util import make_saml_response
37
36
from satosa .exception import SATOSAError
38
37
import satosa .util as util
39
38
39
+ import satosa .logging_util as lu
40
40
from satosa .internal import InternalData
41
41
from satosa .deprecated import saml_name_id_format_to_hash_type
42
42
from satosa .deprecated import hash_type_to_saml_name_id_format
@@ -190,15 +190,19 @@ def _handle_authn_request(self, context, binding_in, idp):
190
190
"""
191
191
req_info = idp .parse_authn_request (context .request ["SAMLRequest" ], binding_in )
192
192
authn_req = req_info .message
193
- satosa_logging (logger , logging .DEBUG , "%s" % authn_req , context .state )
193
+ msg = "{}" .format (authn_req )
194
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
195
+ logger .debug (logline )
194
196
195
197
# keep the ForceAuthn value to be used by plugins
196
198
context .decorate (Context .KEY_FORCE_AUTHN , authn_req .force_authn )
197
199
198
200
try :
199
201
resp_args = idp .response_args (authn_req )
200
202
except SAMLError as e :
201
- satosa_logging (logger , logging .ERROR , "Could not find necessary info about entity: %s" % e , context .state )
203
+ msg = "Could not find necessary info about entity: {}" .format (e )
204
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
205
+ logger .error (logline )
202
206
return ServiceError ("Incorrect request from requester: %s" % e )
203
207
204
208
requester = resp_args ["sp_entity_id" ]
@@ -273,7 +277,9 @@ def _get_approved_attributes(self, idp, idp_policy, sp_entity_id, state):
273
277
attribute_filter = list (idp_policy .restrict (all_attributes , sp_entity_id , idp .metadata ).keys ())
274
278
break
275
279
attribute_filter = self .converter .to_internal_filter (self .attribute_profile , attribute_filter )
276
- satosa_logging (logger , logging .DEBUG , "Filter: %s" % attribute_filter , state )
280
+ msg = "Filter: {}" .format (attribute_filter )
281
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (state ), message = msg )
282
+ logger .debug (logline )
277
283
return attribute_filter
278
284
279
285
def _filter_attributes (self , idp , internal_response , context ,):
@@ -343,8 +349,9 @@ def _handle_authn_response(self, context, internal_response, idp):
343
349
name_qualifier = None ,
344
350
)
345
351
346
- dbgmsg = "returning attributes %s" % json .dumps (ava )
347
- satosa_logging (logger , logging .DEBUG , dbgmsg , context .state )
352
+ msg = "returning attributes {}" .format (json .dumps (ava ))
353
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
354
+ logger .debug (logline )
348
355
349
356
policies = self .idp_config .get (
350
357
'service' , {}).get ('idp' , {}).get ('policy' , {})
@@ -376,22 +383,26 @@ def _handle_authn_response(self, context, internal_response, idp):
376
383
try :
377
384
args ['sign_alg' ] = getattr (xmldsig , sign_alg )
378
385
except AttributeError as e :
379
- errmsg = "Unsupported sign algorithm %s" % sign_alg
380
- satosa_logging (logger , logging .ERROR , errmsg , context .state )
381
- raise Exception (errmsg ) from e
386
+ msg = "Unsupported sign algorithm {}" .format (sign_alg )
387
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
388
+ logger .error (logline )
389
+ raise Exception (msg ) from e
382
390
else :
383
- dbgmsg = "signing with algorithm %s" % args ['sign_alg' ]
384
- satosa_logging (logger , logging .DEBUG , dbgmsg , context .state )
391
+ msg = "signing with algorithm {}" .format (args ['sign_alg' ])
392
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
393
+ logger .debug (logline )
385
394
386
395
try :
387
396
args ['digest_alg' ] = getattr (xmldsig , digest_alg )
388
397
except AttributeError as e :
389
- errmsg = "Unsupported digest algorithm %s" % digest_alg
390
- satosa_logging (logger , logging .ERROR , errmsg , context .state )
391
- raise Exception (errmsg ) from e
398
+ msg = "Unsupported digest algorithm {}" .format (digest_alg )
399
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
400
+ logger .error (logline )
401
+ raise Exception (msg ) from e
392
402
else :
393
- dbgmsg = "using digest algorithm %s" % args ['digest_alg' ]
394
- satosa_logging (logger , logging .DEBUG , dbgmsg , context .state )
403
+ msg = "using digest algorithm {}" .format (args ['digest_alg' ])
404
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
405
+ logger .debug (logline )
395
406
396
407
resp = idp .create_authn_response (** args )
397
408
http_args = idp .apply_binding (
@@ -426,7 +437,9 @@ def _handle_backend_error(self, exception, idp):
426
437
http_args = idp .apply_binding (resp_args ["binding" ], str (error_resp ), resp_args ["destination" ], relay_state ,
427
438
response = True )
428
439
429
- satosa_logging (logger , logging .DEBUG , "HTTPargs: %s" % http_args , exception .state )
440
+ msg = "HTTPSards: {}" .format (http_args )
441
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (exception .state ), message = msg )
442
+ logger .debug (logline )
430
443
return make_saml_response (resp_args ["binding" ], http_args )
431
444
432
445
def _metadata_endpoint (self , context ):
@@ -438,7 +451,9 @@ def _metadata_endpoint(self, context):
438
451
:param context: The current context
439
452
:return: response with metadata
440
453
"""
441
- satosa_logging (logger , logging .DEBUG , "Sending metadata response" , context .state )
454
+ msg = "Sending metadata response"
455
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
456
+ logger .debug (logline )
442
457
metadata_string = create_metadata_string (None , self .idp .config , 4 , None , None , None , None ,
443
458
None ).decode ("utf-8" )
444
459
return Response (metadata_string , content = "text/xml" )
@@ -478,15 +493,21 @@ def _set_common_domain_cookie(self, internal_response, http_args, context):
478
493
cookie = SimpleCookie (context .cookie )
479
494
if '_saml_idp' in cookie :
480
495
common_domain_cookie = cookie ['_saml_idp' ]
481
- satosa_logging (logger , logging .DEBUG , "Found existing common domain cookie {}" .format (common_domain_cookie ), context .state )
496
+ msg = "Found existing common domain cookie {}" .format (common_domain_cookie )
497
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
498
+ logger .debug (logline )
482
499
space_separated_b64_idp_string = unquote (common_domain_cookie .value )
483
500
b64_idp_list = space_separated_b64_idp_string .split ()
484
501
idp_list = [urlsafe_b64decode (b64_idp ).decode ('utf-8' ) for b64_idp in b64_idp_list ]
485
502
else :
486
- satosa_logging (logger , logging .DEBUG , "No existing common domain cookie found" , context .state )
503
+ msg = "No existing common domain cookie found"
504
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
505
+ logger .debug (logline )
487
506
idp_list = []
488
507
489
- satosa_logging (logger , logging .DEBUG , "Common domain cookie list of IdPs is {}" .format (idp_list ), context .state )
508
+ msg = "Common domain cookie list of IdPs is {}" .format (idp_list )
509
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
510
+ logger .debug (logline )
490
511
491
512
# Identity the current IdP just used for authentication in this flow.
492
513
this_flow_idp = internal_response .auth_info .issuer
@@ -496,8 +517,12 @@ def _set_common_domain_cookie(self, internal_response, http_args, context):
496
517
497
518
# Append the current IdP.
498
519
idp_list .append (this_flow_idp )
499
- satosa_logging (logger , logging .DEBUG , "Added IdP {} to common domain cookie list of IdPs" .format (this_flow_idp ), context .state )
500
- satosa_logging (logger , logging .DEBUG , "Common domain cookie list of IdPs is now {}" .format (idp_list ), context .state )
520
+ msg = "Added IdP {} to common domain cookie list of IdPs" .format (this_flow_idp )
521
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
522
+ logger .debug (logline )
523
+ msg = "Common domain cookie list of IdPs is now {}" .format (idp_list )
524
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
525
+ logger .debug (logline )
501
526
502
527
# Construct the cookie.
503
528
b64_idp_list = [urlsafe_b64encode (idp .encode ()).decode ("utf-8" ) for idp in idp_list ]
@@ -523,7 +548,9 @@ def _set_common_domain_cookie(self, internal_response, http_args, context):
523
548
cookie ['_saml_idp' ]['secure' ] = True
524
549
525
550
# Set the cookie.
526
- satosa_logging (logger , logging .DEBUG , "Setting common domain cookie with {}" .format (cookie .output ()), context .state )
551
+ msg = "Setting common domain cookie with {}" .format (cookie .output ())
552
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
553
+ logger .debug (logline )
527
554
http_args ['headers' ].append (tuple (cookie .output ().split (": " , 1 )))
528
555
529
556
def _build_idp_config_endpoints (self , config , providers ):
@@ -840,10 +867,12 @@ def _get_co_name(self, context):
840
867
"""
841
868
try :
842
869
co_name = context .state [self .name ][self .KEY_CO_NAME ]
843
- logger .debug ("Found CO {} from state" .format (co_name ))
870
+ logline = "Found CO {} from state" .format (co_name )
871
+ logger .debug (logline )
844
872
except KeyError :
845
873
co_name = self ._get_co_name_from_path (context )
846
- logger .debug ("Found CO {} from request path" .format (co_name ))
874
+ logline = "Found CO {} from request path" .format (co_name )
875
+ logger .debug (logline )
847
876
848
877
return co_name
849
878
@@ -985,9 +1014,9 @@ def _create_co_virtual_idp(self, context):
985
1014
if co_name not in co_names :
986
1015
msg = "CO {} not in configured list of COs {}" .format (co_name ,
987
1016
co_names )
988
- satosa_logging (logger , logging .WARN , msg , context .state )
1017
+ logline = lu .LOG_FMT .format (id = lu .get_session_id (context .state ), message = msg )
1018
+ logger .warn (logline )
989
1019
raise SATOSAError (msg )
990
-
991
1020
# Make a copy of the general IdP config that we will then overwrite
992
1021
# with mappings between SAML bindings and CO specific URL endpoints,
993
1022
# and the entityID for the CO virtual IdP.
@@ -1038,27 +1067,30 @@ def _register_endpoints(self, backend_names):
1038
1067
1039
1068
# Create a regex pattern that will match any of the backend names.
1040
1069
backend_url_pattern = "|^" .join (backend_names )
1041
- logger .debug ("Input backend names are {}" .format (backend_names ))
1042
- logger .debug ("Created backend regex '{}'" .format (backend_url_pattern ))
1070
+ logline = "Input backend names are {}" .format (backend_names )
1071
+ logger .debug (logline )
1072
+ logline = "Created backend regex '{}'" .format (backend_url_pattern )
1073
+ logger .debug (logline )
1043
1074
1044
1075
# Hold a list of tuples containing URL regex patterns and the callables
1045
1076
# that handle them.
1046
1077
url_to_callable_mappings = []
1047
1078
1048
1079
# Loop over IdP endpoint categories, e.g., single_sign_on_service.
1049
1080
for endpoint_category in self .endpoints :
1050
- logger . debug ( "Examining endpoint category {}" .format (
1051
- endpoint_category ) )
1081
+ logline = "Examining endpoint category {}" .format (endpoint_category )
1082
+ logger . debug ( logline )
1052
1083
1053
1084
# For each endpoint category loop of the bindings and their
1054
1085
# assigned endpoints.
1055
1086
for binding , endpoint in self .endpoints [endpoint_category ].items ():
1056
- logger . debug ( "Found binding {} and endpoint {}" .format (binding ,
1057
- endpoint ) )
1087
+ logline = "Found binding {} and endpoint {}" .format (binding , endpoint )
1088
+ logger . debug ( logline )
1058
1089
1059
1090
# Parse out the path from the endpoint.
1060
1091
endpoint_path = urlparse (endpoint ).path
1061
- logger .debug ("Using path {}" .format (endpoint_path ))
1092
+ logline = "Using path {}" .format (endpoint_path )
1093
+ logger .debug (logline )
1062
1094
1063
1095
# Use the backend URL pattern and the endpoint path to create
1064
1096
# a regex that will match and that includes a pattern for
@@ -1067,7 +1099,8 @@ def _register_endpoints(self, backend_names):
1067
1099
backend_url_pattern ,
1068
1100
co_name_pattern ,
1069
1101
endpoint_path )
1070
- logger .debug ("Created URL regex {}" .format (regex_pattern ))
1102
+ logline = "Created URL regex {}" .format (regex_pattern )
1103
+ logger .debug (logline )
1071
1104
1072
1105
# Map the regex pattern to a callable.
1073
1106
the_callable = functools .partial (self .handle_authn_request ,
@@ -1076,6 +1109,7 @@ def _register_endpoints(self, backend_names):
1076
1109
1077
1110
mapping = (regex_pattern , the_callable )
1078
1111
url_to_callable_mappings .append (mapping )
1079
- logger .debug ("Adding mapping {}" .format (mapping ))
1112
+ logline = "Adding mapping {}" .format (mapping )
1113
+ logger .debug (logline )
1080
1114
1081
1115
return url_to_callable_mappings
0 commit comments