source: TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/openidrelyingparty/securedapp.py @ 7077

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/integration/openidrelyingparty/securedapp.py@7077
Revision 7077, 1.7 KB checked in by pjkersha, 11 years ago (diff)
  • Property svn:keywords set to Id
Line 
1class TestOpenIDRelyingPartyMiddleware(object):
2    '''Test Application for the Authentication handler to protect'''
3    response = "Test Authentication redirect application"
4       
5    def __init__(self, app_conf, **local_conf):
6        self.beakerSessionKeyName = app_conf['beakerSessionKeyName']
7   
8    def __call__(self, environ, start_response):
9       
10        username = environ[self.beakerSessionKeyName].get('username')
11        if username:
12            response = """<html>
13    <head/>
14    <body>
15        <p>Authenticated!</p>
16        <p><a href="/logout">logout</a></p>
17    </body>
18</html>"""
19            start_response('200 OK', 
20                           [('Content-type', 'text/html'),
21                            ('Content-length', str(len(response)))])
22        else:
23            response = "Trigger OpenID Relying Party..."
24            start_response('401 Unauthorized', 
25                           [('Content-type', 'text/plain'),
26                            ('Content-length', str(len(response)))])
27        return [response]
28   
29# To start run
30# $ paster serve services.ini or run this file as a script
31# $ ./securedapp.py [port #]
32if __name__ == '__main__':
33    import sys
34    import os
35    from os.path import dirname, abspath
36    import logging
37    logging.basicConfig(level=logging.DEBUG)
38
39    if len(sys.argv) > 1:
40        port = int(sys.argv[1])
41    else:
42        port = 6080
43       
44    cfgFilePath = os.path.join(dirname(abspath(__file__)), 'securedapp.ini')
45       
46    from paste.httpserver import serve
47    from paste.deploy import loadapp
48    from paste.script.util.logging_config import fileConfig
49   
50    fileConfig(cfgFilePath)
51    app = loadapp('config:%s' % cfgFilePath)
52    serve(app, host='0.0.0.0', port=port)
Note: See TracBrowser for help on using the repository browser.