source: TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/attributeauthority.py @ 5643

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.server/ndg/security/server/wsgi/attributeauthority.py@5643
Revision 5643, 2.9 KB checked in by pjkersha, 11 years ago (diff)

Working Attribute Authority unit test with refactored attribute properties.

Line 
1"""WSGI Middleware to set an Attribute Authority instance in tyhe WSGI environ
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "19/08/09"
7__copyright__ = "(C) 2009 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__revision__ = "$Id$"
11import logging
12log = logging.getLogger(__name__)
13import os
14
15from ndg.security.server.wsgi import NDGSecurityMiddlewareBase
16from ndg.security.server.attributeauthority import AttributeAuthority
17
18
19class AttributeAuthorityMiddleware(NDGSecurityMiddlewareBase):
20    '''WSGI to add an NDG Security Attribute Authority in the environ
21    '''
22    DEFAULT_KEYNAME = 'ndg.security.server.attributeauthority'
23    ENVIRON_KEYNAME_PARAMNAME = 'environKeyName'
24   
25    # Enable Attribute Authority properties to be included in app_conf
26#    propertyDefaults = {
27#        ENVIRON_KEYNAME_PARAMNAME: DEFAULT_KEYNAME
28#    }
29#    propertyDefaults.update(NDGSecurityMiddlewareBase.propertyDefaults)
30#    propertyDefaults.update(AttributeAuthority.propertyDefaults)
31   
32    def __init__(self,app,global_conf,prefix='attributeauthority.',**app_conf):
33        '''Set-up an Attribute Authority instance
34       
35        @type app: callable following WSGI interface
36        @param app: next middleware application in the chain     
37        @type global_conf: dict       
38        @param global_conf: PasteDeploy global configuration dictionary
39        @type prefix: basestring
40        @param prefix: prefix for configuration items
41        @type app_conf: dict       
42        @param app_conf: PasteDeploy application specific configuration
43        dictionary
44        '''
45        # Stop in debugger at beginning of SOAP stub if environment variable
46        # is set
47        self.__debug = bool(os.environ.get('NDGSEC_INT_DEBUG'))
48        if self.__debug:
49            import pdb
50            pdb.set_trace()
51       
52        self._app = app
53
54        # Set key name for attribute authority set in environ
55        self.__keyName = app_conf.pop(
56                        AttributeAuthorityMiddleware.ENVIRON_KEYNAME_PARAMNAME,
57                        AttributeAuthorityMiddleware.DEFAULT_KEYNAME)
58       
59        self.__aa = AttributeAuthority()
60        self.__aa.setProperties(**app_conf)
61        self.__aa.initAttributeInterface()
62        self.__aa.readMapConfig()
63       
64    def __call__(self, environ, start_response):
65        '''Set the Attribute Authority instantiated at initialisation in
66        environ
67       
68        @type environ: dict
69        @param environ: WSGI environment variables dictionary
70        @type start_response: function
71        @param start_response: standard WSGI start response function
72        @rtype: iterable
73        @return: next application in the WSGI stack
74        '''
75        environ[self.__keyName] = self.__aa
76        return self._app(environ, start_response)
77       
Note: See TracBrowser for help on using the repository browser.