Changeset 4379 for TI12-security/trunk
- Timestamp:
- 29/10/08 10:32:28 (12 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/credentialwallet.py
r4378 r4379 1 """NDG Credential sWallet1 """NDG Credential Wallet 2 2 3 3 NERC Data Grid Project … … 10 10 License, version 1.0 or later.""" 11 11 __contact__ = "P.J.Kershaw@rl.ac.uk" 12 __revision__ = '$Id $'12 __revision__ = '$Id:credentialwallet.py 4378 2008-10-29 10:30:14Z pjkersha $' 13 13 14 14 import logging 15 15 log = logging.getLogger(__name__) 16 16 17 # Temporary store of certificates for use with Cred Wallet getAttCert()17 # Temporary store of certificates for use with CredentialWallet getAttCert() 18 18 import tempfile 19 19 … … 28 28 aaImportError = True 29 29 try: 30 # AttAuthority client package resides with Cred Wallet module in30 # AttAuthority client package resides with CredentialWallet module in 31 31 # ndg.security.common 32 32 from ndg.security.common.attributeauthority import AttributeAuthorityClient, \ … … 35 35 aaImportError = False 36 36 except ImportError: 37 log.warning('Loading Cred Wallet without SOAP interface imports')37 log.warning('Loading CredentialWallet without SOAP interface imports') 38 38 pass 39 39 … … 45 45 aaImportError = False 46 46 except: 47 log.warning('Loading Cred Wallet without Attribute Authority interface '47 log.warning('Loading CredentialWallet without Attribute Authority interface ' 48 48 'imports') 49 49 pass … … 67 67 68 68 69 class _Cred WalletException(Exception):70 """Generic Exception class for Cred Wallet module. Overrides Exception to69 class _CredentialWalletException(Exception): 70 """Generic Exception class for CredentialWallet module. Overrides Exception to 71 71 enable writing to the log""" 72 72 def __init__(self, msg): … … 75 75 76 76 77 class Cred WalletError(_CredWalletException):77 class CredentialWalletError(_CredentialWalletException): 78 78 """Exception handling for NDG Credential Wallet class. Overrides Exception 79 79 to enable writing to the log""" 80 80 81 81 82 class Cred WalletAttributeRequestDenied(CredWalletError):83 """Handling exception where Cred Wallet is denied authorisation by an82 class CredentialWalletAttributeRequestDenied(CredentialWalletError): 83 """Handling exception where CredentialWallet is denied authorisation by an 84 84 Attribute Authority. 85 85 … … 110 110 self.__extAttCertList = kw.pop('extAttCertList', []) 111 111 112 Cred WalletError.__init__(self, *args, **kw)112 CredentialWalletError.__init__(self, *args, **kw) 113 113 114 114 def _getTrustedHostInfo(self): … … 132 132 133 133 134 class _MetaCred Wallet(type):135 """Enable Cred Wallet to have read only class variables e.g.136 137 print Cred Wallet.accessDenied134 class _MetaCredentialWallet(type): 135 """Enable CredentialWallet to have read only class variables e.g. 136 137 print CredentialWallet.accessDenied 138 138 139 139 ... is allowed but, 140 140 141 Cred Wallet.accessDenied = None141 CredentialWallet.accessDenied = None 142 142 143 143 ... raises - AttributeError: can't set attribute""" … … 156 156 157 157 158 # Cred Wallet is a 'new-style' class inheriting from "object" and making use158 # CredentialWallet is a 'new-style' class inheriting from "object" and making use 159 159 # of new Get/Set methods for hiding of attributes 160 class Cred Wallet(object):160 class CredentialWallet(object): 161 161 """Volatile store of user credentials associated with a user session 162 162 … … 266 266 """ 267 267 268 __metaclass__ = _MetaCred Wallet268 __metaclass__ = _MetaCredentialWallet 269 269 270 270 propertyDefaults = dict( … … 329 329 from 330 330 @type cfgPrefix: basestring 331 @param cfgPrefix: apply a prefix to all Cred Wallet config params so331 @param cfgPrefix: apply a prefix to all CredentialWallet config params so 332 332 that if placed in a file with other parameters they can be 333 333 distinguished … … 335 335 @param cfgKw: set parameters as key value pairs.""" 336 336 337 log.debug("Calling Cred Wallet.__init__ ...")337 log.debug("Calling CredentialWallet.__init__ ...") 338 338 339 339 # Initialise attributes - 1st protected ones 340 attr = {}.fromkeys(Cred Wallet._protectedAttrs)340 attr = {}.fromkeys(CredentialWallet._protectedAttrs) 341 341 342 342 # ... then properties 343 attr.update(Cred Wallet.propertyDefaults)343 attr.update(CredentialWallet.propertyDefaults) 344 344 for k, v in attr.items(): 345 345 try: … … 377 377 378 378 if not issubclass(self._credentialRepository,CredentialRepository): 379 raise Cred WalletError("Input Credential Repository instance "379 raise CredentialWalletError("Input Credential Repository instance " 380 380 "must be of a class derived from " 381 381 "\"CredentialRepository\"") … … 405 405 except Exception, e: 406 406 try: 407 raise Cred WalletError("Error parsing Attribute Certificate"407 raise CredentialWalletError("Error parsing Attribute Certificate" 408 408 " ID '%s' retrieved from the " 409 409 "Credentials Repository: %s" % 410 410 (cred.id, e)) 411 411 except: 412 raise Cred WalletError("Error parsing Attribute "412 raise CredentialWalletError("Error parsing Attribute " 413 413 "Certificate retrieved from the " 414 414 "Credentials Repository: %s:" % e) … … 431 431 prop = readAndValidate(cfgFilePath, 432 432 cfg=self._cfg, 433 validKeys=Cred Wallet.propertyDefaults,433 validKeys=CredentialWallet.propertyDefaults, 434 434 prefix=prefix, 435 435 sections=(section,)) … … 670 670 671 671 elif caCertFilePathList is not None: 672 raise Cred WalletError("Input CA Certificate file path is not a "672 raise CredentialWalletError("Input CA Certificate file path is not a " 673 673 "valid string") 674 674 … … 706 706 707 707 elif sslCACertFilePathList is not None: 708 raise Cred WalletError("Input CA Certificate file path is not a "708 raise CredentialWalletError("Input CA Certificate file path is not a " 709 709 "valid string") 710 710 … … 724 724 @return: new Attribute Authority client instance""" 725 725 726 log.debug('Cred Wallet._createAttributeAuthorityClnt for service: "%s"'%726 log.debug('CredentialWallet._createAttributeAuthorityClnt for service: "%s"'% 727 727 attributeAuthorityURI) 728 728 … … 927 927 # Check input 928 928 if not isinstance(attCert, AttCert): 929 raise Cred WalletError("Attribute Certificate must be an AttCert "929 raise CredentialWalletError("Attribute Certificate must be an AttCert " 930 930 "type object") 931 931 … … 935 935 936 936 except AttCertError, e: 937 raise Cred WalletError("Adding Credential: %s" % e)937 raise CredentialWalletError("Adding Credential: %s" % e) 938 938 939 939 … … 981 981 expired or are otherwise invalid.""" 982 982 983 log.debug("Cred Wallet.audit ...")983 log.debug("CredentialWallet.audit ...") 984 984 985 985 # Nb. No signature check is carried out. To do a check, access is … … 1001 1001 removing invalid ones""" 1002 1002 1003 log.debug("Cred Wallet.updateCredentialRepository ...")1003 log.debug("CredentialWallet.updateCredentialRepository ...") 1004 1004 1005 1005 if not self._credentialRepository: 1006 raise Cred WalletError("No Credential Repository has been created "1006 raise CredentialWalletError("No Credential Repository has been created " 1007 1007 "for this wallet") 1008 1008 … … 1039 1039 Attribute Authority""" 1040 1040 1041 log.debug("Cred Wallet._getAttCert ...")1041 log.debug("CredentialWallet._getAttCert ...") 1042 1042 1043 1043 if attributeAuthorityClnt is None: … … 1063 1063 1064 1064 except AttributeRequestDenied, e: 1065 raise Cred WalletAttributeRequestDenied, str(e)1065 raise CredentialWalletAttributeRequestDenied, str(e) 1066 1066 1067 1067 elif self.attributeAuthority is not None: … … 1082 1082 1083 1083 except AttributeAuthorityAccessDenied, e: 1084 raise Cred WalletAttributeRequestDenied, str(e)1084 raise CredentialWalletAttributeRequestDenied, str(e) 1085 1085 1086 1086 except Exception, e: 1087 raise Cred WalletError("Requesting attribute certificate: %s"%e)1087 raise CredentialWalletError("Requesting attribute certificate: %s"%e) 1088 1088 1089 1089 else: 1090 raise Cred WalletError("Error requesting attribute: certificate a "1090 raise CredentialWalletError("Error requesting attribute: certificate a " 1091 1091 "URI or Attribute Authority configuration " 1092 1092 "file must be specified") … … 1096 1096 # for signature check in addCredential() 1097 1097 if self._caCertFilePathList is None: 1098 raise Cred WalletError("No CA certificate has been set")1098 raise CredentialWalletError("No CA certificate has been set") 1099 1099 1100 1100 attCert.certFilePathList = self._caCertFilePathList … … 1130 1130 """ 1131 1131 1132 log.debug('Cred Wallet.getAATrustedHostInfo for role "%s" and service: '1132 log.debug('CredentialWallet.getAATrustedHostInfo for role "%s" and service: ' 1133 1133 '"%s"' % (userRole, attributeAuthorityURI or attributeAuthority)) 1134 1134 if attributeAuthorityURI: … … 1161 1161 1162 1162 else: 1163 raise Cred WalletError("Error requesting trusted hosts info: "1163 raise CredentialWalletError("Error requesting trusted hosts info: " 1164 1164 "a URI or Attribute Authority " 1165 1165 "configuration file must be specified") … … 1226 1226 altered 1227 1227 1228 The list is returned via Cred WalletAttributeRequestDenied exception1228 The list is returned via CredentialWalletAttributeRequestDenied exception 1229 1229 If no value is set, the default value held in 1230 1230 self.mapFromTrustedHosts is used … … 1241 1241 is used. 1242 1242 1243 The list is returned via a Cred WalletAttributeRequestDenied exception1243 The list is returned via a CredentialWalletAttributeRequestDenied exception 1244 1244 object. 1245 1245 … … 1277 1277 @return: Attribute Certificate retrieved from Attribute Authority""" 1278 1278 1279 log.debug("Cred Wallet.getAttCert ...")1279 log.debug("CredentialWallet.getAttCert ...") 1280 1280 1281 1281 # Both these assignments are calling set property methods implicitly! … … 1292 1292 # Find out the site ID for the target AA by calling AA's host 1293 1293 # info WS method 1294 log.debug("Cred Wallet.getAttCert - check AA site ID ...")1294 log.debug("CredentialWallet.getAttCert - check AA site ID ...") 1295 1295 1296 1296 try: … … 1298 1298 aaName = hostInfo.keys()[0] 1299 1299 except Exception, e: 1300 raise Cred WalletError("Getting host info: %s" % e)1300 raise CredentialWalletError("Getting host info: %s" % e) 1301 1301 1302 1302 # Look in the wallet for an AC with the same issuer name … … 1333 1333 1334 1334 if not self.mapFromTrustedHosts: 1335 raise Cred WalletError("A list of trusted hosts has been "1335 raise CredentialWalletError("A list of trusted hosts has been " 1336 1336 "input but mapping from trusted hosts " 1337 1337 "is set to disallowed") … … 1380 1380 pass 1381 1381 1382 raise Cred WalletAttributeRequestDenied, errMsg1382 raise CredentialWalletAttributeRequestDenied, errMsg 1383 1383 1384 1384 … … 1389 1389 return attCert 1390 1390 1391 except Cred WalletAttributeRequestDenied, attributeRequestDenied:1391 except CredentialWalletAttributeRequestDenied, attributeRequestDenied: 1392 1392 if not self.mapFromTrustedHosts and not self.rtnExtAttCertList: 1393 1393 # Creating a mapped certificate is not allowed - raise … … 1412 1412 attributeAuthority=attributeAuthority) 1413 1413 except NoMatchingRoleInTrustedHosts, e: 1414 raise Cred WalletAttributeRequestDenied(1414 raise CredentialWalletAttributeRequestDenied( 1415 1415 'Can\'t get a mapped Attribute Certificate for ' 1416 1416 'the "%s" role' % reqRole) 1417 1417 1418 1418 except Exception, e: 1419 raise Cred WalletError, "Getting trusted hosts: %s" % e1419 raise CredentialWalletError, "Getting trusted hosts: %s" % e 1420 1420 1421 1421 if not trustedHostInfo: 1422 raise Cred WalletAttributeRequestDenied(1422 raise CredentialWalletAttributeRequestDenied( 1423 1423 "Attribute Authority has no trusted hosts with " 1424 1424 "which to make a mapping") … … 1481 1481 1482 1482 if not extAttCertList: 1483 raise Cred WalletAttributeRequestDenied, \1483 raise CredentialWalletAttributeRequestDenied, \ 1484 1484 "No certificates are available with which to " + \ 1485 1485 "make a mapping to the Attribute Authority" … … 1495 1495 "trusted hosts" 1496 1496 1497 raise Cred WalletAttributeRequestDenied(msg,1497 raise CredentialWalletAttributeRequestDenied(msg, 1498 1498 extAttCertList=extAttCertList, 1499 1499 trustedHostInfo=trustedHostInfo) 1500 1500 1501 1501 1502 class CredentialRepositoryError(_Cred WalletException):1502 class CredentialRepositoryError(_CredentialWalletException): 1503 1503 """Exception handling for NDG Credential Repository class.""" 1504 1504 1505 1505 1506 1506 class CredentialRepository: 1507 """Cred Wallet's abstract interface class to a Credential Repository. The1507 """CredentialWallet's abstract interface class to a Credential Repository. The 1508 1508 Credential Repository is abstract store of user currently valid user 1509 1509 credentials. It enables retrieval of attribute certificates from a user's
Note: See TracChangeset
for help on using the changeset viewer.