Changeset 964
- Timestamp:
- 19/05/06 14:33:28 (15 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/NDG/AttAuthority.py
r930 r964 157 157 try: 158 158 # Temporarily extend system path ready for import 159 sysPathBak = sys.path 159 sysPathBak = sys.path[:] 160 160 sys.path.append(self.__prop['usrRolesModFilePath']) 161 161 … … 169 169 self.__prop['usrRolesClassName']) 170 170 finally: 171 sys.path = sysPathBak171 sys.path[:] = sysPathBak 172 172 173 173 except Exception, e: -
TI12-security/trunk/python/NDG/Gatekeeper.py
r930 r964 16 16 import cElementTree as ElementTree 17 17 18 # Alter system path for dynamic import of user rolesclass18 # Alter system path for dynamic import of resource interface class 19 19 import sys 20 20 … … 39 39 40 40 __validKeys = ( 'resrcURI', 41 'resrcURImodFilePath', 42 'resrcURImodName', 43 'resrcURIclassName', 44 'resrcURIpropFile') 41 'resrcModFilePath', 42 'resrcModName', 43 'resrcClassName', 44 'resrcPropFile', 45 'caCertFilePath') 45 46 46 47 #_________________________________________________________________________ … … 48 49 49 50 self.__propFilePath = propFilePath 50 self.__resrc URIobj = None51 self.__resrcObj = None 51 52 self.__prop = {}.fromkeys(self.__validKeys) 52 53 … … 65 66 if max(self.__prop.values()) is not None: 66 67 # Initialize if all required resource URI class properties are set 67 self.initResrc URIinterface()68 self.initResrcinterface() 68 69 69 70 70 71 #_________________________________________________________________________ 71 def initResrc URIinterface(self):72 def initResrcinterface(self): 72 73 """Set-up Resource URI interface to Gatekeeper""" 73 74 … … 75 76 try: 76 77 # Temporarily extend system path ready for import 77 sysPathBak = sys.path 78 sys.path.append(self.__prop['resrc URImodFilePath'])78 sysPathBak = sys.path[:] 79 sys.path.append(self.__prop['resrcModFilePath']) 79 80 80 81 # Import module name specified in properties file 81 resrc URImod = __import__(self.__prop['resrcURImodName'],82 83 84 [self.__prop['resrcURIclassName']])85 86 resrc URIclass = eval('resrcURImod.' + \87 self.__prop['resrcURIclassName'])82 resrcMod = __import__(self.__prop['resrcModName'], 83 globals(), 84 locals(), 85 [self.__prop['resrcClassName']]) 86 87 resrcClass = eval('resrcMod.' + self.__prop['resrcClassName']) 88 88 89 finally: 89 sys.path = sysPathBak90 sys.path[:] = sysPathBak 90 91 91 92 except KeyError, e: … … 97 98 98 99 99 # Check class inherits from GatekeeperResrc URIabstract base class100 if not issubclass(resrc URIclass, GatekeeperResrcURI):100 # Check class inherits from GatekeeperResrc abstract base class 101 if not issubclass(resrcClass, GatekeeperResrc): 101 102 raise GatekeeperError(\ 102 103 "Resource URI interface class %s must be derived from " + \ 103 "GatekeeperResrc URI" % self.__prop['resrcURIclassName'])104 "GatekeeperResrc" % self.__prop['resrcClassName']) 104 105 105 106 106 107 # Instantiate custom class 107 108 try: 108 self.__resrcURIobj = resrcURIclass(\ 109 filePath=self.__prop['resrcURIpropFile']) 109 self.__resrcObj = resrcClass(\ 110 resrcID=self.__prop['resrcID'], 111 filePath=self.__prop['resrcPropFile']) 110 112 except Exception, e: 111 113 raise GatekeeperError(\ … … 123 125 if propFilePath is not None: 124 126 if not isinstance(propFilePath, basestring): 125 raise AttAuthorityError("Input Properties file path " + \127 raise GatekeeperError("Input Properties file path " + \ 126 128 "must be a valid string.") 127 129 … … 130 132 131 133 try: 132 tree = ElementTree.parse(self.__propFilePath)134 elems = ElementTree.parse(self.__propFilePath).getroot() 133 135 134 136 except IOError, ioErr: 135 raise AttAuthorityError(\137 raise GatekeeperError(\ 136 138 "Error parsing properties file \"%s\": %s" % \ 137 139 (ioErr.filename, ioErr.strerror)) 138 139 140 #_________________________________________________________________________ 141 def __call__(self, input): 142 143 if isinstance(input, basestring): 140 141 # Copy properties from file as dictionary 142 self.__prop = dict([(elem.tag, elem.text) for elem in elems]) 143 144 145 # Check for missing properties 146 propKeys = self.__prop.keys() 147 missingKeys = [key for key in Gatekeeper.__validKeys \ 148 if key not in propKeys] 149 if missingKeys != []: 150 raise GatekeeperError("The following properties are " + \ 151 "missing from the properties file: " + \ 152 ', '.join(missingKeys)) 153 154 155 def __formatInput(self, input): 156 """Convert generic input into a list of roles - use with access 157 routines""" 158 159 if isinstance(input, list): 160 # Input is list of roles 161 return input 162 163 elif isinstance(input, basestring): 144 164 # Input is a role 145 roleList = [input] 146 147 elif isinstance(input, list): 148 # Input is list of roles 149 roleList = input 165 return [input] 150 166 151 167 elif isinstance(input, AttCert): 152 168 # Input is an Attribute Certificate 153 roleList = input.getRoles() 169 # Check signature of AttCert 170 try: 171 attCert.isValid(raiseExcep=True, 172 certFilePathList=self.__prop['caCertFilePath']) 173 except Exception, e: 174 raise GateKeeperError, "Access denied for input: %s" % str(e) 175 176 return input.getRoles() 154 177 else: 155 178 raise GatekeeperError("Input must be a role, role list or " + \ 156 179 "Attribute Certificate type") 157 180 181 182 #_________________________________________________________________________ 183 def __call__(self, input): 184 """Get the permissions for the input rile, list of roles or 185 Attribute Certificate containing roles. A Dictionary of permissions 186 are returned indexed by role name. Permissions are expressed as a 187 tuple containing the relevant permissions flags e.g. ('r', 'w', 'x') 188 for read/write/execute permission or e.g. ('x') for exceute only 189 permission""" 190 191 roleList = self.__formatInput(input) 158 192 159 return dict([(role, self.__resrc URIobj.getPermissions(role)) \193 return dict([(role, self.__resrcObj.getPermissions(role)) \ 160 194 for role in roleList]) 161 195 162 196 163 197 getPermissions = __call__ 164 165 198 199 200 #_________________________________________________________________________ 201 def readAccess(self, input): 202 """Determine read access permitted against the given 203 input role/role list or Attribute Certificate roles 204 205 Return a dictionary of booleans for access granted/denied keyed 206 by role name""" 207 208 roleList = self.__formatInput(input) 209 210 return dict([(role, self.__resrcObj.readAccess(role)) \ 211 for role in roleList]) 212 213 214 #_________________________________________________________________________ 215 def writeAccess(self, input): 216 """Determine write access permitted against the given 217 input role/role list or Attribute Certificate roles 218 219 Return a dictionary of booleans for access granted/denied keyed 220 by role name""" 221 222 roleList = self.__formatInput(input) 223 224 return dict([(role, self.__resrcObj.writeAccess(role)) \ 225 for role in roleList]) 226 227 228 #_________________________________________________________________________ 229 def executeAccess(self, input): 230 """Determine execute access permitted against the given 231 input role/role list or Attribute Certificate roles 232 233 Return a dictionary of booleans for access granted/denied keyed 234 by role name""" 235 236 roleList = self.__formatInput(input) 237 238 return dict([(role, self.__resrcObj.executeAccess(role)) \ 239 for role in roleList]) 240 166 241 167 242 #_____________________________________________________________________________ 168 class GatekeeperResrc URIError(Exception):169 """Exception handling for NDG Attribute Authority User Roles interface243 class GatekeeperResrcError(GateKeeperError): 244 """Exception handling for NDG Gatekeeper Resource interface class 170 245 class.""" 171 172 def __init__(self, msg): 173 self.__msg = msg 174 175 def __str__(self): 176 return self.__msg 177 246 pass 178 247 179 248 180 249 #_____________________________________________________________________________ 181 class GatekeeperResrc URI:182 """An abstract base class to define the resource URI-> role interface250 class GatekeeperResrc: 251 """An abstract base class to define the resource -> role interface 183 252 for the Gatekeeper. 184 253 185 254 Each NDG resource should implement a derived class which implements 186 the way a resource roles is served from the given resource URI."""255 the way a resource roles is served from the given resource.""" 187 256 188 257 # User defined class may wish to specify a URI or path for a configuration 189 258 # file 190 def __init__(self, uri=None, filePath=None):191 """ Roles abstract base class - derive from this class to define259 def __init__(self, resrcID=None, filePath=None): 260 """Abstract base class - derive from this class to define 192 261 resource role interface to Gatekeeper""" 193 262 raise NotImplementedError(\ 194 263 self.__init__.__doc__.replace('\n ','')) 195 196 197 def __getRole(self):198 """Derived method should return the role for the resource199 This method is not essential to interface with GateKeeper class"""200 raise NotImplementedError(201 self.__getRole.__doc__.replace('\n ',''))202 203 role = property(fget=__getRole, doc="Access resource access role")204 264 205 265 … … 217 277 raise NotImplementedError( 218 278 self.__getPermissions.__doc__.replace('\n ','')) 279 280 281 def readAccess(self, role): 282 """Derived method should return the role for read access to the 283 resource - should return boolean for access granted/denied""" 284 raise NotImplementedError( 285 self.readAccess.__doc__.replace('\n ','')) 286 287 288 def writeAccess(self, role): 289 """Derived method should return the role for write access to the 290 resource - should return boolean for access granted/denied""" 291 raise NotImplementedError( 292 self.writeAccess.__doc__.replace('\n ','')) 293 294 295 def executeAccess(self, role): 296 """Derived method should return the role for execute access to the 297 resource - should return boolean for access granted/denied""" 298 raise NotImplementedError( 299 self.executeAccess.__doc__.replace('\n ','')) 300 301 -
TI12-security/trunk/python/NDG/log_services_server.py
r920 r964 13 13 version 1.0 or later. 14 14 """ 15 reposID = '$Id$' 16 15 17 import os 16 18 -
TI12-security/trunk/python/Tests/SecurityClientTest.py
r941 r964 105 105 try: 106 106 # Connect as a command line client - a proxyCert is returned 107 proxyCert = self.sessClnt.connect(userName,107 self.proxyCert = self.sessClnt.connect(userName, 108 108 pPhraseFilePath="./tmp", 109 109 createServerSess=True, … … 111 111 clntPriKeyPwd=self.__clntPriKeyPwd) 112 112 print "User '%s' connected to Session Manager:\n%s" % \ 113 (userName, proxyCert)113 (userName, self.proxyCert) 114 114 115 115 except Exception, e: … … 196 196 pdb.set_trace() 197 197 try: 198 proxyCert = open("./proxy.pem").read().strip() 198 # Alternative means of getting proxy cert - from file 199 #self.proxyCert = open("./proxy.pem").read().strip() 200 self.proxyCertConnectTest() 199 201 userAttCert = None 200 202 201 203 ac = self.aaClnt.reqAuthorisation( 202 proxyCert= proxyCert,204 proxyCert=self.proxyCert, 203 205 userAttCert=userAttCert, 204 206 clntPriKeyPwd=self.__clntPriKeyPwd) -
TI12-security/trunk/python/conf/gatekeeperProperties.xml
r930 r964 1 1 <?xml version="1.0" encoding="utf-8"?> 2 2 <gatekeeperProp> 3 <resrcURI></resrcURI> 4 <resrcURImodFilePath></resrcURImodFilePath> 5 <resrcURImodName></resrcURImodName> 6 <resrcURIclassName></resrcURIclassName> 7 <resrcURIpropFile></resrcURIpropFile> 3 <!-- Resource identifier e.g. a URI --> 4 <resrcID></resrcID> 5 <!-- Resource interface class --> 6 <resrcModFilePath></resrcModFilePath> 7 <resrcModName></resrcModName> 8 <resrcClassName></resrcClassName> 9 <resrcPropFile></resrcPropFile> 10 <!-- CA Certificate used in validation of Attribute Certificate XML 11 singature --> 12 <caCertFilePath></caCertFilePath> 8 13 </gatekeeperProp> -
TI12-security/trunk/python/conf/sessionMgrProperties.xml
r784 r964 9 9 <cookieDomain></cookieDomain> 10 10 <myProxyProp> 11 <myProxyServer></myProxyServer>12 <gridSecurityDir></gridSecurityDir>13 <credStorageDir></credStorageDir>14 <openSSLConfFileName></openSSLConfFileName>11 <myProxyServer></myProxyServer> 12 <gridSecurityDir></gridSecurityDir> 13 <credStorageDir></credStorageDir> 14 <openSSLConfFileName></openSSLConfFileName> 15 15 <tmpDir></tmpDir> 16 <path></path>17 <proxyCertMaxLifetime></proxyCertMaxLifetime>18 <proxyCertLifetime></proxyCertLifetime> <!-- in hours -->19 <simpleCACltProp>20 <wsdl></wsdl>21 16 <path></path> 17 <proxyCertMaxLifetime></proxyCertMaxLifetime> 18 <proxyCertLifetime></proxyCertLifetime> <!-- in hours --> 19 <simpleCACltProp> 20 <wsdl></wsdl> 21 <xmlSigKeyFile></xmlSigKeyFile> 22 22 <xmlSigCertFile></xmlSigCertFile> 23 23 <xmlSigCertPPhrase></xmlSigCertPPhrase> 24 </simpleCACltProp> 25 <!--26 <simpleCASrvProp>27 <certExpiryDate></certExpiryDate>28 <certLifetimeDays></certLifetimeDays>29 <certTmpDir></certTmpDir>30 <caCertFile></caCertFile>31 <signExe></signExe>32 <path></path>33 </simpleCASrvProp>34 -->24 </simpleCACltProp 25 <!-- 26 <simpleCASrvProp> 27 <certExpiryDate></certExpiryDate> 28 <certLifetimeDays></certLifetimeDays> 29 <certTmpDir></certTmpDir> 30 <caCertFile></caCertFile> 31 <signExe></signExe> 32 <path></path> 33 </simpleCASrvProp> 34 --> 35 35 </myProxyProp> 36 36 <credReposProp> 37 37 <dbURI></dbURI> 38 38 </credReposProp> 39 39 </sessMgrProp>
Note: See TracChangeset
for help on using the changeset viewer.