Skip to content

Commit 6466c4e

Browse files
Mark Gregsonc00kiemon5ter
authored andcommitted
Initialize session_info and cleanup code
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent b84d55a commit 6466c4e

File tree

1 file changed

+21
-23
lines changed
  • src/saml2/s2repoze/plugins

1 file changed

+21
-23
lines changed

src/saml2/s2repoze/plugins/sp.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -445,26 +445,25 @@ def identify(self, environ):
445445
"""
446446
#logger = environ.get('repoze.who.logger', '')
447447

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
459449

460450
uri = environ.get('REQUEST_URI', construct_url(environ))
451+
query = parse_dict_querystring(environ)
461452

462453
logger.debug('[sp.identify] uri: %s', uri)
463-
464-
query = parse_dict_querystring(environ)
465454
logger.debug('[sp.identify] query: %s', query)
466455

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:
468467
post = query
469468
binding = BINDING_HTTP_REDIRECT
470469
else:
@@ -482,7 +481,7 @@ def identify(self, environ):
482481
if path_info in self.logout_endpoints:
483482
logout = True
484483

485-
if logout and "SAMLRequest" in post:
484+
if logout and is_request:
486485
print("logout request received")
487486
try:
488487
response = self.saml_client.handle_logout_request(
@@ -494,10 +493,9 @@ def identify(self, environ):
494493
import traceback
495494

496495
traceback.print_exc()
497-
elif "SAMLResponse" not in post:
496+
elif not is_response:
498497
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
501499
environ["post.fieldstorage"] = post
502500
# restore wsgi.input incase that is needed
503501
# only of s2repoze.body is present
@@ -507,20 +505,18 @@ def identify(self, environ):
507505
else:
508506
logger.info("[sp.identify] --- SAMLResponse ---")
509507
# check for SAML2 authN response
510-
#if self.debug:
511508
try:
512509
if logout:
513510
response = \
514511
self.saml_client.parse_logout_request_response(
515-
post["SAMLResponse"][0], binding)
512+
post["SAMLResponse"][0], binding)
516513
if response:
517514
action = self.saml_client.handle_logout_response(
518515
response)
519516

520517
if type(action) == dict:
521518
request = self._handle_logout(action)
522519
else:
523-
#logout complete
524520
request = HTTPSeeOther(headers=[
525521
('Location', "/")])
526522
if request:
@@ -551,9 +547,11 @@ def identify(self, environ):
551547

552548
if session_info:
553549
environ["s2repoze.sessioninfo"] = session_info
554-
return self._construct_identity(session_info)
550+
identity_info = self._construct_identity(session_info)
555551
else:
556-
return None
552+
identity_info = None
553+
554+
return identity_info
557555

558556
# IMetadataProvider
559557
def add_metadata(self, environ, identity):

0 commit comments

Comments
 (0)