@@ -120,7 +120,7 @@ def unpack_either(self):
120
120
121
121
def operation (self , _dict , binding ):
122
122
logger .debug ("_operation: %s" % _dict )
123
- if not _dict :
123
+ if not _dict or not 'SAMLRequest' in _dict :
124
124
resp = BadRequest ('Error parsing request or no request' )
125
125
return resp (self .environ , self .start_response )
126
126
else :
@@ -335,8 +335,13 @@ def redirect(self):
335
335
self .req_info = _info ["req_info" ]
336
336
del IDP .ticket [_key ]
337
337
except KeyError :
338
- self .req_info = IDP .parse_authn_request (_info ["SAMLRequest" ],
339
- BINDING_HTTP_REDIRECT )
338
+ try :
339
+ self .req_info = IDP .parse_authn_request (_info ["SAMLRequest" ],
340
+ BINDING_HTTP_REDIRECT )
341
+ except KeyError :
342
+ resp = BadRequest ("Message signature verification failure" )
343
+ return resp (self .environ , self .start_response )
344
+
340
345
_req = self .req_info .message
341
346
342
347
if "SigAlg" in _info and "Signature" in _info : # Signed request
@@ -547,8 +552,11 @@ def do(self, request, binding, relay_state=""):
547
552
if msg .name_id :
548
553
lid = IDP .ident .find_local_id (msg .name_id )
549
554
logger .info ("local identifier: %s" % lid )
550
- del IDP .cache .uid2user [IDP .cache .user2uid [lid ]]
551
- del IDP .cache .user2uid [lid ]
555
+ if lid in IDP .cache .user2uid :
556
+ uid = IDP .cache .user2uid [lid ]
557
+ if uid in IDP .cache .uid2user :
558
+ del IDP .cache .uid2user [uid ]
559
+ del IDP .cache .user2uid [lid ]
552
560
# remove the authentication
553
561
try :
554
562
IDP .session_db .remove_authn_statements (msg .name_id )
@@ -843,6 +851,19 @@ def metadata(environ, start_response):
843
851
logger .error ("An error occured while creating metadata:" + ex .message )
844
852
return not_found (environ , start_response )
845
853
854
+ def staticfile (environ , start_response ):
855
+ try :
856
+ path = args .path
857
+ if path is None or len (path ) == 0 :
858
+ path = os .path .dirname (os .path .abspath (__file__ ))
859
+ if path [- 1 ] != "/" :
860
+ path += "/"
861
+ path += environ .get ('PATH_INFO' , '' ).lstrip ('/' )
862
+ start_response ('200 OK' , [('Content-Type' , "text/xml" )])
863
+ return open (path , 'r' ).read ()
864
+ except Exception as ex :
865
+ logger .error ("An error occured while creating metadata:" + ex .message )
866
+ return not_found (environ , start_response )
846
867
847
868
def application (environ , start_response ):
848
869
"""
@@ -900,19 +921,40 @@ def application(environ, start_response):
900
921
return func ()
901
922
return callback (environ , start_response , user )
902
923
924
+ if re .search (r'static/.*' , path ) is not None :
925
+ return staticfile (environ , start_response )
903
926
return not_found (environ , start_response )
904
927
905
928
# ----------------------------------------------------------------------------
906
929
930
+ # allow uwsgi or gunicorn mount
931
+ # by moving some initialization out of __name__ == '__main__' section.
932
+ # uwsgi -s 0.0.0.0:8088 --protocol http --callable application --module idp
933
+
934
+ args = type ('Config' , (object ,), { })
935
+ args .config = 'idp_conf'
936
+ args .mako_root = './'
937
+ args .path = None
938
+
939
+ import socket
940
+ from idp_user import USERS
941
+ from idp_user import EXTRA
942
+ from mako .lookup import TemplateLookup
943
+
944
+ AUTHN_BROKER = AuthnBroker ()
945
+ AUTHN_BROKER .add (authn_context_class_ref (PASSWORD ),
946
+ username_password_authn , 10 ,
947
+ "http://%s" % socket .gethostname ())
948
+ AUTHN_BROKER .add (authn_context_class_ref (UNSPECIFIED ),
949
+ "" , 0 , "http://%s" % socket .gethostname ())
950
+
951
+ IDP = server .Server (args .config , cache = Cache ())
952
+ IDP .ticket = {}
907
953
908
954
# ----------------------------------------------------------------------------
909
955
910
956
if __name__ == '__main__' :
911
- import socket
912
- from idp_user import USERS
913
- from idp_user import EXTRA
914
957
from wsgiref .simple_server import make_server
915
- from mako .lookup import TemplateLookup
916
958
917
959
parser = argparse .ArgumentParser ()
918
960
parser .add_argument ('-p' , dest = 'path' , help = 'Path to configuration file.' )
@@ -937,16 +979,11 @@ def application(environ, start_response):
937
979
938
980
PORT = 8088
939
981
940
- AUTHN_BROKER = AuthnBroker ()
941
- AUTHN_BROKER .add (authn_context_class_ref (PASSWORD ),
942
- username_password_authn , 10 ,
943
- "http://%s" % socket .gethostname ())
944
- AUTHN_BROKER .add (authn_context_class_ref (UNSPECIFIED ),
945
- "" , 0 , "http://%s" % socket .gethostname ())
946
-
947
- IDP = server .Server (args .config , cache = Cache ())
948
- IDP .ticket = {}
949
-
950
982
SRV = make_server ('' , PORT , application )
951
983
print "IdP listening on port: %s" % PORT
952
984
SRV .serve_forever ()
985
+ else :
986
+ _rot = args .mako_root
987
+ LOOKUP = TemplateLookup (directories = [_rot + 'templates' , _rot + 'htdocs' ],
988
+ module_directory = _rot + 'modules' ,
989
+ input_encoding = 'utf-8' , output_encoding = 'utf-8' )
0 commit comments