from wsgiref.util import setup_testing_defaults ATTR_LIST = ['givenName', 'sn', 'mail', 'uid', 'eppn'] TEMPLATE = """ %(title)s | %(server_name)s

%(title)s | %(server_name)s

%(sub_heading)s

Given Name: %(givenName)s

Surname: %(sn)s

Email: %(mail)s (UID: %(uid)s, EPPN: %(eppn)s)

Environment dump:

         
%(server_attrs)s
          
       
""" def lookup_environ(environ, key): try: var = environ[key] except: var = 'Not found' return var def shib_attr_dict(environ, attribute_list): res = {} for attr in attribute_list: res[attr] = lookup_environ(environ, attr) return res def application(environ, start_response): global ATTR_LIST global TEMPLATE setup_testing_defaults(environ) status = '200 OK' headers = [('Content-type', 'text/html; charset=utf-8')] start_response(status, headers) data = { 'title': 'Shibboleth Test', 'sub_heading': 'Default Shibboleth user attributes', 'server_name': environ['SERVER_NAME'], 'server_attrs': '\n'.join( [("%s: %s" % (key, value)) for key, value in environ.items()]) } data.update(shib_attr_dict(environ, ATTR_LIST)) result = [(TEMPLATE % data).encode("utf-8")] return result # Debug def print_dictionary(dictionary): res = "" for key, value in dictionary.items(): res += "%s: %s\n" % (key, value) return res.encode("utf-8")