Skip to content

Commit 3a9326f

Browse files
author
Roland Hedberg
committed
Merge pull request #265 from its-dirg/example_updates
Updated examples
2 parents a12cc2a + 21e018b commit 3a9326f

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

example/idp2/idp.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import re
88
import socket
99
import time
10+
import ssl
1011

1112
from Cookie import SimpleCookie
1213
from hashlib import sha1
1314
from urlparse import parse_qs
15+
from cherrypy import wsgiserver
16+
from cherrypy.wsgiserver import ssl_pyopenssl
1417

1518
from saml2 import BINDING_HTTP_ARTIFACT
1619
from saml2 import BINDING_URI
@@ -1044,13 +1047,15 @@ def application(environ, start_response):
10441047
parser.add_argument(dest="config")
10451048
args = parser.parse_args()
10461049

1050+
CONFIG = importlib.import_module(args.config)
1051+
10471052
AUTHN_BROKER = AuthnBroker()
10481053
AUTHN_BROKER.add(authn_context_class_ref(PASSWORD),
10491054
username_password_authn, 10,
1050-
"http://%s" % socket.gethostname())
1055+
CONFIG.BASE)
10511056
AUTHN_BROKER.add(authn_context_class_ref(UNSPECIFIED),
1052-
"", 0, "http://%s" % socket.gethostname())
1053-
CONFIG = importlib.import_module(args.config)
1057+
"", 0, CONFIG.BASE)
1058+
10541059
IDP = server.Server(args.config, cache=Cache())
10551060
IDP.ticket = {}
10561061

@@ -1062,6 +1067,17 @@ def application(environ, start_response):
10621067
HOST = CONFIG.HOST
10631068
PORT = CONFIG.PORT
10641069

1065-
SRV = make_server(HOST, PORT, application)
1066-
print("IdP listening on %s:%s" % (HOST, PORT))
1067-
SRV.serve_forever()
1070+
SRV = wsgiserver.CherryPyWSGIServer((HOST, PORT), application)
1071+
1072+
_https = ""
1073+
if CONFIG.HTTPS:
1074+
SRV.ssl_adapter = ssl_pyopenssl.pyOpenSSLAdapter(CONFIG.SERVER_CERT,
1075+
CONFIG.SERVER_KEY, CONFIG.CERT_CHAIN)
1076+
_https = " using SSL/TLS"
1077+
logger.info("Server starting")
1078+
print("IDP listening on %s:%s%s" % (HOST, PORT, _https))
1079+
try:
1080+
SRV.start()
1081+
except KeyboardInterrupt:
1082+
SRV.stop()
1083+

example/idp2/idp_conf.py.example

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ def full_path(local_file):
2828
HOST = 'localhost'
2929
PORT = 8088
3030

31-
BASE = "http://%s:%s" % (HOST, PORT)
31+
HTTPS = True
32+
33+
if HTTPS:
34+
BASE = "https://%s:%s" % (HOST, PORT)
35+
else:
36+
BASE = "http://%s:%s" % (HOST, PORT)
37+
38+
# HTTPS cert information
39+
SERVER_CERT = "pki/mycert.pem"
40+
SERVER_KEY = "pki/mykey.pem"
41+
CERT_CHAIN = ""
3242

3343
CONFIG = {
3444
"entityid": "%s/idp.xml" % BASE,

example/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mako
2+
cherrypy

example/sp-wsgi/sp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ def do(self, response, binding, relay_state="", mtype="response"):
379379
cookie = self.cache.set_cookie(user)
380380

381381
resp = Redirect("/", headers=[
382-
("Location", "/"),
383382
cookie,
384383
])
385384
return resp(self.environ, self.start_response)

0 commit comments

Comments
 (0)