Changeset 5666


Ignore:
Timestamp:
25/08/09 11:08:28 (10 years ago)
Author:
pjkersha
Message:

Added AttributeAuthoritySOAPBindingMiddleware class. This extends the ZSI SOAP Binding class ndg.security.server.zsi.attributeauthority.AttributeAuthorityWS by enabling the underlying Attribute Authority instance to be referenced via the WSGI environ. This enables it to be used in conjunction with AttributeAuthorityMiddleware? and the SAML SOAP Binding middleware to serve the same Attribute Authority through two different interfaces: SAML/SOAP and SOAP WSDL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg_security_server/ndg/security/server/wsgi/attributeauthority.py

    r5663 r5666  
    1818 
    1919class AttributeAuthorityMiddleware(NDGSecurityMiddlewareBase): 
    20     '''WSGI to add an NDG Security Attribute Authority in the environ 
     20    '''WSGI to add an NDG Security Attribute Authority in the environ.  This 
     21    enables multiple WSGi filters to access the same underlying Attribute 
     22    Authority instance e.g. provide SAML SOAP and WSDL SOAP based interfaces 
     23    to the same Attribute Authority 
    2124    ''' 
    2225    DEFAULT_KEYNAME = 'ndg.security.server.wsgi.attributeauthority' 
     
    154157                              doc="Attribute Authority SAML attribute query " 
    155158                                  "function") 
     159 
     160 
     161from ndg.security.server.zsi.attributeauthority import AttributeAuthorityWS 
     162 
     163class AttributeAuthoritySOAPBindingMiddlewareConfigError(Exception): 
     164    """Raise if a configuration problem is found""" 
     165     
     166     
     167class AttributeAuthoritySOAPBindingMiddleware(NDGSecurityMiddlewareBase, 
     168                                              AttributeAuthorityWS): 
     169    """Inheritance from NDGSecurityMiddlewareBase provides a __call__ 
     170    implementation which sets a reference to environ as an object attribute. 
     171     
     172    Inheritance from AttributeAuthorityWS enables preservation of the same 
     173    SOAP callbacks but with the  
     174    ndg.security.server.attributeauthority.AttributeAuthority instance provided 
     175    from environ 
     176    """ 
     177    DEFAULT_ATTRIBUTE_AUTHORITY_KEYNAME = \ 
     178                "ndg.security.server.attributeauthority.AttributeAuthority" 
     179    ATTRIBUTE_AUTHORITY_KEYNAME_CFG_OPTNAME = 'attributeAuthorityEnvironKeyName' 
     180              
     181    def __init__(self, app): 
     182        """Don't call AttributeAuthorityWS.__init__ - AttributeAuthority  
     183        instance is provided via environ through upstream  
     184        AttributeAuthorityMiddleware 
     185        """ 
     186        # Call this base class initialiser to set-up the environ attribute 
     187        NDGSecurityMiddlewareBase.__init__(self, app, None) 
     188         
     189        self.__keyName = None 
     190 
     191    def _getKeyName(self): 
     192        return self.__keyName 
     193 
     194    def _setKeyName(self, val): 
     195        if not isinstance(val, basestring): 
     196            raise TypeError('Expecting %r for "keyName" attribute; got %r' % 
     197                            (basestring, type(val))) 
     198        self.__keyName = val 
     199         
     200    keyName = property(fget=_getKeyName,  
     201                       fset=_setKeyName,  
     202                       doc="Key name used to index Attribute Authority in " 
     203                           "environ dictionary")    
     204          
     205    @classmethod 
     206    def filter_app_factory(cls, app, global_conf,  
     207                           prefix='attributeauthority.soapbinding.',  
     208                           **app_conf): 
     209        """Set-up Attribute Authority SOAP Binding middleware using a Paste app 
     210        factory pattern.  Overloaded base class method to enable custom  
     211        settings from app_conf 
     212         
     213        @type app: callable following WSGI interface 
     214        @param app: next middleware application in the chain       
     215        @type global_conf: dict         
     216        @param global_conf: PasteDeploy global configuration dictionary 
     217        @type prefix: basestring 
     218        @param prefix: prefix for configuration items 
     219        @type app_conf: dict         
     220        @param app_conf: PasteDeploy application specific configuration  
     221        dictionary 
     222        """ 
     223        app = AttributeAuthoritySOAPBindingMiddleware(app) 
     224         
     225        optName = prefix + AttributeAuthoritySOAPBindingMiddleware.\ 
     226                                        ATTRIBUTE_AUTHORITY_KEYNAME_CFG_OPTNAME 
     227        defaultValue = AttributeAuthoritySOAPBindingMiddleware.\ 
     228                                        DEFAULT_ATTRIBUTE_AUTHORITY_KEYNAME 
     229                                         
     230        app.keyName = app_conf.get(optName, defaultValue) 
     231         
     232        return app 
     233    
     234    def soap_getAttCert(self, ps): 
     235        '''Retrieve an Attribute Certificate 
     236         
     237        @type ps: ZSI ParsedSoap 
     238        @param ps: client SOAP message 
     239        @rtype: ndg.security.common.zsi.attributeauthority.AttributeAuthority_services_types.getAttCertResponse_Holder 
     240        @return: response''' 
     241        self._setAttributeAuthorityFromEnviron() 
     242        return AttributeAuthorityWS.soap_getAttCert(self, ps) 
     243 
     244    def soap_getHostInfo(self, ps): 
     245        '''Get information about this host 
     246                 
     247        @type ps: ZSI ParsedSoap 
     248        @param ps: client SOAP message 
     249        @rtype: response 
     250        @return: response''' 
     251        self._setAttributeAuthorityFromEnviron() 
     252        return AttributeAuthorityWS.soap_getHostInfo(self, ps) 
     253     
     254    def soap_getAllHostsInfo(self, ps): 
     255        '''Get information about all hosts 
     256                 
     257        @type ps: ZSI ParsedSoap 
     258        @param ps: client SOAP message 
     259        @rtype: tuple 
     260        @return: response object''' 
     261        self._setAttributeAuthorityFromEnviron() 
     262        return AttributeAuthorityWS.soap_getAllHostsInfo(self, ps) 
     263     
     264    def soap_getTrustedHostInfo(self, ps): 
     265        '''Get information about other trusted hosts 
     266                 
     267        @type ps: ZSI ParsedSoap 
     268        @param ps: client SOAP message 
     269        @rtype: tuple 
     270        @return: response object''' 
     271        self._setAttributeAuthorityFromEnviron() 
     272        return AttributeAuthorityWS.soap_getTrustedHostInfo(self, ps) 
     273     
     274     
     275    def _setAttributeAuthorityFromEnviron(self): 
     276        self.aa = self.environ.get(self.keyName) 
     277        if self.aa is None: 
     278            raise AttributeAuthoritySOAPBindingMiddlewareConfigError( 
     279                                'No "%s" key found in environ' % self.keyName) 
Note: See TracChangeset for help on using the changeset viewer.