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

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@5565
Revision 5565, 3.4 KB checked in by pjkersha, 10 years ago (diff)

Important fix for OpenID Relying Party: enable fully configurable URI path for OpenID AuthKit? verify action. AuthKit? requires a patch also.

RevLine 
[4863]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', 
[4905]34        'templatePackage': None,
[4863]35        'staticContentRootDir': './',
36        'baseURL': 'http://localhost',
[5084]37        'initialOpenID': '',
[4905]38        'logoutURI': '',
[4863]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, 
[4905]62                                            template_root=self.templatePackage)
[4863]63       
64        self.title = "Enter your OpenID to Sign in"
65        self.xml = ''
66        self.headExtras = ''
67        self.loginStatus = True
[4905]68        self.loggedIn = False
[4863]69       
[5565]70        # Get Path for AuthKit OpenID verify action
71        verifyPath = local_conf.get('authkit.openid.path.verify', '/verify')
72        self.verifyPath = self.baseURL + verifyPath
73       
[4905]74        # TODO: handle session object scope
75        self.session = {'username': ''}
76       
[4863]77        staticApp = StaticURLParser(self.staticContentRootDir)
[4907]78        self._app = Cascade([staticApp, self._app], catch=(404, 401))
[4863]79       
80    def _render(self, templateName, c=None, **kw):
81        '''Wrapper for Buffet.render'''
82        if c is None:
83            c = self
84           
85        kw['c'] = c
86       
87        rendering = self._buffet.render(template_name=templateName, 
88                                        namespace=kw)
89        return rendering
90   
91    def makeTemplate(self):
92        return self._render('signin', c=self)
93   
94    def getTemplateFunc(self):
95        """Set-up template for OpenID Provider Login"""
96        def _makeTemplate():
97            return self.makeTemplate()
98           
99        return _makeTemplate
100   
101    def __call__(self, environ, start_response):
[4905]102        return self._app(environ, start_response)
Note: See TracBrowser for help on using the repository browser.