5
5
import tornado .httputil
6
6
7
7
from onelogin .saml2 .auth import OneLogin_Saml2_Auth
8
- from onelogin .saml2 .settings import OneLogin_Saml2_Settings
9
8
from onelogin .saml2 .utils import OneLogin_Saml2_Utils
10
9
11
- ## Global session info
10
+ # Global session info
12
11
session = {}
13
12
13
+
14
14
class Application (tornado .web .Application ):
15
15
def __init__ (self ):
16
16
handlers = [
17
17
(r"/" , IndexHandler ),
18
18
(r"/attrs" , AttrsHandler ),
19
- (r"/metadata" ,MetadataHandler ),
19
+ (r"/metadata" , MetadataHandler ),
20
20
]
21
21
settings = {
22
22
"template_path" : Settings .TEMPLATE_PATH ,
@@ -55,7 +55,7 @@ def post(self):
55
55
if len (session ['samlUserdata' ]) > 0 :
56
56
attributes = session ['samlUserdata' ].items ()
57
57
58
- self .render ('index.html' ,errors = errors ,error_reason = error_reason ,not_auth_warn = not_auth_warn ,success_slo = success_slo ,attributes = attributes ,paint_logout = paint_logout )
58
+ self .render ('index.html' , errors = errors , error_reason = error_reason , not_auth_warn = not_auth_warn , success_slo = success_slo , attributes = attributes , paint_logout = paint_logout )
59
59
60
60
def get (self ):
61
61
req = prepare_tornado_request (self .request )
@@ -99,7 +99,7 @@ def get(self):
99
99
error_reason = auth .get_last_error_reason ()
100
100
elif 'sls' in req ['get_data' ]:
101
101
print ('-sls-' )
102
- dscb = lambda : session .clear () # # clear out the session
102
+ dscb = lambda : session .clear () # clear out the session
103
103
url = auth .process_slo (delete_session_cb = dscb )
104
104
errors = auth .get_errors ()
105
105
if len (errors ) == 0 :
@@ -115,7 +115,8 @@ def get(self):
115
115
if len (session ['samlUserdata' ]) > 0 :
116
116
attributes = session ['samlUserdata' ].items ()
117
117
print ("ATTRIBUTES" , attributes )
118
- self .render ('index.html' ,errors = errors ,error_reason = error_reason ,not_auth_warn = not_auth_warn ,success_slo = success_slo ,attributes = attributes ,paint_logout = paint_logout )
118
+ self .render ('index.html' , errors = errors , error_reason = error_reason , not_auth_warn = not_auth_warn , success_slo = success_slo , attributes = attributes , paint_logout = paint_logout )
119
+
119
120
120
121
class AttrsHandler (tornado .web .RequestHandler ):
121
122
def get (self ):
@@ -127,27 +128,28 @@ def get(self):
127
128
if len (session ['samlUserdata' ]) > 0 :
128
129
attributes = session ['samlUserdata' ].items ()
129
130
130
- self .render ('attrs.html' ,paint_logout = paint_logout ,attributes = attributes )
131
+ self .render ('attrs.html' , paint_logout = paint_logout , attributes = attributes )
132
+
131
133
132
134
class MetadataHandler (tornado .web .RequestHandler ):
133
135
def get (self ):
134
136
req = prepare_tornado_request (self .request )
135
137
auth = init_saml_auth (req )
136
138
saml_settings = auth .get_settings ()
137
- #saml_settings = OneLogin_Saml2_Settings(settings=None, custom_base_path=settings.SAML_FOLDER, sp_validation_only=True)
138
139
metadata = saml_settings .get_sp_metadata ()
139
140
errors = saml_settings .validate_metadata (metadata )
140
141
141
142
if len (errors ) == 0 :
142
- #resp = HttpResponse(content=metadata, content_type='text/xml')
143
- self .set_header ('Content-Type' ,'text/xml' )
143
+ # resp = HttpResponse(content=metadata, content_type='text/xml')
144
+ self .set_header ('Content-Type' , 'text/xml' )
144
145
self .write (metadata )
145
146
else :
146
- #resp = HttpResponseServerError(content=', '.join(errors))
147
+ # resp = HttpResponseServerError(content=', '.join(errors))
147
148
self .write (', ' .join (errors ))
148
- #return resp
149
+ # return resp
149
150
150
- def prepare_tornado_request (request ):
151
+
152
+ def prepare_tornado_request (request ):
151
153
152
154
dataDict = {}
153
155
for key in request .arguments :
@@ -164,6 +166,7 @@ def prepare_tornado_request(request):
164
166
}
165
167
return result
166
168
169
+
167
170
def init_saml_auth (req ):
168
171
auth = OneLogin_Saml2_Auth (req , custom_base_path = Settings .SAML_PATH )
169
172
return auth
0 commit comments