Changeset 1018 for TI12-security
- Timestamp:
- 25/05/06 16:14:18 (14 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/NDG/AttAuthority.py
r964 r1018 607 607 608 608 # Add signatureFile and list of roles 609 # 610 # (Currently Optional) additional tag allows query of the URI 611 # where a user would normally login at the trusted host. Added 612 # this feature to allow users to be forwarded to their home site 613 # if they are accessing a secure resource and are not 614 # authenticated 615 # 616 # P J Kershaw 25/05/06 609 617 self.__mapConfig[trustedHost] = \ 610 618 { 611 'wsdl': elem.findtext('wsdl'), 612 'role': [dict(i.items()) for i in roleElem] 619 'loginURI': elem.findtext('loginURI'), 620 'wsdl': elem.findtext('wsdl'), 621 'role': [dict(i.items()) for i in roleElem] 613 622 } 614 623 … … 636 645 # map look-ups 637 646 try: 638 self.__remoteRole2LocalRole[trustedHost][remoteRole]. append(\639 647 self.__remoteRole2LocalRole[trustedHost][remoteRole].\ 648 append(localRole) 640 649 except KeyError: 641 650 self.__remoteRole2LocalRole[trustedHost][remoteRole] = \ … … 685 694 their possible roles 686 695 687 Returns Noneif role isn't recognised"""696 Returns emoty dictionary if role isn't recognised""" 688 697 689 698 if not self.__localRole2RemoteRole: … … 704 713 k, \ 705 714 { 706 'wsdl': v['wsdl'], \707 ' role':\708 {}.fromkeys(\715 'wsdl': v['wsdl'], \ 716 'loginURI': v['loginURI'], \ 717 'role': {}.fromkeys(\ 709 718 [\ 710 719 role['remote'] for role in v['role'] … … 720 729 trustedHosts = self.__localRole2TrustedHost[role] 721 730 except: 722 return None731 return {} 723 732 724 733 … … 730 739 host, \ 731 740 { 732 'wsdl': self.__mapConfig[host]['wsdl'], 733 'role': self.__localRole2RemoteRole[host][role] 741 'wsdl': self.__mapConfig[host]['wsdl'], 742 'loginURI': self.__mapConfig[host]['loginURI'], 743 'role': self.__localRole2RemoteRole[host][role] 734 744 }\ 735 745 ) for host in trustedHosts -
TI12-security/trunk/python/NDG/AttAuthorityIO.py
r930 r1018 299 299 # Allow user credentials to be access like dictionary keys 300 300 super(self.__class__, self).__init__(**xmlMsgKeys) 301 302 301 303 #_________________________________________________________________________ 302 304 def updateXML(self, **xmlTags): … … 320 322 xmlTxt += os.linesep 321 323 xmlTxt += " <wsdl>%s</wsdl>" % hostInfo['wsdl'] 324 xmlTxt += " <loginURI>%s</loginURI>" % \ 325 hostInfo['loginURI'] 322 326 xmlTxt += os.linesep 323 327 xmlTxt += " <roleSet>" + os.linesep … … 352 356 trustedHostsElem = rootElem.find('trustedHosts') 353 357 if not trustedHostsElem: 354 raise TrustedHostInfoRespError(\355 "\"trustedHosts\" tag not found in trusted host info response")358 # No trusted hosts were found 359 return 356 360 357 361 for trusted in trustedHostsElem: … … 362 366 self['trustedHosts'][host] = {} 363 367 364 # Add WSDL URI and role set for that host368 # Add WSDL URI, loginURI and role set for that host 365 369 self['trustedHosts'][host]['wsdl'] = \ 366 370 trusted.find('wsdl').text.strip() 371 372 self['trustedHosts'][host]['loginURI'] = \ 373 trusted.find('loginURI').text.strip() 367 374 368 375 self['trustedHosts'][host]['role'] = \ -
TI12-security/trunk/python/NDG/SecurityCGI.py
r1007 r1018 43 43 def __init__(self, 44 44 smWSDL, 45 userName=None, 46 passPhrase=None, 45 aaWSDL, 47 46 smPubKeyFilePath=None, 47 aaPubKeyFilePath=None, 48 48 clntPubKeyFilePath=None, 49 49 clntPriKeyFilePath=None, 50 50 clntPriKeyPwd=None, 51 aaPubKey=None, 51 userName=None, 52 passPhrase=None, 52 53 scriptName=None, 53 54 returnURI=None, 54 trustedHost s=None,55 trustedHostInfo=None, 55 56 wsDebug=False, 56 57 **cgiFieldStorageKwArgs): … … 64 65 to the user's home site to obtain their 65 66 credentials 66 trustedHost s:dictionary of URIs for trusted hosts indexed by67 trustedHostInfo: dictionary of URIs for trusted hosts indexed by 67 68 hostname 68 69 wsDebug: print output from WS transactions to stderr""" 69 70 70 71 self.smWSDL = smWSDL 72 self.aaWSDL = aaWSDL 73 71 74 self.userName = userName 72 75 self.passPhrase = passPhrase 76 73 77 self.smPubKeyFilePath = smPubKeyFilePath 78 self.aaPubKeyFilePath = aaPubKeyFilePath 79 74 80 self.clntPubKeyFilePath = clntPubKeyFilePath 75 81 self.clntPriKeyFilePath = clntPriKeyFilePath 76 82 self.clntPriKeyPwd = clntPriKeyPwd 77 self.__aaPubKey = aaPubKey78 83 79 84 if scriptName: … … 83 88 84 89 self.returnURI = returnURI 85 self.trustedHost s = trustedHosts90 self.trustedHostInfo = trustedHostInfo 86 91 self.__wsDebug = False 87 92 self.__authorisationMethod = None … … 320 325 # Instantiate WS proxy and request connection 321 326 try: 322 smClient = SessionClient( 323 smWSDL=self.smWSDL, 324 smPubKeyFilePath=self.smPubKeyFilePath, 325 clntPubKeyFilePath=self.clntPubKeyFilePath, 326 clntPriKeyFilePath=self.clntPriKeyFilePath, 327 traceFile=traceFile) 328 329 return smClient.connect(userName=self.userName, 330 pPhrase=self.passPhrase, 331 clntPriKeyPwd=self.clntPriKeyPwd) 327 smClnt = SessionClient(smWSDL=self.smWSDL, 328 smPubKeyFilePath=self.smPubKeyFilePath, 329 clntPubKeyFilePath=self.clntPubKeyFilePath, 330 clntPriKeyFilePath=self.clntPriKeyFilePath, 331 traceFile=traceFile) 332 333 return smClnt.connect(userName=self.userName, 334 pPhrase=self.passPhrase, 335 clntPriKeyPwd=self.clntPriKeyPwd) 332 336 except Exception, e: 333 337 raise SecurityCGIError("Session client: " + str(e)) … … 492 496 493 497 498 #_________________________________________________________________________ 494 499 def showHomeSiteSelect(self, 495 trustedHost s=None,500 trustedHostInfo=None, 496 501 scriptName=None, 497 502 contentTypeHdr=False, … … 502 507 pageTitle=""): 503 508 504 if trustedHosts: 505 self.trustedHosts = trustedHosts 506 509 if trustedHostInfo: 510 self.trustedHostInfo = trustedHostInfo 511 512 if not self.trustedHostInfo: 513 self.getTrustedHostInfo() 514 507 515 if scriptName: 508 516 self.scriptName = scriptName … … 552 560 <option value="">Select your home site...""" % self.scriptName 553 561 554 for hostname, uri in trustedHosts.items():555 print "<option value=\"%s\">%s" % ( uri, hostname)562 for hostname, info in self.trustedHostInfo.items(): 563 print "<option value=\"%s\">%s" % (info['loginURI'], hostname) 556 564 557 565 print \ … … 573 581 574 582 # end of showHomeSiteSelect() 575 576 577 if __name__ == "__main__": 578 clntPubKeyFilePath = "../certs/GabrielCGI-cert.pem" 579 clntPriKeyFilePath = "../certs/GabrielCGI-key.pem" 580 581 securityCGI = SecurityCGI("http://gabriel.bnsc.rl.ac.uk/sessionMgr.wsdl", 582 smPubKeyFilePath="/usr/local/NDG/conf/certs/gabriel-sm-cert.pem, 583 clntPubKeyFilePath=clntPubKeyFilePath, 584 clntPriKeyFilePath=clntPriKeyFilePath, 585 returnURI="https://gabriel.bnsc.rl.ac.uk/cgi-bin/security.py", 586 trustedHosts=None) 587 securityCGI() 583 584 585 #_________________________________________________________________________ 586 def getTrustedHostInfo(self): 587 """Call Attribute Authority to find out trusted hosts. These can be 588 use to populate list for use to select home site for login""" 589 590 if self.__wsDebug: 591 traceFile = sys.stderr 592 else: 593 traceFile = None 594 595 try: 596 aaClnt = AttAuthorityClient(aaWSDL=self.aaWSDL, 597 aaPubKeyFilePath=self.aaPubKeyFilePath, 598 clntPubKeyFilePath=self.clntPubKeyFilePath, 599 clntPriKeyFilePath=self.clntPriKeyFilePath, 600 traceFile=traceFile) 601 602 self.trustedHostInfo = aaClnt.getTrustedHostInfo( 603 clntPriKeyPwd=self.clntPriKeyPwd) 604 except Exception, e: 605 raise SecurityCGIError("Attribute Authority client: " + str(e)) -
TI12-security/trunk/python/Tests/SecurityClientTest.py
r968 r1018 28 28 try: 29 29 # Session Manager WSDL 30 smWSDL = 'http://g lue.badc.rl.ac.uk/sessionMgr.wsdl'30 smWSDL = 'http://gabriel.bnsc.rl.ac.uk/sessionMgr.wsdl' 31 31 32 32 # Public key of session manager used to encrypt requests … … 50 50 51 51 # Attribute Authority client tests 52 aaWSDL = 'http://g lue.badc.rl.ac.uk/attAuthority.wsdl'52 aaWSDL = 'http://gabriel.bnsc.rl.ac.uk/attAuthority.wsdl' 53 53 aaPubKeyFilePath = None 54 54 … … 68 68 def testAddUser(self): 69 69 70 userName = ' pjkersha'70 userName = 'gabriel' 71 71 72 72 try: … … 101 101 def proxyCertConnectTest(self): 102 102 103 userName = ' lawrence'103 userName = 'gabriel' 104 104 105 105 try: … … 179 179 """Call Attribute Authority GetTrustedHostInfo""" 180 180 181 role = 'rapid' 181 import pdb 182 pdb.set_trace() 183 role = 'staff' 182 184 try: 183 185 trustedHosts = self.aaClnt.getTrustedHostInfo( -
TI12-security/trunk/python/Tests/security.py
r1007 r1018 17 17 class TestSecurityCGI(SecurityCGI): 18 18 """CGI interface test class for NDG Security""" 19 19 20 #_________________________________________________________________________ 20 def showLogin(self, 21 returnURI=None, 22 **junk): 21 def showLogin(self, returnURI=None, **kwargs): 23 22 """Display initial NDG login form""" 24 23 … … 159 158 160 159 161 def showHomeSiteSelect(self, trustedHosts=None):162 163 if trustedHosts:164 self. trustedHosts = trustedHosts160 def showHomeSiteSelect(self, **kwargs): 161 162 if not self.trustedHostInfo: 163 self.getTrustedHostInfo() 165 164 166 165 print """Content-type: text/html … … 194 193 <option value="">Select your home site...""" % self.scriptName 195 194 196 for hostname, uri in trustedHosts.items():195 for hostname, uri in self.trustedHostInfo.items(): 197 196 print "<option value=\"%s\">%s" % (uri, hostname) 198 197 … … 211 210 # end of showHomeSiteSelect() 212 211 212 213 213 214 if __name__ == "__main__": 214 securityCGI = TestSecurityCGI() 215 216 smWSDL = "http://gabriel.bnsc.rl.ac.uk/sessionMgr.wsdl" 217 aaWSDL = 'http://gabriel.bnsc.rl.ac.uk/attAuthority.wsdl' 218 219 smPubKeyFilePath = "/usr/local/NDG/conf/certs/gabriel-sm-cert.pem" 220 aaPubKeyFilePath = "/usr/local/NDG/conf/certs/gabriel-aa-cert.pem" 221 222 clntPubKeyFilePath = "../certs/GabrielCGI-cert.pem" 223 clntPriKeyFilePath = "../certs/GabrielCGI-key.pem" 224 225 returnURI = "https://gabriel.bnsc.rl.ac.uk/cgi-bin/security.py" 226 227 securityCGI = SecurityCGI(smWSDL, 228 aaWSDL, 229 smPubKeyFilePath=smPubKeyFilePath, 230 aaPubKeyFilePath=aaPubKeyFilePath, 231 clntPubKeyFilePath=clntPubKeyFilePath, 232 clntPriKeyFilePath=clntPriKeyFilePath, 233 returnURI=returnURI) 215 234 securityCGI() -
TI12-security/trunk/python/conf/mapConfig.xml
r739 r1018 2 2 <AAmap> 3 3 <trusted name="BODC"> 4 <wsdl>bodcAttAuthorityURI</wsdl> 5 <role remote="aBODCrole" local="aLocalRole"/> 4 <wsdl>bodcAttAuthorityURI</wsdl> 5 <loginURI>bodcLoginPageURI</loginURI> 6 <role remote="aBODCrole" local="aLocalRole"/> 6 7 </trusted> 7 8 <trusted name="escience"> 8 9 <role remote="anEScienceRole" local="anotherLocalRole"/>9 <wsdl>eScienceAttAuthorityURI</wsdl> 10 <role remote="anEScienceRole" local="anotherLocalRole"/> 10 11 </trusted> 11 12 </AAmap>
Note: See TracChangeset
for help on using the changeset viewer.