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

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@4905
Revision 4905, 3.2 KB checked in by pjkersha, 11 years ago (diff)

Initial working version of OpenID Relying Party middleware - this is an RP factored out of the original functionality included in the SSO Pylons project.

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        'logoutURI': '',
38        'leftLogo': None,
39        'leftAlt': None,
40        'ndgLink': 'http://ndg.nerc.ac.uk',
41        'ndgImage': None,
42        'disclaimer': 'Test deployment only',
43        'stfcLink': 'http://www.stfc.ac.uk/',
44        'stfcImage': None,
45        'helpIcon': None
46    }
47       
48    def __init__(self, app, global_conf, **local_conf):
49        '''Extend SignInterface to include config and set-up for Buffet
50        object
51       
52        @type *arg: tuple
53        @param *arg: RenderingInterface parent class arguments
54        @type **opt: dict
55        @param **opt: additional keywords to set-up Buffet rendering'''
56        super(BuffetSigninTemplate, self).__init__(app, 
57                                                   global_conf, 
58                                                   **local_conf)
59       
60        self._buffet = OpenIDRelyingPartyRenderingBuffet(self.templateType, 
61                                            template_root=self.templatePackage)
62       
63        self.title = "Enter your OpenID to Sign in"
64        self.xml = ''
65        self.headExtras = ''
66        self.loginStatus = True
67        self.loggedIn = False
68       
69        # TODO: handle session object scope
70        self.session = {'username': ''}
71       
72        staticApp = StaticURLParser(self.staticContentRootDir)
73        self._app = Cascade([staticApp, app])
74       
75    def _render(self, templateName, c=None, **kw):
76        '''Wrapper for Buffet.render'''
77        if c is None:
78            c = self
79           
80        kw['c'] = c
81       
82        rendering = self._buffet.render(template_name=templateName, 
83                                        namespace=kw)
84        return rendering
85   
86    def makeTemplate(self):
87        return self._render('signin', c=self)
88   
89    @classmethod
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.