Changeset 546
- Timestamp:
- 10/02/06 17:39:36 (15 years ago)
- Location:
- security/trunk/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
security/trunk/python/NDG/Session.py
r543 r546 347 347 dbPPhrase=credReposPPhrase) 348 348 elif elem.tag in self.__validKeys: 349 self.__prop[elem.tag] = elem.text350 351 349 # Check for environment variables in file paths 352 350 tagCaps = elem.tag.upper() 353 351 if 'FILE' in tagCaps or 'PATH' in tagCaps or 'DIR' in tagCaps: 354 352 elem.text = os.path.expandvars(elem.text) 353 354 self.__prop[elem.tag] = elem.text 355 355 else: 356 356 raise SessionMgrError(\ -
security/trunk/python/NDG/SessionClient.py
r541 r546 50 50 give extra WS debug information""" 51 51 52 53 self.__setSMwsdl(smWSDL) 54 self.__setSMencrPubKeyFilePath(smEncrPubKeyFilePath) 52 if smWSDL: 53 self.__setSMwsdl(smWSDL) 54 55 if smEncrPubKeyFilePath: 56 self.__setSMencrPubKeyFilePath(smEncrPubKeyFilePath) 57 55 58 self.__traceFile = traceFile 56 59 60 57 61 # Instantiate Session Manager WS proxy 58 62 if self.__smWSDL: … … 74 78 def __setSMencrPubKeyFilePath(self, smEncrPubKeyFilePath): 75 79 76 if not isinstance(sm WSDL, basestring):80 if not isinstance(smEncrPubKeyFilePath, basestring): 77 81 raise SessionClientError(\ 78 82 "Session Manager public key file path must be a valid string") … … 210 214 extAttCertList=None, 211 215 extTrustedHostList=None, 212 encrCert=None): 216 encrCert=None, 217 smEncrPubKeyFilePath=None): 213 218 """Request authorisation from NDG Session Manager Web Service. 214 219 … … 246 251 # Instantiate WS proxy 247 252 self.serviceProxy(smWSDL) 253 254 if smEncrPubKeyFilePath: 255 self.__setSMencrPubKeyFilePath(smEncrPubKeyFilePath) 248 256 249 257 … … 251 259 try: 252 260 authReq=AuthorisationReq(aaWSDL=aaWSDL, 253 254 255 256 257 258 259 260 encrPubKeyFilePath=smEncrPubKeyFilePath)261 sessID=sessID, 262 encrSessMgrWSDLuri=encrSessMgrWSDLuri, 263 reqRole=reqRole, 264 mapFromTrustedHosts=mapFromTrustedHosts, 265 extAttCertList=extAttCertList, 266 extTrustedHostList=extTrustedHostList, 267 encrCert=encrCert, 268 encrPubKeyFilePath=self.__smEncrPubKeyFilePath) 261 269 262 270 resp = self.__smSrv.reqAuthorisation(authorisationReq=authReq()) -
security/trunk/python/Tests/security.py
r500 r546 22 22 from ZSI import ServiceProxy 23 23 24 try: 25 from NDG.AttCert import * 26 27 except ImportError, e: 28 # Temporary Hack - try getting from development area instead 29 sys.path.append('/home/users/pjkersha/Development/security/python') 30 from NDG.AttCert import * 24 from NDG.AttCert import * 25 from NDG.SessionClient import * 31 26 32 27 … … 51 46 userName=None, 52 47 passPhrase=None, 48 smEncrPubKeyFilePath=None, 53 49 org=None): 54 50 """Omit username, passphrase and org if running from CGI""" … … 58 54 self.__userName = userName 59 55 self.__passPhrase = passPhrase 56 self.__smEncrPubKeyFilePath = smEncrPubKeyFilePath 57 60 58 61 59 # Authenticating organisation … … 229 227 <option>BODC</option> 230 228 <option>PML</option> 231 <option> SOC</option>229 <option>NOCS</option> 232 230 </td></tr> 233 231 <tr> … … 290 288 # Instantiate WS proxy and request connection 291 289 try: 292 smSrv = ServiceProxy(self.__smWSDL, 293 use_wsdl=True, 294 tracefile=traceFile) 295 296 resp = smSrv.addUser(userName=self.__userName, 297 passPhrase=self.__passPhrase) 298 except socket.error, e: 290 smClient = SessionClient( 291 smWSDL=self.__smWSDL, 292 smEncrPubKeyFilePath=self.__smEncrPubKeyFilePath, 293 traceFile=traceFile) 294 295 296 resp = smClient.addUser(userName=self.__userName, 297 pPhrase=self.__passPhrase) 298 except Exception, e: 299 299 # Socket error returns tuple - reformat to just give msg 300 raise SecurityCGIError( str(e[1]))300 raise SecurityCGIError("Session Client: " + str(e)) 301 301 302 302 if resp['errMsg']: … … 359 359 # Instantiate WS proxy and request connection 360 360 try: 361 sm Srv = ServiceProxy(self.__smWSDL,362 use_wsdl=True,363 tracefile=traceFile)364 365 resp = smSrv.connect(userName=self.__userName, 366 passPhrase=self.__passPhrase,367 rtnAsCookie=True)368 except socket.error, e:361 smClient = SessionClient( 362 smWSDL=self.__smWSDL, 363 smEncrPubKeyFilePath=self.__smEncrPubKeyFilePath, 364 traceFile=traceFile) 365 366 sessCookie = smClient.connect(userName=self.__userName, 367 pPhrase=self.__passPhrase) 368 except Exception, e: 369 369 # Socket error returns tuple - reformat to just give msg 370 raise SecurityCGIError(str(e[1])) 371 372 if resp['errMsg']: 373 raise SecurityCGIError(str(resp['errMsg'])) 374 375 cookie = str(resp['cookie']) 376 377 if setCookie: 378 379 print \ 370 raise SecurityCGIError("Session client: " + str(e)) 371 372 print \ 380 373 """Content-type: text/html 381 374 %s … … 391 384 <p>User %s authenticated</p> 392 385 <p>Cookie is: %s</p> 393 </body>""" % (cookie, self.__userName, cookie) 394 395 return cookie 386 </body>""" % (sessCookie, self.__userName, sessCookie) 387 return sessCookie 396 388 397 389 except Exception, e: … … 449 441 bSetCookie = False 450 442 443 451 444 try: 452 445 # Check for session ID input … … 454 447 bSetCookie = True 455 448 456 # Get session ID from cookie 457 sessID = SimpleCookie(cookie)['Hash'].value 458 449 elif 'HTTP_COOKIE' not in os.environ: 450 # Check for session ID set in existing cookie 451 452 # Re-display login screen 453 print "Content-type: text/html" + os.linesep 454 self.showLogin(bAuthorise=True, 455 bodyTag=True, 456 heading="NDG User Authorisation (Test)") 457 458 return 459 459 else: 460 # Check for session ID set in existing cookie 461 if 'HTTP_COOKIE' not in os.environ: 462 463 # Re-display login screen 464 print "Content-type: text/html" + os.linesep 465 self.showLogin(bAuthorise=True, 466 bodyTag=True, 467 heading="NDG User Authorisation (Test)") 468 469 return 470 471 # Get session ID from existing cookie 472 sessID = SimpleCookie(os.environ['HTTP_COOKIE'])['Hash'].value 460 cookie = os.environ['HTTP_COOKIE'] 461 462 463 # Get session ID from existing cookie 464 cookieObj = SimpleCookie(cookie) 465 if "NDG-ID1" not in cookieObj: 466 raise SecurityCGIError(\ 467 'Expecting "NDG-ID1" ID for session cookie') 468 469 if "NDG-ID2" not in cookieObj: 470 raise SecurityCGIError(\ 471 'Expecting "NDG-ID2" ID for session cookie') 473 472 474 473 … … 481 480 # Instantiate WS proxy and request authorisation 482 481 try: 483 smSrv = ServiceProxy(self.__smWSDL, 484 use_wsdl=True, 485 tracefile=traceFile) 486 487 resp = smSrv.reqAuthorisation(aaWSDL=self.__aaWSDL, 488 sessID=sessID, 482 smClient = SessionClient( 483 smWSDL=self.__smWSDL, 484 smEncrPubKeyFilePath=self.__smEncrPubKeyFilePath, 485 traceFile=traceFile) 486 487 resp = smClient.reqAuthorisation(cookieObj["NDG-ID1"].value, 488 cookieObj["NDG-ID2"].value, 489 aaWSDL=self.__aaWSDL, 489 490 reqRole=reqRole, 490 491 mapFromTrustedHosts=bMapFromTrustedHosts, 491 extAttCertList='',492 492 extTrustedHostList=extTrustedHostList) 493 except socket.error, e:493 except Exception, e: 494 494 # Socket error returns tuple - reformat to just give msg 495 raise SecurityCGIError( str(e[1]))495 raise SecurityCGIError("Session client: " + str(e)) 496 496 497 497 if resp['statCode'] == 'AccessGranted': … … 503 503 if not resp['extAttCertList']: 504 504 raise SecurityCGIError(str(resp['errMsg'])) 505 506 # Convert from unicode507 extAttCertList = [str(attCert) \508 for attCert in resp['extAttCertList']]509 505 510 506 elif resp['statCode'] == 'AccessError': … … 538 534 re.sub("<", "<", re.sub(">", ">", self.__attCert)) 539 535 540 elif extAttCertList:536 elif 'extAttCertList' in resp: 541 537 # Display available certificates from other AAs in a table 542 self.showExtAttCertSelect( extAttCertList)538 self.showExtAttCertSelect(resp['extAttCertList']) 543 539 544 540 print "</body>" … … 703 699 if __name__ == "__main__": 704 700 701 smWSDL = "http://glue.badc.rl.ac.uk/sessionMgr.wsdl" 702 aaWSDL = "http://glue.badc.rl.ac.uk/attAuthority.wsdl" 703 smPubKey = os.path.expandvars("/usr/local/NDG/conf/certs/badc-sm-cert.pem") 704 705 705 # Instantiate and call CGI 706 security = SecurityCGI("http://glue.badc.rl.ac.uk/sessionMgr.wsdl", 707 #"../html/sessionMgr.wsdl", 708 "http://glue.badc.rl.ac.uk/attAuthority.wsdl") 709 #"../html/attAuthority.wsdl") 706 security = SecurityCGI(smWSDL, aaWSDL, smEncrPubKeyFilePath=smPubKey) 710 707 security.cgi()
Note: See TracChangeset
for help on using the changeset viewer.