Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Commit 1f6ea86

Browse files
author
Roland Hedberg
committed
Updated to use pyjwkest 0.2.0
Fixed a lot of PEP-8 errors
1 parent 1b69881 commit 1f6ea86

File tree

8 files changed

+219
-191
lines changed

8 files changed

+219
-191
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright 2013 Roland Hedberg. All rights reserved.
2+
3+
Redistribution and use in source and binary forms, with or without modification, are
4+
permitted provided that the following conditions are met:
5+
6+
1. Redistributions of source code must retain the above copyright notice, this list of
7+
conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list
10+
of conditions and the following disclaimer in the documentation and/or other materials
11+
provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY ROLAND HEDBERG ``AS IS'' AND ANY EXPRESS OR IMPLIED
14+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
15+
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ROLAND HEDBERG OR
16+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
21+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

idp.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ def application(environ, start_response):
129129
return idp_srv.logo(environ, start_response, SERVER_ENV)
130130
elif path == "/logout":
131131
return idp_srv.logout(environ, start_response, sid, SERVER_ENV)
132-
elif generateMetadata is not None and generateMetadata.verifyHandleRequest(
132+
elif generateMetadata is not None and generateMetadata.verify_handle_request(
133133
path):
134-
return generateMetadata.handleRequest(environ, start_response, path)
134+
return generateMetadata.handle_request(environ, start_response, path)
135135
else:
136136
environ['idpproxy.url_args'] = ""
137137
return idp_srv.auth_choice(path, environ, start_response, sid,
@@ -263,16 +263,17 @@ def usage():
263263
_key = None
264264
idp_conf = import_module(args.config)
265265
metadata = idp_conf.CONFIG["metadata"]
266+
267+
#noinspection PyUnboundLocalVariable
268+
_idp = setup_server_env(idp_proxy_conf, args.config, key)
269+
266270
if _key:
267271
generateMetadata = MetadataGeneration(
268272
logger, idp_proxy_conf.SERVICE, publicKey=_key, privateKey=key,
269-
metadataList=[metadata])
273+
metadataList=[metadata], idp_conf=_idp.config)
270274
else:
271275
generateMetadata = None
272276

273-
#noinspection PyUnboundLocalVariable
274-
_idp = setup_server_env(idp_proxy_conf, args.config, key)
275-
276277
print SERVER_ENV["base_url"]
277278
SRV = wsgiserver.CherryPyWSGIServer(('0.0.0.0', SERVER_ENV["PORT"]),
278279
application)

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./idp.py -r 'keys/idptest.key' idp_conf
1+
./idp.py -r 'pki/mykey.pem' idp_conf

src/idpproxy/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ def authn_response(server_env, req_info, userid, identity,
162162
# -----------------------------------------------------------------------------
163163

164164

165-
#noinspection PyUnusedLocal
166-
def get_eptid(server_env, req_info, identity, session):
165+
def get_eptid(server_env, req_info, session):
167166
return server_env["eptid"].get(server_env["idp"].config.entityid,
168167
req_info.sender(), session["permanent_id"],
169168
session["authn_auth"])
@@ -181,7 +180,7 @@ def do_req_response(server_env, req_info, response, environ, source,
181180
userid = identity["uid"]
182181
if "eduPersonTargetedID" not in identity:
183182
identity["eduPersonTargetedID"] = get_eptid(server_env, req_info,
184-
identity, session)
183+
session)
185184
else:
186185
userid = "anonymous"
187186

src/idpproxy/idp_srv.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
AUTH_CHOICE = BASE + "AuthChoice"
1919
POLICY = "policy.html"
2020

21+
2122
def not_found(environ, start_response, text):
2223
resp = NotFound(text)
2324
return resp(environ, start_response)
2425

26+
2527
def match(path, service):
2628
"""
2729
@@ -41,6 +43,7 @@ def match(path, service):
4143

4244
return pp[0] == service
4345

46+
4447
def local_path(path):
4548
# First non-'' part is the service name
4649

@@ -102,7 +105,7 @@ def auth_choice(path, environ, start_response, sid, server_env):
102105

103106
environ['idpproxy.url_args'] = local_path(path)
104107
_cache = server_env["CACHE"]
105-
if func_name == "callback": # Callback from the Social service
108+
if func_name == "callback": # Callback from the Social service
106109
try:
107110
query = parse_qs(environ["QUERY_STRING"])
108111
except KeyError:
@@ -114,7 +117,7 @@ def auth_choice(path, environ, start_response, sid, server_env):
114117
except KeyError:
115118
exception_log()
116119
return bad_request(environ, start_response, "Unknown session")
117-
else: # This is the SAML endpoint
120+
else: # This is the SAML endpoint
118121
# Should I support mote then HTTP redirect
119122
_dict = unpack_redirect(environ)
120123
if _dict is None:
@@ -129,8 +132,8 @@ def auth_choice(path, environ, start_response, sid, server_env):
129132
logger.debug("Query: %s" % query)
130133

131134
try:
132-
req_info = server_env["idp"].parse_authn_request(query,
133-
BINDING_HTTP_REDIRECT)
135+
req_info = server_env["idp"].parse_authn_request(
136+
query, BINDING_HTTP_REDIRECT)
134137
except KeyError:
135138
exception_log()
136139
return bad_request(environ, start_response,
@@ -145,18 +148,17 @@ def auth_choice(path, environ, start_response, sid, server_env):
145148
except KeyError:
146149
pass
147150

148-
logger.debug("type req_info: %s message: %s" % (type(req_info),
149-
type(req_info.message)))
151+
logger.debug("type req_info: %s message: %s" % (
152+
type(req_info), type(req_info.message)))
150153

151154
entity_id = req_info.sender()
152155
_cache.set(sid, {"req_info": req_info, "entity_id": entity_id})
153156
else:
154157
return not_found(environ, start_response, "No query")
155158

156159
logger.debug("SID: %s" % sid)
157-
cookie = server_env["CACHE"].create_cookie(sid,
158-
path="/%s" % _dic["social_endpoint"],
159-
expire=60)
160+
cookie = server_env["CACHE"].create_cookie(
161+
sid, path="/%s" % _dic["social_endpoint"], expire=60)
160162

161163
logger.debug("NEW COOKIE: %s" % (cookie,))
162164
#logger.debug("_dic: %s" % (_dic,))
@@ -186,6 +188,7 @@ def logo(environ, start_response, serv_env):
186188

187189
# ----------------------------------------------------------------------------
188190

191+
189192
def logout(environ, start_response, sid, server_env):
190193
msg = ""
191194
resp = Response(msg)

0 commit comments

Comments
 (0)