1
1
#!/usr/bin/env python
2
- import importlib
3
2
import argparse
4
3
import base64
5
- import re
4
+ import importlib
6
5
import logging
6
+ import os
7
+ import re
8
+ import socket
7
9
import time
8
- from hashlib import sha1
9
10
10
- from urlparse import parse_qs
11
11
from Cookie import SimpleCookie
12
- import os
13
- from saml2 . profile import ecp
12
+ from hashlib import sha1
13
+ from urlparse import parse_qs
14
14
15
- from saml2 import server
16
15
from saml2 import BINDING_HTTP_ARTIFACT
17
16
from saml2 import BINDING_URI
18
17
from saml2 import BINDING_PAOS
19
18
from saml2 import BINDING_SOAP
20
19
from saml2 import BINDING_HTTP_REDIRECT
21
20
from saml2 import BINDING_HTTP_POST
21
+ from saml2 import server
22
22
from saml2 import time_util
23
23
24
24
from saml2 .authn_context import AuthnBroker
35
35
from saml2 .httputil import ServiceError
36
36
from saml2 .ident import Unknown
37
37
from saml2 .metadata import create_metadata_string
38
+ from saml2 .profile import ecp
38
39
from saml2 .s_utils import rndstr
39
40
from saml2 .s_utils import exception_trace
40
41
from saml2 .s_utils import UnknownPrincipal
43
44
from saml2 .sigver import verify_redirect_signature
44
45
from saml2 .sigver import encrypt_cert_from_item
45
46
47
+ from idp_user import USERS
48
+ from idp_user import EXTRA
49
+ from mako .lookup import TemplateLookup
50
+
46
51
logger = logging .getLogger ("saml2.idp" )
47
52
48
53
@@ -716,7 +721,7 @@ def do(self, request, binding, relay_state="", encrypt_cert=None):
716
721
name_id = _query .subject .name_id
717
722
uid = name_id .text
718
723
logger .debug ("Local uid: %s" % uid )
719
- identity = EXTRA [uid ]
724
+ identity = EXTRA [self . user ]
720
725
721
726
# Comes in over SOAP so only need to construct the response
722
727
args = IDP .response_args (_query , [BINDING_SOAP ])
@@ -948,32 +953,6 @@ def application(environ, start_response):
948
953
949
954
# ----------------------------------------------------------------------------
950
955
951
- # allow uwsgi or gunicorn mount
952
- # by moving some initialization out of __name__ == '__main__' section.
953
- # uwsgi -s 0.0.0.0:8088 --protocol http --callable application --module idp
954
-
955
- args = type ('Config' , (object ,), { })
956
- args .config = 'idp_conf'
957
- args .mako_root = './'
958
- args .path = None
959
-
960
- import socket
961
- from idp_user import USERS
962
- from idp_user import EXTRA
963
- from mako .lookup import TemplateLookup
964
-
965
- AUTHN_BROKER = AuthnBroker ()
966
- AUTHN_BROKER .add (authn_context_class_ref (PASSWORD ),
967
- username_password_authn , 10 ,
968
- "http://%s" % socket .gethostname ())
969
- AUTHN_BROKER .add (authn_context_class_ref (UNSPECIFIED ),
970
- "" , 0 , "http://%s" % socket .gethostname ())
971
- CONFIG = importlib .import_module (args .config )
972
- IDP = server .Server (args .config , cache = Cache ())
973
- IDP .ticket = {}
974
-
975
- # ----------------------------------------------------------------------------
976
-
977
956
if __name__ == '__main__' :
978
957
from wsgiref .simple_server import make_server
979
958
@@ -993,6 +972,16 @@ def application(environ, start_response):
993
972
parser .add_argument (dest = "config" )
994
973
args = parser .parse_args ()
995
974
975
+ AUTHN_BROKER = AuthnBroker ()
976
+ AUTHN_BROKER .add (authn_context_class_ref (PASSWORD ),
977
+ username_password_authn , 10 ,
978
+ "http://%s" % socket .gethostname ())
979
+ AUTHN_BROKER .add (authn_context_class_ref (UNSPECIFIED ),
980
+ "" , 0 , "http://%s" % socket .gethostname ())
981
+ CONFIG = importlib .import_module (args .config )
982
+ IDP = server .Server (args .config , cache = Cache ())
983
+ IDP .ticket = {}
984
+
996
985
_rot = args .mako_root
997
986
LOOKUP = TemplateLookup (directories = [_rot + 'templates' , _rot + 'htdocs' ],
998
987
module_directory = _rot + 'modules' ,
@@ -1004,8 +993,3 @@ def application(environ, start_response):
1004
993
SRV = make_server (HOST , PORT , application )
1005
994
print "IdP listening on %s:%s" % (HOST , PORT )
1006
995
SRV .serve_forever ()
1007
- else :
1008
- _rot = args .mako_root
1009
- LOOKUP = TemplateLookup (directories = [_rot + 'templates' , _rot + 'htdocs' ],
1010
- module_directory = _rot + 'modules' ,
1011
- input_encoding = 'utf-8' , output_encoding = 'utf-8' )
0 commit comments