Changeset 1312
- Timestamp:
- 25/07/06 15:20:19 (15 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/NDG/AttAuthority.py
r1215 r1312 488 488 489 489 except Exception, e: 490 raise AttAuthorityError("New Attribute Certificate \"%s\": %s" % \ 491 (attCert.filePath, e)) 492 493 494 495 490 raise AttAuthorityError, "New Attribute Certificate \"%s\": %s" %\ 491 (attCert.filePath, e) 492 493 494 #_________________________________________________________________________ 496 495 def readProperties(self, propFilePath=None): 497 496 … … 503 502 if propFilePath is not None: 504 503 if not isinstance(propFilePath, basestring): 505 raise AttAuthorityError ("Input Properties file path " + \506 "must be a valid string." )504 raise AttAuthorityError, "Input Properties file path " + \ 505 "must be a valid string." 507 506 508 507 self.__propFilePath = propFilePath … … 513 512 514 513 except IOError, ioErr: 515 raise AttAuthorityError (\514 raise AttAuthorityError, \ 516 515 "Error parsing properties file \"%s\": %s" % \ 517 (ioErr.filename, ioErr.strerror) )516 (ioErr.filename, ioErr.strerror) 518 517 519 518 520 519 aaProp = tree.getroot() 521 522 # Copy properties from file as member variables 523 prop = dict([(elem.tag, elem.text) for elem in aaProp]) 524 525 526 # Check for missing properties 527 propKeys = prop.keys() 528 missingKeys = [key for key in AttAuthority.__validKeys \ 529 if key not in propKeys] 520 if aaProp is None: 521 raise AttAuthorityError, \ 522 "Parsing properties file \"%s\": root element is not defined" % \ 523 self.__propFilePath 524 525 526 # Copy properties from file into a dictionary 527 self.__prop = {} 528 missingKeys = [] 529 try: 530 for elem in aaProp: 531 if elem.tag in self.__class__.__validKeys: 532 533 if elem.tag != 'keyPwd' and elem.text: 534 self.__prop[elem.tag] = \ 535 os.path.expandvars(elem.text.strip()) 536 else: 537 self.__prop[elem.tag] = elem.text 538 else: 539 missingKeys.append(elem.tag) 540 541 except Exception, e: 542 raise AttAuthorityError, \ 543 "Error parsing tag \"%s\" in properties file \"%s\": %s" % \ 544 (elem.tag, self.__propFilePath, e) 545 530 546 if missingKeys != []: 531 raise AttAuthorityError("The following properties are " + \ 532 "missing from the properties file: " + \ 533 ', '.join(missingKeys)) 534 535 # Strip white space - apart from fields where may be required 536 for key in prop: 537 if key != 'keyPwd' and prop[key]: 538 prop[key] = prop[key].strip() 539 540 # Check for environment variables in file paths 541 tagCaps = key.upper() 542 if 'FILE' in tagCaps or 'PATH' in tagCaps or 'DIR' in tagCaps: 543 prop[key] = os.path.expandvars(prop[key]) 544 547 raise AttAuthorityError, "The following properties are " + \ 548 "missing from the properties file: " + \ 549 ', '.join(missingKeys) 545 550 546 551 # Ensure Certificate time parameters are converted to numeric type 547 prop['attCertLifeTime'] = float(prop['attCertLifeTime']) 548 prop['attCertNotBeforeOff'] = float(prop['attCertNotBeforeOff']) 549 550 self.__prop = prop 552 self.__prop['attCertLifeTime'] = float(self.__prop['attCertLifeTime']) 553 self.__prop['attCertNotBeforeOff'] = \ 554 float(self.__prop['attCertNotBeforeOff']) 551 555 552 556 … … 556 560 557 561 except OSError, osError: 558 raise AttAuthorityError(\ 559 "Invalid directory path Attribute Certificates store: " + \ 560 osError.strerror) 561 562 raise AttAuthorityError, \ 563 "Invalid directory path Attribute Certificates store: %s" % \ 564 osError.strerror 562 565 563 566 564 567 #_________________________________________________________________________ 565 568 def readMapConfig(self, mapConfigFilePath=None): 566 569 """Parse Map Configuration file. … … 700 703 self.__localRole2RemoteRole[trustedHost][localRole] = \ 701 704 [remoteRole] 702 703 704 705 706 707 #_________________________________________________________________________ 705 708 def usrIsRegistered(self, usrDN): 706 709 """Check a particular user is registered with the Data Centre that the 707 710 Attribute Authority represents""" 708 711 return self.__usrRoles.usrIsRegistered(usrDN) 709 710 711 712 713 712 713 714 #_________________________________________________________________________ 714 715 def getRoles(self, dn): 715 716 """Get the roles available to the registered user identified usrDN. … … 724 725 except Exception, e: 725 726 raise AttAuthorityError("Getting user roles: %s" % e) 726 727 728 729 727 728 729 #_________________________________________________________________________ 730 730 def __getHostInfo(self): 731 731 """Return the host that this Attribute Authority represents: its ID, … … 737 737 hostInfo = property(fget=__getHostInfo, 738 738 doc="Return information about this host") 739 740 741 742 739 740 741 #_________________________________________________________________________ 743 742 def getTrustedHostInfo(self, role=None): 744 743 """Return a dictionary of the hosts that have trust relationships … … 801 800 802 801 return trustedHostInfo 803 804 805 806 802 803 804 #_________________________________________________________________________ 807 805 def mapRemoteRoles2LocalRoles(self, trustedHost, trustedHostRoles): 808 806 """Map roles of trusted hosts to roles for this data centre … … 829 827 830 828 return localRoles 831 832 833 834 829 830 831 #_________________________________________________________________________ 835 832 def __newAttCertFilePath(self): 836 833 """Create a new unique attribute certificate file path""" -
TI12-security/trunk/python/NDG/Session.py
r1303 r1312 561 561 562 562 if propElem is None: 563 raise SessionMgrError("Root element for parsing is not defined") 564 565 for elem in propElem: 566 if elem.tag == 'myProxyProp': 567 self.__myPx.readProperties(propElem=elem) 568 569 elif elem.tag == 'credReposProp': 570 self.__credRepos.readProperties(propElem=elem, 563 raise SessionMgrError, \ 564 "Parsing properties file \"%s\": root element is not defined" % \ 565 propFilePath 566 567 568 missingKeys = [] 569 try: 570 for elem in propElem: 571 if elem.tag == 'myProxyProp': 572 self.__myPx.readProperties(propElem=elem) 573 574 elif elem.tag == 'credReposProp': 575 self.__credRepos.readProperties(propElem=elem, 571 576 dbPPhrase=credReposPPhrase) 572 elif elem.tag in self.__validKeys: 573 try: 577 elif elem.tag in self.__validKeys: 574 578 # Check for environment variables in file paths 575 tagCaps = elem.tag.upper() 576 if 'FILE' in tagCaps or \ 577 'PATH' in tagCaps or \ 578 'DIR' in tagCaps: 579 elem.text = os.path.expandvars(elem.text) 580 581 self.__prop[elem.tag] = elem.text 579 self.__prop[elem.tag] = os.path.expandvars(elem.text) 582 580 583 581 # Strip white space but not in the case of pass-phrase 584 # field as pass-phrase might contain leading or trailing585 # white space582 # field as pass-phrase might contain leading or 583 # trailing white space 586 584 if elem.tag != 'keyPPhrase' and \ 587 585 isinstance(self.__prop[elem.tag], basestring): 588 self.__prop[elem.tag].strip() 589 590 except Exception, e: 591 raise SessionMgrError(\ 592 "Error parsing properties file tag: \"%s\": %s" % \ 593 (elem.tag, e)) 594 595 else: 596 raise SessionMgrError(\ 597 "\"%s\" is not a valid properties file tag" % elem.tag) 586 self.__prop[elem.tag].strip() 587 else: 588 missingKeys.append(elem.tag) 589 590 except Exception, e: 591 raise SessionMgrError, \ 592 "Error parsing tag \"%s\" in properties file \"%s\": %s" % \ 593 (elem.tag, propFilePath, e) 594 595 596 if missingKeys != []: 597 raise SessionMgrError, "The following properties are " + \ 598 "missing from the properties file: " + \ 599 ', '.join(missingKeys) 598 600 599 601
Note: See TracChangeset
for help on using the changeset viewer.