40
40
from saml2 .config import config_factory
41
41
from saml2 .profile import paos
42
42
43
- #from saml2.population import Population
43
+ # from saml2.population import Population
44
44
#from saml2.attribute_resolver import AttributeResolver
45
45
46
46
logger = logging .getLogger (__name__ )
@@ -58,6 +58,7 @@ def construct_came_from(environ):
58
58
came_from += '?' + qstr
59
59
return came_from
60
60
61
+
61
62
def exception_trace (tag , exc , log ):
62
63
message = traceback .format_exception (* sys .exc_info ())
63
64
log .error ("[%s] ExcList: %s" % (tag , "" .join (message ),))
@@ -79,12 +80,11 @@ def __call__(self, environ, start_response):
79
80
80
81
81
82
class SAML2Plugin (object ):
82
-
83
83
implements (IChallenger , IIdentifier , IAuthenticator , IMetadataProvider )
84
84
85
85
def __init__ (self , rememberer_name , config , saml_client , wayf , cache ,
86
86
sid_store = None , discovery = "" , idp_query_param = "" ,
87
- sid_store_cert = None ,):
87
+ sid_store_cert = None , ):
88
88
self .rememberer_name = rememberer_name
89
89
self .wayf = wayf
90
90
self .saml_client = saml_client
@@ -130,17 +130,20 @@ def _get_post(self, environ):
130
130
:param environ: A dictionary with environment variables
131
131
"""
132
132
133
- body = ''
133
+ body = ''
134
134
try :
135
- length = int (environ .get ('CONTENT_LENGTH' , '0' ))
135
+ length = int (environ .get ('CONTENT_LENGTH' , '0' ))
136
136
except ValueError :
137
- length = 0
138
- if length != 0 :
137
+ length = 0
138
+ if length != 0 :
139
139
body = environ ['wsgi.input' ].read (length ) # get the POST variables
140
- environ ['s2repoze.body' ] = body # store the request body for later use by pysaml2
141
- environ ['wsgi.input' ] = StringIO (body ) # restore the request body as a stream so that everything seems untouched
140
+ environ [
141
+ 's2repoze.body' ] = body # store the request body for later
142
+ # use by pysaml2
143
+ environ ['wsgi.input' ] = StringIO (body ) # restore the request body
144
+ # as a stream so that everything seems untouched
142
145
143
- post = parse_qs (body ) # parse the POST fields into a dict
146
+ post = parse_qs (body ) # parse the POST fields into a dict
144
147
145
148
logger .debug ('identify post: %s' % (post ,))
146
149
@@ -161,10 +164,11 @@ def _pick_idp(self, environ, came_from):
161
164
"""
162
165
163
166
# check headers to see if it's an ECP request
164
- # headers = {
165
- # 'Accept' : 'text/html; application/vnd.paos+xml',
166
- # 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE, SERVICE)
167
- # }
167
+ # headers = {
168
+ # 'Accept' : 'text/html; application/vnd.paos+xml',
169
+ # 'PAOS' : 'ver="%s";"%s"' % (paos.NAMESPACE,
170
+ # SERVICE)
171
+ # }
168
172
169
173
_cli = self .saml_client
170
174
@@ -262,7 +266,6 @@ def challenge(self, environ, _status, _app_headers, _forget_headers):
262
266
263
267
_cli = self .saml_client
264
268
265
-
266
269
if 'REMOTE_USER' in environ :
267
270
name_id = decode (environ ["REMOTE_USER" ])
268
271
@@ -360,7 +363,7 @@ def challenge(self, environ, _status, _app_headers, _forget_headers):
360
363
361
364
try :
362
365
ret = _cli .config .getattr (
363
- "endpoints" ,"sp" )["discovery_response" ][0 ][0 ]
366
+ "endpoints" , "sp" )["discovery_response" ][0 ][0 ]
364
367
if (environ ["PATH_INFO" ]) in ret and ret .split (
365
368
environ ["PATH_INFO" ])[1 ] == "" :
366
369
query = parse_qs (environ ["QUERY_STRING" ])
@@ -439,8 +442,10 @@ def identify(self, environ):
439
442
#logger = environ.get('repoze.who.logger', '')
440
443
441
444
query = parse_dict_querystring (environ )
442
- if ("CONTENT_LENGTH" not in environ or not environ ["CONTENT_LENGTH" ]) and \
443
- "SAMLResponse" not in query and "SAMLRequest" not in query :
445
+ if ("CONTENT_LENGTH" not in environ or not environ [
446
+ "CONTENT_LENGTH" ]) and \
447
+ "SAMLResponse" not in query and "SAMLRequest" not in \
448
+ query :
444
449
logger .debug ('[identify] get or empty post' )
445
450
return None
446
451
@@ -483,6 +488,7 @@ def identify(self, environ):
483
488
return {}
484
489
except :
485
490
import traceback
491
+
486
492
traceback .print_exc ()
487
493
elif "SAMLResponse" not in post :
488
494
logger .info ("[sp.identify] --- NOT SAMLResponse ---" )
@@ -498,7 +504,8 @@ def identify(self, environ):
498
504
#if self.debug:
499
505
try :
500
506
if logout :
501
- response = self .saml_client .parse_logout_request_response (
507
+ response = \
508
+ self .saml_client .parse_logout_request_response (
502
509
post ["SAMLResponse" ][0 ], binding )
503
510
if response :
504
511
action = self .saml_client .handle_logout_response (
@@ -548,7 +555,8 @@ def add_metadata(self, environ, identity):
548
555
name_id = identity ['repoze.who.userid' ]
549
556
if isinstance (name_id , basestring ):
550
557
try :
551
- # Make sure that userids authenticated by another plugin don't cause problems here.
558
+ # Make sure that userids authenticated by another plugin
559
+ # don't cause problems here.
552
560
name_id = decode (name_id )
553
561
except :
554
562
pass
@@ -602,7 +610,9 @@ def _service_url(environ, qstr=None):
602
610
#noinspection PyUnusedLocal
603
611
def authenticate (self , environ , identity = None ):
604
612
if identity :
605
- if identity .get ('user' ) and environ .get ('s2repoze.sessioninfo' ) and identity .get ('user' ) == environ .get ('s2repoze.sessioninfo' ).get ('ava' ):
613
+ if identity .get ('user' ) and environ .get (
614
+ 's2repoze.sessioninfo' ) and identity .get (
615
+ 'user' ) == environ .get ('s2repoze.sessioninfo' ).get ('ava' ):
606
616
return identity .get ('login' )
607
617
tktuser = identity .get ('repoze.who.plugins.auth_tkt.userid' , None )
608
618
if tktuser and self .saml_client .is_logged_in (decode (tktuser )):
@@ -634,8 +644,7 @@ def make_plugin(remember_name=None, # plugin for remember
634
644
identity_cache = "" ,
635
645
discovery = "" ,
636
646
idp_query_param = ""
637
- ):
638
-
647
+ ):
639
648
if saml_conf is "" :
640
649
raise ValueError (
641
650
'must include saml_conf in configuration' )
0 commit comments