@@ -445,26 +445,25 @@ def identify(self, environ):
445
445
"""
446
446
#logger = environ.get('repoze.who.logger', '')
447
447
448
- query = parse_dict_querystring (environ )
449
- if ("CONTENT_LENGTH" not in environ or not environ [
450
- "CONTENT_LENGTH" ]) and \
451
- "SAMLResponse" not in query and "SAMLRequest" not in \
452
- query :
453
- logger .debug ('[identify] get or empty post' )
454
- return None
455
-
456
- # if logger:
457
- # logger.info("ENVIRON: %s", environ)
458
- # logger.info("self: %s", self.__dict__)
448
+ session_info = None
459
449
460
450
uri = environ .get ('REQUEST_URI' , construct_url (environ ))
451
+ query = parse_dict_querystring (environ )
461
452
462
453
logger .debug ('[sp.identify] uri: %s' , uri )
463
-
464
- query = parse_dict_querystring (environ )
465
454
logger .debug ('[sp.identify] query: %s' , query )
466
455
467
- if "SAMLResponse" in query or "SAMLRequest" in query :
456
+ is_request = "SAMLRequest" in query
457
+ is_response = "SAMLResponse" in query
458
+ has_content_length = \
459
+ "CONTENT_LENGTH" in environ \
460
+ or environ ["CONTENT_LENGTH" ]
461
+
462
+ if not has_content_length and not is_request and not is_response :
463
+ logger .debug ('[identify] get or empty post' )
464
+ return None
465
+
466
+ if is_request or is_response :
468
467
post = query
469
468
binding = BINDING_HTTP_REDIRECT
470
469
else :
@@ -482,7 +481,7 @@ def identify(self, environ):
482
481
if path_info in self .logout_endpoints :
483
482
logout = True
484
483
485
- if logout and "SAMLRequest" in post :
484
+ if logout and is_request :
486
485
print ("logout request received" )
487
486
try :
488
487
response = self .saml_client .handle_logout_request (
@@ -494,10 +493,9 @@ def identify(self, environ):
494
493
import traceback
495
494
496
495
traceback .print_exc ()
497
- elif "SAMLResponse" not in post :
496
+ elif not is_response :
498
497
logger .info ("[sp.identify] --- NOT SAMLResponse ---" )
499
- # Not for me, put the post back where next in line can
500
- # find it
498
+ # Not for me, put the post back where next in line can find it
501
499
environ ["post.fieldstorage" ] = post
502
500
# restore wsgi.input incase that is needed
503
501
# only of s2repoze.body is present
@@ -507,20 +505,18 @@ def identify(self, environ):
507
505
else :
508
506
logger .info ("[sp.identify] --- SAMLResponse ---" )
509
507
# check for SAML2 authN response
510
- #if self.debug:
511
508
try :
512
509
if logout :
513
510
response = \
514
511
self .saml_client .parse_logout_request_response (
515
- post ["SAMLResponse" ][0 ], binding )
512
+ post ["SAMLResponse" ][0 ], binding )
516
513
if response :
517
514
action = self .saml_client .handle_logout_response (
518
515
response )
519
516
520
517
if type (action ) == dict :
521
518
request = self ._handle_logout (action )
522
519
else :
523
- #logout complete
524
520
request = HTTPSeeOther (headers = [
525
521
('Location' , "/" )])
526
522
if request :
@@ -551,9 +547,11 @@ def identify(self, environ):
551
547
552
548
if session_info :
553
549
environ ["s2repoze.sessioninfo" ] = session_info
554
- return self ._construct_identity (session_info )
550
+ identity_info = self ._construct_identity (session_info )
555
551
else :
556
- return None
552
+ identity_info = None
553
+
554
+ return identity_info
557
555
558
556
# IMetadataProvider
559
557
def add_metadata (self , environ , identity ):
0 commit comments