From c8edb28d5b9a6b1d65c76978ac4388ef351eb6e8 Mon Sep 17 00:00:00 2001 From: Hank Leininger Date: Wed, 2 Apr 2014 22:00:28 -0400 Subject: [PATCH] Change examples to bind to 127.0.0.1 by default. Since the README already says to point a browser at localhost, it was surprising to see the listeners bound to 0.0.0.0 by default. Changed that and added notes in README about how to change it if the user really wants to make a test listener accessible externally. Updated output messages during startup to include the bound IP, to make this more obvious. Added a missing EOL or two. --- example/README | 4 ++++ example/idp2/idp.py | 5 +++-- example/idp2_repoze/idp.py | 5 +++-- example/sp-repoze/sp.py | 5 +++-- example/sp-wsgi/service_conf.py | 3 ++- example/sp-wsgi/sp.py | 5 +++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/example/README b/example/README index 70d8cca..03aa4e1 100644 --- a/example/README +++ b/example/README @@ -25,6 +25,10 @@ To run the setup do and then use your favourite webbrowser to look at "http://localhost:8087/whoami" +Note, the listeners are all configured to bind to localhost (127.0.0.1) only. +If you want to be able to connect to them externally, grep "HOST = '127.0.0.1'" +example/*/*.py and replace 127.0.0.1 with 0.0.0.0 or a specific IP. + ./all.sh stop will of course stop your IdP and SP. diff --git a/example/idp2/idp.py b/example/idp2/idp.py index 3828d41..9fdaf5a 100755 --- a/example/idp2/idp.py +++ b/example/idp2/idp.py @@ -976,10 +976,11 @@ if __name__ == '__main__': module_directory=_rot + 'modules', input_encoding='utf-8', output_encoding='utf-8') + HOST = '127.0.0.1' PORT = 8088 - SRV = make_server('', PORT, application) - print "IdP listening on port: %s" % PORT + SRV = make_server(HOST, PORT, application) + print "IdP listening on %s:%s" % (HOST, PORT) SRV.serve_forever() else: _rot = args.mako_root diff --git a/example/idp2_repoze/idp.py b/example/idp2_repoze/idp.py index 562ce51..4729392 100755 --- a/example/idp2_repoze/idp.py +++ b/example/idp2_repoze/idp.py @@ -977,10 +977,11 @@ if __name__ == '__main__': module_directory=_rot + 'modules', input_encoding='utf-8', output_encoding='utf-8') + HOST = '127.0.0.1' PORT = 8088 - SRV = make_server('', PORT, application) - print "IdP listening on port: %s" % PORT + SRV = make_server(HOST, PORT, application) + print "IdP listening on %s:%s" % (HOST, PORT) SRV.serve_forever() else: _rot = args.mako_root diff --git a/example/sp-repoze/sp.py b/example/sp-repoze/sp.py index f16cc39..a0af4e7 100755 --- a/example/sp-repoze/sp.py +++ b/example/sp-repoze/sp.py @@ -268,6 +268,7 @@ app_with_auth = make_middleware_with_config(application, {"here": "."}, log_file="repoze_who.log") # ---------------------------------------------------------------------------- +HOST = '127.0.0.1' PORT = 8087 # allow uwsgi or gunicorn mount @@ -291,6 +292,6 @@ if __name__ == '__main__': args = parser.parse_args() from wsgiref.simple_server import make_server - srv = make_server('', PORT, app_with_auth) - print "SP listening on port: %s" % PORT + srv = make_server(HOST, PORT, app_with_auth) + print "SP listening on %s:%s" % (HOST, PORT) srv.serve_forever() diff --git a/example/sp-wsgi/service_conf.py b/example/sp-wsgi/service_conf.py index e5dbf17..ad6c847 100644 --- a/example/sp-wsgi/service_conf.py +++ b/example/sp-wsgi/service_conf.py @@ -1,5 +1,6 @@ from saml2.assertion import Policy +HOST = '127.0.0.1' PORT = 8087 HTTPS = False @@ -13,4 +14,4 @@ POLICY = Policy( # HTTPS cert information SERVER_CERT = "pki/ssl.crt" SERVER_KEY = "pki/ssl.pem" -CERT_CHAIN = "" \ No newline at end of file +CERT_CHAIN = "" diff --git a/example/sp-wsgi/sp.py b/example/sp-wsgi/sp.py index 05fcc03..f940f29 100755 --- a/example/sp-wsgi/sp.py +++ b/example/sp-wsgi/sp.py @@ -683,6 +683,7 @@ def application(environ, start_response): # ---------------------------------------------------------------------------- +HOST = service_conf.HOST PORT = service_conf.PORT # ------- HTTPS ------- # These should point to relevant files @@ -727,13 +728,13 @@ if __name__ == '__main__': add_urls() - SRV = wsgiserver.CherryPyWSGIServer(('0.0.0.0', PORT), application) + SRV = wsgiserver.CherryPyWSGIServer((HOST, PORT), application) if service_conf.HTTPS: SRV.ssl_adapter = ssl_pyopenssl.pyOpenSSLAdapter(SERVER_CERT, SERVER_KEY, CERT_CHAIN) logger.info("Server starting") - print "SP listening on port: %s" % PORT + print "SP listening on %s:%s" % (HOST, PORT) try: SRV.start() except KeyboardInterrupt: