source: TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/openid/provider/axinterface/sessionmanager.py @ 5168

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/openid/provider/axinterface/sessionmanager.py@5168
Revision 5168, 3.4 KB checked in by pjkersha, 12 years ago (diff)

Added new access control interface and functionality to OpenID Provider to enable a custom context object to be passed between login and logout calls.

Line 
1"""NDG Security OpenID Provider AX Interface for Session Manager based
2authentication
3
4This enables an OpenID Provider's to return a URI for the associated Session
5Manager
6
7NERC DataGrid Project
8"""
9__author__ = "P J Kershaw"
10__date__ = "27/03/09"
11__copyright__ = "(C) 2009 Science and Technology Facilities Council"
12__license__ = "BSD - see LICENSE file in top-level directory"
13__contact__ = "Philip.Kershaw@stfc.ac.uk"
14__revision__ = "$Id$"
15import logging
16log = logging.getLogger(__name__)
17from string import Template
18from sqlalchemy import create_engine
19
20from ndg.security.server.wsgi.openid.provider.axinterface import \
21    AXInterface, AXInterfaceConfigError, MissingRequiredAttrs
22   
23   
24class SessionManagerAXInterface(AXInterface):
25    '''Authentication interface class for OpenIDProviderMiddleware to enable
26    authentication to a Session Manager instance running in the same WSGI
27    stack or via a SOAP call to a remote service
28   
29    @type uriKeyName: basestring
30    @cvar uriKeyName: expected key name in config for Session Manager
31    endpoint'''
32   
33    propertyNames = (
34        'sessionManagerURI', 
35        'sessionManagerURITypeURI',
36        'sessionId',
37        'sessionIdTypeURI')
38   
39    def __init__(self, **cfg):
40        """Copy session manager URI setting from the input config dict
41       
42        @type **cfg: dict
43        @param **cfg: dict containing the Session Manager URI setting
44        @raise AuthNInterfaceConfigError: error with configuration
45        """
46        for name in SessionManagerAXInterface.propertyNames:
47            val = cfg.get(name)
48            if val is None:
49                raise AXInterfaceConfigError("Missing configuration setting: "
50                                             "%s" % val)   
51                   
52            setattr(self, name, val)
53       
54    def __call__(self, ax_req, ax_resp, authNInterfaceCtx):
55        """Add the attributes to the ax_resp object requested in the ax_req
56        object.  If it is not possible to return them, raise
57        MissingRequiredAttrs error
58       
59        @type ax_req: openid.extensions.ax.FetchRequest
60        @param ax_req: attribute exchange request object.  To find out what
61        attributes the Relying Party has requested for example, call
62        ax_req.getRequiredAttrs()
63        @type ax_resp: openid.extensions.ax.FetchResponse
64        @param ax_resp: attribute exchange response object.  This method should
65        update the settings in this object.  Use addValue and setValues methods
66        @type authNInterfaceCtx: AuthNInterfaceCtx
67        @param authNInterfaceCtx: custom authentication context information set
68        at login.  See ndg.security.server.openid.provider.AuthNInterfaceCtx
69        for more information
70        """
71        reqAttrURIs = ax_req.getRequiredAttrs()
72        if self.sessionManagerURITypeURI in reqAttrURIs:
73            ax_resp.addValue(self.sessionManagerURITypeURI,
74                             self.sessionManagerURI)
75           
76        if self.sessionIdTypeURI in reqAttrURIs:
77            if not isinstance(authNInterfaceCtx, AuthNInterfaceCtx):
78                raise AXInterfaceConfigError("Expecting AuthNInterfaceCtx "
79                                        "type for authNInterfaceCtx arg; "
80                                        "got: %s" % 
81                                        authNInterfaceCtx.__class__.__name__)
82               
83            ax_resp.addValue(self.sessionIdTypeURI,authNInterfaceCtx.sessionId)
Note: See TracBrowser for help on using the repository browser.