Ignore:
Timestamp:
01/09/08 14:37:03 (13 years ago)
Author:
cbyrom
Message:

Create new utility module, ClassFactory? - to allow generic instantiation
of classes dynamically.

Implement use of this in the AttAuth? and SessionMgr? services + adjust
the config files for these accordingly + abstract use of MyProxy? in
SessionMgr? to generic authNService - and create packages with real
and test authN services. Adjust the SessionMgr? tests to use the
test authN service.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/ndg.security.server/ndg/security/server/AttAuthority/__init__.py

    r4139 r4158  
    4141 
    4242from ndg.security.common.utils.ConfigFileParsers import readAndValidateProperties 
     43from ndg.security.common.utils.ClassFactory import instantiateClass 
    4344 
    4445#_____________________________________________________________________________ 
     
    130131        read.  Set this flag to False to override. 
    131132        """ 
    132         log.info("Initialising service ... ") 
     133        log.info("Initialising service ...") 
    133134         
    134135        # Base class initialisation 
     
    182183        self.__issuerSerialNumber = self.__cert.serialNumber 
    183184         
    184          
    185185        # Load host sites custom user roles interface to enable the AA to 
    186186        # assign roles in an attribute certificate on a getAttCert request 
    187         self.loadUserRolesInterface() 
    188  
     187        self.__userRoles = instantiateClass(self.__prop['userRolesModName'],\ 
     188                                                 self.__prop['userRolesClassName'],\ 
     189                                                 moduleFilePath=self.__prop.get('userRolesModFilePath'),\ 
     190                                                 objectType=AAUserRoles, \ 
     191                                                 classProperties=self.__prop.get('userRolesPropFile')) 
    189192 
    190193        attCertFilePath = os.path.join(self.__prop['attCertDir'], 
     
    201204        ''' 
    202205        # Configuration file properties are held together in a dictionary 
    203         self.__prop = readAndValidateProperties(self.propFilePath, validKeys=AttAuthority.__validKeys) 
     206        self.__prop = readAndValidateProperties(self.propFilePath, \ 
     207                                                validKeys=AttAuthority.__validKeys) 
    204208         
    205209        # add the WS-security properties to the main properties 
     
    220224            'Invalid directory path Attribute Certificates store "%s": %s' % \ 
    221225                (self.__prop['attCertDir'], osError.strerror) 
    222  
    223     #_________________________________________________________________________ 
    224     def loadUserRolesInterface(self): 
    225         """Set-up user roles interface - load host sites custom AAUserRoles 
    226         derived class.  This class interfaces with the sites mechanism for 
    227         mapping user ID to the roles to which they are entitled.  This 
    228         could be via a user database""" 
    229  
    230         log.debug("Loading User roles interface ...") 
    231         try: 
    232             try: 
    233                 # Module file path may be None if the new module to be loaded 
    234                 # can be found in the existing system path             
    235                 if self.__prop['userRolesModFilePath'] is not None: 
    236                     if not os.path.exists(\ 
    237                               self.__prop['userRolesModFilePath']): 
    238                         raise Exception, "File path '%s' doesn't exist" % \ 
    239                               self.__prop['userRolesModFilePath'] 
    240                                
    241                     # Temporarily extend system path ready for import 
    242                     sysPathBak = sys.path[:] 
    243                                
    244                     sys.path.append(self.__prop['userRolesModFilePath']) 
    245                  
    246                 # Import module name specified in properties file 
    247                 userRolesMod = __import__(self.__prop['userRolesModName'], 
    248                                           globals(), 
    249                                           locals(), 
    250                                           [self.__prop['userRolesClassName']]) 
    251      
    252                 userRolesClass = eval('userRolesMod.' + \ 
    253                                      self.__prop['userRolesClassName']) 
    254             finally: 
    255                 try: 
    256                     sys.path[:] = sysPathBak 
    257                 except NameError: 
    258                     # sysPathBak may not have been defined 
    259                     pass 
    260                                  
    261         except Exception, e: 
    262             raise AttAuthorityError,'Importing User Roles module: %s' % str(e) 
    263  
    264         # Check class inherits from AAUserRoles abstract base class 
    265         if not issubclass(userRolesClass, AAUserRoles): 
    266             raise AttAuthorityError, \ 
    267                 "User Roles class %s must be derived from AAUserRoles" % \ 
    268                 self.__prop['userRolesClassName'] 
    269  
    270  
    271         # Instantiate custom class 
    272         try: 
    273             self.__userRoles=userRolesClass(self.__prop['userRolesPropFile']) 
    274              
    275         except Exception, e: 
    276             raise AttAuthorityError, \ 
    277                 "Error instantiating User Roles interface: " + str(e) 
    278                  
    279         log.info(\ 
    280              'Instantiated "%s" class from user roles module: "%s" in "%s"' %\ 
    281                  (self.__prop['userRolesClassName'], 
    282                   self.__prop['userRolesModName'], 
    283                   self.__prop['userRolesModFilePath'])) 
    284226 
    285227         
Note: See TracChangeset for help on using the changeset viewer.