Skip to content

Commit 4d28828

Browse files
committed
Update tornado version. Remove unnecesary doc. Improve demo
1 parent addb1e2 commit 4d28828

File tree

4 files changed

+22
-43
lines changed

4 files changed

+22
-43
lines changed

README.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ This folder contains a Pyramid project that will be used as demo to show how to
178178

179179
This folder contains a Tornado project that will be used as demo to show how to add SAML support to the Tornado Framework. ``views.py`` (with its ``settings.py``) is the main Flask file that has all the code, this file uses the templates stored at the ``templates`` folder. In the ``saml`` folder we found the ``certs`` folder to store the X.509 public and private key, and the SAML toolkit settings (``settings.json`` and ``advanced_settings.json``).
180180

181+
It requires python3.5 (it's using tornado 6.0.3)
182+
181183
#### setup.py ####
182184

183185
Setup script is the centre of all activity in building, distributing, and installing modules.
@@ -1253,33 +1255,6 @@ First we need to edit the ``saml/settings.json`` file, configure the SP part and
12531255

12541256
Once the SP is configured, the metadata of the SP is published at the ``/metadata`` url. Based on that info, configure the IdP.
12551257

1256-
##### Test with keycloack #####
1257-
1258-
You can test your SP with every compatible IdP, for example Keycloack by Red Hat (Check if you need also authorization and not only authentication )
1259-
1260-
###### Install Docker ######
1261-
1262-
Install docker as suggested by [docker guide](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
1263-
1264-
###### Keycloack starting ######
1265-
1266-
First run:
1267-
* docker run --name keycloackContainer -d -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin -e DB_VENDOR=H2 jboss/keycloak
1268-
1269-
After first run:
1270-
* sudo docker start keycloackContainer
1271-
1272-
Remember to stop keycloack after usage:
1273-
* sudo docker stop keycloackContainer
1274-
1275-
1276-
###### Keycloack useful urls ######
1277-
1278-
* master: http://localhost:8080/auth/admin
1279-
* users: http://localhost:8080/auth/realms/idp_dacd/account/
1280-
* saml request: http://localhost:8080/auth/realms/idp_dacd/protocol/saml
1281-
* metadata: http://localhost:8080/auth/realms/idp_dacd/protocol/saml/descriptor
1282-
12831258
#### How it works ####
12841259

12851260
1. First time you access to the main view (http://localhost:8000), you can select to login and return to the same view or login and be redirected to ``/?attrs`` (attrs view).

demo-tornado/requirements.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1 @@
1-
defusedxml==0.5.0
2-
isodate==0.6.0
3-
lxml==4.3.3
4-
pkgconfig==1.5.1
5-
python3-saml==1.6.0
6-
six==1.12.0
7-
tornado==6.0.2
8-
xmlsec==1.3.3
1+
tornado==6.0.3

demo-tornado/templates/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
{% for err in errors %}
1010
<li>{{err}}</li>
1111
{% end %}
12+
{% if error_reason %}
13+
<span>{{error_reason}}</span>
14+
{% end %}
1215
</ul>
1316
</div>
1417
{% end %}

demo-tornado/views.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,36 @@ class IndexHandler(tornado.web.RequestHandler):
3131
def post(self):
3232
req = prepare_tornado_request(self.request)
3333
auth = init_saml_auth(req)
34+
error_reason = None
3435
attributes = False
3536
paint_logout = False
37+
success_slo = False
3638

3739
auth.process_response()
3840
errors = auth.get_errors()
3941
not_auth_warn = not auth.is_authenticated()
4042

4143
if len(errors) == 0:
42-
session['samlUserdata'] = auth.get_attributes()
43-
session['samlNameId'] = auth.get_nameid()
44-
session['samlSessionIndex'] = auth.get_session_index()
45-
self_url = OneLogin_Saml2_Utils.get_self_url(req)
46-
if 'RelayState' in self.request.arguments and self_url != self.request.arguments['RelayState'][0].decode('utf-8'):
44+
session['samlUserdata'] = auth.get_attributes()
45+
session['samlNameId'] = auth.get_nameid()
46+
session['samlSessionIndex'] = auth.get_session_index()
47+
self_url = OneLogin_Saml2_Utils.get_self_url(req)
48+
if 'RelayState' in self.request.arguments and self_url != self.request.arguments['RelayState'][0].decode('utf-8'):
4749
return self.redirect(self.request.arguments['RelayState'][0].decode('utf-8'))
50+
elif auth.get_settings().is_debug_active():
51+
error_reason = auth.get_last_error_reason()
4852

4953
if 'samlUserdata' in session:
5054
paint_logout = True
5155
if len(session['samlUserdata']) > 0:
5256
attributes = session['samlUserdata'].items()
5357

54-
self.render('index.html',errors=errors,not_auth_warn=not_auth_warn,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)
5559

5660
def get(self):
5761
req = prepare_tornado_request(self.request)
5862
auth = init_saml_auth(req)
63+
error_reason = None
5964
errors = []
6065
not_auth_warn = False
6166
success_slo = False
@@ -90,6 +95,8 @@ def get(self):
9095
self_url = OneLogin_Saml2_Utils.get_self_url(req)
9196
if 'RelayState' in self.request.arguments and self_url != self.request.arguments['RelayState'][0].decode('utf-8'):
9297
return self.redirect(auth.redirect_to(self.request.arguments['RelayState'][0].decode('utf-8')))
98+
elif auth.get_settings().is_debug_active():
99+
error_reason = auth.get_last_error_reason()
93100
elif 'sls' in req['get_data']:
94101
print('-sls-')
95102
dscb = lambda: session.clear() ## clear out the session
@@ -100,14 +107,15 @@ def get(self):
100107
return self.redirect(url)
101108
else:
102109
success_slo = True
103-
110+
elif auth.get_settings().is_debug_active():
111+
error_reason = auth.get_last_error_reason()
104112
if 'samlUserdata' in session:
105113
print('-samlUserdata-')
106114
paint_logout = True
107115
if len(session['samlUserdata']) > 0:
108116
attributes = session['samlUserdata'].items()
109117
print("ATTRIBUTES", attributes)
110-
self.render('index.html',errors=errors,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)
111119

112120
class AttrsHandler(tornado.web.RequestHandler):
113121
def get(self):

0 commit comments

Comments
 (0)