source: TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/openid/relyingparty/signin_interface/buffet/__init__.py @ 5084

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/openid/relyingparty/signin_interface/buffet/__init__.py@5084
Revision 5084, 3.2 KB checked in by pjkersha, 11 years ago (diff)

ndg.security.test.integration.openid - combined OpenID Provider and Relying Party in same WSGI stack: improvements to interface

Line 
1"""NDG Security OpenID Relying Party Buffet based Sign in template
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "20/01/2009"
7__copyright__ = "(C) 2009 Science and Technology Facilities Council"
8__license__ = "BSD - see top-level directory for LICENSE file"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = "$Id$"
11import logging
12log = logging.getLogger(__name__)
13
14from paste.cascade import Cascade
15from paste.registry import RegistryManager
16from paste.urlparser import StaticURLParser
17
18from pylons.templating import Buffet
19
20from ndg.security.server.wsgi.openid.relyingparty import SigninInterface, \
21    SigninInterfaceConfigError
22
23# Boiler plate to create renderer
24class OpenIDRelyingPartyRenderingBuffet(Buffet):
25    def _update_names(self, ns):
26        return ns
27
28class BuffetSigninTemplate(SigninInterface):
29    """Provide Templating for OpenID Relying Party Middleware Sign in interface
30    via Buffet class"""
31
32    propertyDefaults = {
33        'templateType': 'kid', 
34        'templatePackage': None,
35        'staticContentRootDir': './',
36        'baseURL': 'http://localhost',
37        'initialOpenID': '',
38        'logoutURI': '',
39        'leftLogo': None,
40        'leftAlt': None,
41        'ndgLink': 'http://ndg.nerc.ac.uk',
42        'ndgImage': None,
43        'disclaimer': 'Test deployment only',
44        'stfcLink': 'http://www.stfc.ac.uk/',
45        'stfcImage': None,
46        'helpIcon': None
47    }
48       
49    def __init__(self, app, global_conf, **local_conf):
50        '''Extend SignInterface to include config and set-up for Buffet
51        object
52       
53        @type *arg: tuple
54        @param *arg: RenderingInterface parent class arguments
55        @type **opt: dict
56        @param **opt: additional keywords to set-up Buffet rendering'''
57        super(BuffetSigninTemplate, self).__init__(app, 
58                                                   global_conf, 
59                                                   **local_conf)
60       
61        self._buffet = OpenIDRelyingPartyRenderingBuffet(self.templateType, 
62                                            template_root=self.templatePackage)
63       
64        self.title = "Enter your OpenID to Sign in"
65        self.xml = ''
66        self.headExtras = ''
67        self.loginStatus = True
68        self.loggedIn = False
69       
70        # TODO: handle session object scope
71        self.session = {'username': ''}
72       
73        staticApp = StaticURLParser(self.staticContentRootDir)
74        self._app = Cascade([staticApp, self._app], catch=(404, 401))
75       
76    def _render(self, templateName, c=None, **kw):
77        '''Wrapper for Buffet.render'''
78        if c is None:
79            c = self
80           
81        kw['c'] = c
82       
83        rendering = self._buffet.render(template_name=templateName, 
84                                        namespace=kw)
85        return rendering
86   
87    def makeTemplate(self):
88        return self._render('signin', c=self)
89   
90    def getTemplateFunc(self):
91        """Set-up template for OpenID Provider Login"""
92        def _makeTemplate():
93            return self.makeTemplate()
94           
95        return _makeTemplate
96   
97    def __call__(self, environ, start_response):
98        return self._app(environ, start_response)
Note: See TracBrowser for help on using the repository browser.