Changeset 533
- Timestamp:
- 19/01/06 18:00:16 (15 years ago)
- Location:
- security/trunk/python/NDG
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
security/trunk/python/NDG/AttAuthority.py
r531 r533 27 27 28 28 # X509 Certificate handling 29 from NDG.X509 import *29 from X509 import * 30 30 31 31 # NDG Attribute Certificate 32 from NDG.AttCert import * 33 34 32 from AttCert import * 33 34 # Format for XML messages passed over WS 35 from AttAuthorityIO import * 35 36 36 37 … … 49 50 50 51 #_____________________________________________________________________________ 51 class AttAuthorityAccessDenied( Exception):52 class AttAuthorityAccessDenied(AttAuthorityError): 52 53 """NDG Attribute Authority - access denied exception. 53 54 54 55 Raise from authorise method where no roles are available for the user 55 56 but that the request is otherwise valid. In all other error cases raise 56 AttAuthorityError""" 57 58 def __init__(self, msg): 59 self.__msg = msg 60 61 def __str__(self): 62 return self.__msg 63 57 AttAuthorityError""" 58 pass 64 59 65 60 … … 186 181 187 182 188 189 183 #_________________________________________________________________________ 190 184 def authorise(self, 191 usrProxyCertFilePath=None,192 usrProxyCertFileTxt=None,193 extAttCertFilePath=None,194 extAttCertFileTxt=None):185 reqXMLtxt=None, 186 proxyCertFilePath=None, 187 userAttCertFilePath=None, 188 **reqKeys): 195 189 196 190 """Request a new Attribute Certificate for authorisation 197 191 198 usrProxyCertFilePath|usrProxyCertFileTxt:192 proxyCertFilePath|proxyCertTxt: 199 193 200 194 user's proxy certificate use appropriate … … 202 196 text content respectively. 203 197 204 extAttCertFilePath|extAttCertFileTxt: 198 Nb. proxyCertTxt is set via reqKeys 199 200 userAttCertFilePath|userAttCertTxt: 205 201 206 202 externally provided attribute certificate … … 211 207 Pass in either the file path or a string 212 208 containing the certificate XML content. 209 210 Nb. userAttCertTxt is set via reqKeys 213 211 """ 214 212 213 if reqXMLtxt is not None: 214 # Parse XML text into keywords corresponding to the input 215 # parameters 216 if not isinstance(reqXMLtxt, basestring): 217 raise SessionMgrError(\ 218 "XML Authorisation request must be a string") 219 220 # Parse and decrypt as necessary 221 try: 222 # 1st assume that the request was encrypted 223 reqKeys = AuthorisationReq(encrXMLtxt=reqXMLtxt, 224 encrPriKeyFilePath=self.__prop['keyFile'], 225 encrPriKeyPwd=self.__prop['keyPPhrase']) 226 except Exception, e: 227 228 # Error occured decrypting - Trying parsing again, but this 229 # time assuming non-encrypted 230 try: 231 reqKeys = AuthorisationReq(xmlTxt=reqXMLtxt) 232 233 except Exception, e: 234 raise SessionMgrError(\ 235 "Error parsing authorisation request: %s" % e) 236 237 215 238 # Read proxy certificate 216 239 try: 217 240 usrProxyCert = X509Cert() 218 241 219 if usrProxyCertFilePath is not None and \220 isinstance( usrProxyCertFilePath, basestring):242 if proxyCertFilePath is not None and \ 243 isinstance(proxyCertFilePath, basestring): 221 244 222 245 # Proxy Certificate input as a file 223 usrProxyCert.read( usrProxyCertFilePath)246 usrProxyCert.read(proxyCertFilePath) 224 247 225 elif usrProxyCertFileTxt is not None and \ 226 isinstance(usrProxyCertFileTxt, basestring): 248 elif reqKeys['proxyCertTxt'] is not None: 227 249 228 250 # Proxy Certificate input as string text 229 usrProxyCert.parse( usrProxyCertFileTxt)251 usrProxyCert.parse(reqKeys['proxyCertTxt']) 230 252 231 253 else: … … 320 342 extAttCert = AttCert(certFilePathList=self.__prop['caCertFile']) 321 343 322 if extAttCertFilePathis None:323 if extAttCertFileTxt is None:344 if reqKeys['userAttCertTxt'] is None: 345 if userAttCertTxt is None: 324 346 raise AttAuthorityAccessDenied(\ 325 347 "User \"%s\" is not registered " % attCert['holder'] + \ … … 330 352 # Parse externally provided certificate 331 353 try: 332 extAttCert.parse( extAttCertFileTxt)354 extAttCert.parse(reqKeys['userAttCertTxt']) 333 355 334 356 except Exception, e: … … 338 360 # Read externally provided certificate 339 361 try: 340 extAttCert.read( extAttCertFilePath)362 extAttCert.read(userAttCertFilePath) 341 363 342 364 except Exception, e: -
security/trunk/python/NDG/CredWallet.py
r531 r533 16 16 # Temporary store of certificates for use with CredWallet reqAuthorisation() 17 17 import tempfile 18 19 # Keyword formatting/XML message creation for Attribute Authority WS 20 from AttAuthorityIO import * 18 21 19 22 # Access Attribute Authority's web service using ZSI - allow pass if not loaded … … 32 35 # no need to import it 33 36 try: 34 from NDG.AttAuthority import *37 from AttAuthority import * 35 38 aaImportError = False 36 39 except: … … 43 46 44 47 # Authentication X.509 Certificate 45 from NDG.X509 import *48 from X509 import * 46 49 47 50 # Authorisation - attribute certificate 48 from NDG.AttCert import *51 from AttCert import * 49 52 50 53 … … 187 190 except Exception, e: 188 191 raise CredWalletError( 189 "Error updating wallet with credentials from repository: %s"%\190 e)192 "Error updating wallet with credentials from repository: " + \ 193 str(e)) 191 194 192 195 … … 206 209 "Error parsing Attribute Certificate ID '" + \ 207 210 cred.id + "' retrieved from the " + \ 208 "Credentials Repository: %s" % e)211 "Credentials Repository: %s" % str(e)) 209 212 except: 210 213 raise CredWalletError("Error parsing Attribute " + \ … … 455 458 tracefile=traceFile) 456 459 460 # Format XML request message 461 authorisationReq = AuthorisationReq(\ 462 proxyCertTxt=self.__proxyCertTxt, 463 userAttCertTxt=extAttCertTxt) 464 457 465 # Call Attribute Authority's Web service 458 resp=aaSrv.reqAuthorisation(usrProxyCert=self.__proxyCertTxt, 459 usrAttCert=extAttCertTxt) 466 resp=aaSrv.reqAuthorisation(authorisationReq=authorisationReq) 460 467 461 468 except socket.error, e: … … 466 473 467 474 475 # Parse the response 476 authorisationResp = AuthorisationResp(xmlTxt=str(resp)) 468 477 # Check the status code returned from the authorisation request 469 if resp['statCode'] == 'AccessError':478 if authorisationResp['statCode'] == authorisationResp.accessError: 470 479 raise CredWalletError(str(resp['errMsg'])) 471 480 472 elif resp['statCode'] == 'AccessDenied': 481 elif authorisationResp['statCode'] == \ 482 authorisationResp.AccessDenied: 473 483 raise CredWalletAuthorisationDenied(\ 474 484 "Authorisation denied: %s" % str(resp['errMsg'])) 475 485 476 elif resp['statCode'] == 'AccessGranted': 477 attCertTxt = resp['attCert'] 486 elif authorisationResp['statCode'] == \ 487 authorisationResp.accessGranted: 488 attCertTxt = authorisationResp['attCert'] 478 489 479 490 else: … … 496 507 # Request a new attribute certificate from the Attribute 497 508 # Authority 498 attCertTxt = aa.authorise(\ 499 usrProxyCertFileTxt=self.__proxyCertTxt, 500 extAttCertFileTxt=extAttCertTxt) 509 attCertTxt = aa.authorise(proxyCertTxt=self.__proxyCertTxt, 510 userAttCertTxt=extAttCertTxt) 501 511 502 512 except AttAuthorityAccessDenied, e: -
security/trunk/python/NDG/Session.py
r531 r533 724 724 725 725 #_________________________________________________________________________ 726 def authorise(self, reqXMLtxt=None, **reqKeys):726 def reqAuthorisation(self, reqXMLtxt=None, **reqKeys): 727 727 """For given sessID, request authorisation from an Attribute Authority 728 728 given by aaWSDL. If sucessful, an attribute certificate is … … 782 782 # and return result to caller 783 783 try: 784 return smSrv. authorisation(authorisationReq=reqText)784 return smSrv.reqAuthorisation(authorisationReq=reqText) 785 785 786 786 except Exception, e: -
security/trunk/python/NDG/SessionMgrIO.py
r531 r533 24 24 import re 25 25 26 # For XML parsing 27 import cElementTree as ElementTree 28 29 from XMLSecDoc import * 26 from XMLMsg import * 30 27 31 28 # For use with AuthorisationResp class 32 29 from AttCert import * 33 34 35 #_____________________________________________________________________________36 class XMLMsgError(Exception):37 """Exception handling for NDG WS I/O Message class."""38 39 def __init__(self, msg):40 self.__msg = msg41 42 def __str__(self):43 return self.__msg44 45 46 #_____________________________________________________________________________47 class XMLMsg(dict):48 """Super class for encrypting arguments in SOAP messages for NDG Security49 Web services"""50 51 # Derived classes should specify XML tags and values as keywords and52 # values in a dictionary53 xmlTagTmpl = {}54 55 56 def __init__(self,57 encrXMLtxt=None,58 xmlTxt=None,59 encrPubKeyFilePath=None,60 encrPriKeyFilePath=None,61 encrPriKeyPwd=None,62 noEncrypt=False,63 xmlVers="1.0",64 xmlEncoding="UTF-8",65 **xmlTags):66 """XML for sending/receiving encrypted XML arguments with NDG web67 services68 69 To encrypt message to send:70 encrXML = XMLMsg(encrPubKeyFilePath=filePath,71 [xmlTxt]|[Key1=key1, Key2=key2, ...])72 73 For recipient to decrypt:74 encrXML = XMLMsg(encrPriKeyFilePath=filePath,75 encrPriKeyPwd=pwd,76 encrXMLtxt=xmlTxt)77 78 encrXMLtxt: string containing encrypted text for79 decryption80 encrPubKeyFilePath: public key to encrypt message - use when81 sending a message only82 encrPriKeyFilePath: private key used to decrypt message - use83 when receiving a message only84 encrPriKeyPwd: password for private key85 86 noEncrypt: When setting up XML to be sent in WS request,87 but no encryption is required, set this flag88 to True.89 90 (!) In this mode, this class is only of91 use in formatting **xmlTags keywords into92 XML string text __xmlTxt.93 94 xmlVers: version number in standard XML header95 xmlEncoding: encoding type set in XML header96 **xmlTags: keywords corresponding to the XML tags to be97 encrypted98 """99 100 self.__xmlTags = {}101 self.__encrXMLtxt = encrXMLtxt102 self.__xmlTxt = xmlTxt103 104 self.__xmlHdr = "<?xml version=\"%s\" encoding=\"%s\"?>" % \105 (xmlVers, xmlEncoding)106 107 # Allow user credentials to be access like dictionary keys108 dict.__init__(self)109 110 111 # Initialisation for XML Security class used for encryption112 try:113 self.__xmlSecDoc=XMLSecDoc(encrPriKeyFilePath=encrPriKeyFilePath,114 encrPubKeyFilePath=encrPubKeyFilePath)115 except Exception, e:116 raise XMLMsgError("Error initialising XML security: %s" % e)117 30 118 119 # Check mode:120 # - encrypted XML entered for decryption121 # or122 # - XML or XML tags entered as keywords to make XML document for123 # encryption124 if encrXMLtxt:125 # Encrypted text has been input for decryption126 if not encrPriKeyFilePath:127 raise XMLMsgError(\128 "A private key must be set in order to decrypt the data")129 130 try:131 self.__xmlSecDoc.decrypt(xmlTxt=encrXMLtxt,132 encrPriKeyPwd=encrPriKeyPwd)133 134 self.__xmlTxt = str(self.__xmlSecDoc)135 136 except Exception, e:137 raise XMLMsgError("Error decrypting credentials: %s" % e)138 139 # Parse elements from decrypted result saving as dictionary140 # self.__xmlTags141 self.parseXML()142 else:143 # XML text or XML tags input ready for encryption144 if xmlTxt:145 # Input XML text set - parse tags into dictionary self.__xmlTags146 self.parseXML()147 else:148 # XML text will be set from tags set as keywords149 self.updateXML(**xmlTags)150 151 if encrPubKeyFilePath:152 try:153 self.__xmlSecDoc.encrypt(xmlTxt=self.__xmlTxt)154 self.__encrXMLtxt = str(self.__xmlSecDoc)155 156 except Exception, e:157 raise XMLMsgError("Error encrypting credentials: %s" % e)158 159 elif not noEncrypt:160 raise XMLMsgError(\161 "A public key must be set in order to encrypt the data")162 163 164 def __repr__(self):165 """Print the XML for user credentials"""166 return repr(self.__xmlTags)167 168 169 def __str__(self):170 """Print the XML for user credentials"""171 return self.__xmlTxt172 173 174 def __call__(self):175 return self.__encrXMLtxt176 177 178 def __getXMLhdr(self):179 return self.__xmlHdr180 181 xmlHdr = property(fget=__getXMLhdr,182 doc="Standard header line for XML document")183 184 def __getXMLtxt(self):185 """Get the user credentials as XML formatted string"""186 return self.__xmlTxt187 188 def __setXMLtxt(self, xmlTxt):189 """Allow text to be set if class of calling method is XMLMsg190 derived"""191 192 try:193 # Get previous frame from stack194 frame = sys._getframe().f_back195 except Exception, e:196 raise AttributeError("Error checking calling method")197 198 try:199 # Check the class that the calling method belongs to200 callerClassName = frame.f_locals['self'].__class__.__name__201 202 if callerClassName == self.__class__.__name__:203 self.__xmlTxt = xmlTxt204 return205 else:206 # Raise KeyError so that execution moves to except block207 raise KeyError208 209 except KeyError:210 # self variable may not be present211 AttributeError("Caller must be a method of a %s derived class" % \212 self.__class__.__name__)213 214 215 # Read-only property216 xmlTxt = property(fget=__getXMLtxt,217 fset=__setXMLtxt,218 doc="XML string text for message")219 220 221 def __getEncrXMLtxt(self):222 """Get the user credentials as encrypted XML formatted string"""223 return self.__encrXMLtxt224 225 # Read-only property226 encrXMLtxt = property(fget=__getEncrXMLtxt,227 doc="encrypted XML user credentials")228 229 230 def __delitem__(self, key):231 "keys cannot be removed"232 raise KeyError('Keys cannot be deleted from ' + \233 self.__class__.__name__)234 235 236 def __getitem__(self, key):237 """Access user credentials as dictionary keys"""238 239 # Check input key240 if self.__xmlTags.has_key(key):241 # key recognised242 return self.__xmlTags[key]243 else:244 # key not recognised245 raise KeyError('Key "%s" not recognised for %s' % \246 (key, self.__class__.__name__))247 248 249 def __setitem__(self, key, item):250 """Allows keys to be set methods of *derived* classes only251 252 - simulates behaviour like 'protected' data members in C++"""253 254 if not key in self.__xmlTags:255 raise KeyError("Key \"%s\" invalid for %s" % \256 (key, self.__class__.__name__))257 258 try:259 # Get previous frame from stack260 frame = sys._getframe().f_back261 except Exception, e:262 raise keyError("Error checking caller")263 264 try:265 # Check the class that the calling method belongs to266 callerClassName = frame.f_locals['self'].__class__.__name__267 268 if callerClassName == self.__class__.__name__:269 self.__xmlTags[key] = item270 return271 272 except KeyError:273 # self variable may not be present274 pass275 276 raise KeyError('Keys may only be set by methods of derived classes')277 278 279 # 'in' operator280 def __contains__(self, key):281 return key in self.__xmlTags282 283 def has_key(self, key):284 return self.__xmlTags.has_key(key)285 286 def clear(self):287 raise KeyError("Data cannot be cleared from " + \288 self.__class__.__name__)289 290 def copy(self):291 import copy292 return copy.copy(self)293 294 def keys(self):295 return self.__xmlTags.keys()296 297 def items(self):298 return self.__xmlTags.items()299 300 def values(self):301 return self.__xmlTags.values()302 303 304 def update(self, xmlTagsDict=None, **xmlTags):305 """override dict.update to carry out validation306 307 Nb. unlike dict.update, an iterable can't be passed in"""308 309 if xmlTagsDict:310 if not isinstance(xmlTagsDict, dict):311 raise TypeError("Input must be dict type")312 313 # Dictionary input overrides keywords314 xmlTags = xmlTagsDict315 316 if not len(xmlTags):317 return318 319 # Check keys are valid - xmlTagTmpl MUST have been altered from the320 # default otherwise this test will always fail321 unknownKeys = [key for key in xmlTags if key not in self.xmlTagTmpl]322 if unknownKeys:323 raise KeyError(\324 "Invalid keywords set for update: \"%s\"" % \325 '", "'.join(unknownKeys))326 327 # Copy keywords - but only those that are NOT None328 self.__xmlTags.update(\329 dict([(k, v) for k, v in xmlTags.items() if v is not None]))330 331 332 def updateXML(self, **xmlTags):333 """Build XML message string from keywords corresponding to334 tags input335 336 Override in a derived class if required"""337 338 # Update dictionary339 self.update(**xmlTags)340 341 # Create XML formatted string ready for encryption342 try:343 rootNode = ElementTree.Element(self.__class__.__name__)344 rootNode.tail = os.linesep345 346 for tag in self.__xmlTags:347 # ElementTree tostring doesn't like bool types348 elem = ElementTree.SubElement(rootNode, tag)349 elem.tail = os.linesep350 351 if isinstance(self.__xmlTags[tag], bool):352 elem.text = "%d" % self.__xmlTags[tag]353 else:354 elem.text = self.__xmlTags[tag]355 356 357 self.__xmlTxt = self.__xmlHdr + os.linesep + \358 ElementTree.tostring(rootNode)359 except Exception, e:360 raise XMLMsgError("Creating XML: %s" % e)361 362 363 def parseXML(self, rtnRootElem=False):364 """Parse unencrypted XML in self.__xmlTxt365 366 Assumes single level of nesting of XML tags - override in a derived367 class if required368 369 rtnRootElem: set to True to return the root element - useful for370 derived classes to be able to access"""371 372 # Convert strings containing digits to integer type373 intCast = lambda str: int(str.isdigit()) and int(str) or str374 375 try:376 rootElem = ElementTree.XML(self.__xmlTxt)377 xmlTags = dict([(elem.tag, intCast(elem.text)) \378 for elem in rootElem])379 380 self.__xmlTags = xmlTags381 382 except Exception, e:383 raise XMLMsgError("Error parsing XML text: %s" % e)384 385 return rootElem386 387 31 388 32 #_____________________________________________________________________________ … … 750 394 raise AuthorisationRespError(\ 751 395 "Error parsing Ext. Attribute Certificate List: %s" % e) 396 752 397 753 398 #_____________________________________________________________________________ -
security/trunk/python/NDG/attAuthority_services.py
r474 r533 41 41 def getTrustedHostInfo(self, request): 42 42 """ 43 @param: request to getTrustedHostInfoRequest::44 _ usrRole: str43 @param: request to trustedHostInfoRequest:: 44 _trustedHostInfoReq: str 45 45 46 @return: response from getTrustedHostInfoResponse:: 47 _errMsg: str 48 _trustedHostInfo: Any 46 @return: response from trustedHostInfoResponse:: 47 _trustedHostInfoResp: str 49 48 """ 50 49 51 if not isinstance(request, getTrustedHostInfoRequest) and\52 not issubclass( getTrustedHostInfoRequest, request.__class__):50 if not isinstance(request, trustedHostInfoRequest) and\ 51 not issubclass(trustedHostInfoRequest, request.__class__): 53 52 raise TypeError, "%s incorrect request type" %(request.__class__) 54 53 kw = {} 55 54 response = self.binding.Send(None, None, request, soapaction="urn:attAuthority#getTrustedHostInfo", **kw) 56 response = self.binding.Receive( getTrustedHostInfoResponseWrapper())57 if not isinstance(response, getTrustedHostInfoResponse) and\58 not issubclass( getTrustedHostInfoResponse, response.__class__):55 response = self.binding.Receive(trustedHostInfoResponseWrapper()) 56 if not isinstance(response, trustedHostInfoResponse) and\ 57 not issubclass(trustedHostInfoResponse, response.__class__): 59 58 raise TypeError, "%s incorrect response type" %(response.__class__) 60 59 return response … … 63 62 def reqAuthorisation(self, request): 64 63 """ 65 @param: request to reqAuthorisationRequest:: 66 _usrAttCert: str 67 _usrProxyCert: str 64 @param: request to authorisationRequest:: 65 _authorisationReq: str 68 66 69 @return: response from reqAuthorisationResponse:: 70 _attCert: str 71 _errMsg: str 72 _statCode: str 67 @return: response from authorisationResponse:: 68 _authorisationResp: str 73 69 """ 74 70 75 if not isinstance(request, reqAuthorisationRequest) and\76 not issubclass( reqAuthorisationRequest, request.__class__):71 if not isinstance(request, authorisationRequest) and\ 72 not issubclass(authorisationRequest, request.__class__): 77 73 raise TypeError, "%s incorrect request type" %(request.__class__) 78 74 kw = {} 79 75 response = self.binding.Send(None, None, request, soapaction="urn:attAuthority#reqAuthorisation", **kw) 80 response = self.binding.Receive( reqAuthorisationResponseWrapper())81 if not isinstance(response, reqAuthorisationResponse) and\82 not issubclass( reqAuthorisationResponse, response.__class__):76 response = self.binding.Receive(authorisationResponseWrapper()) 77 if not isinstance(response, authorisationResponse) and\ 78 not issubclass(authorisationResponse, response.__class__): 83 79 raise TypeError, "%s incorrect response type" %(response.__class__) 84 80 return response … … 86 82 87 83 88 class getTrustedHostInfoRequest (ZSI.TCcompound.Struct):84 class authorisationRequest (ZSI.TCcompound.Struct): 89 85 def __init__(self, name=None, ns=None): 90 self._ usrRole= None86 self._authorisationReq = None 91 87 92 88 oname = None … … 95 91 if ns: 96 92 oname += ' xmlns="%s"' % ns 97 ZSI.TC.Struct.__init__(self, getTrustedHostInfoRequest, [ZSI.TC.String(pname="usrRole",aname="_usrRole",optional=1),], pname=name, aname="_%s" % name, oname=oname )93 ZSI.TC.Struct.__init__(self, authorisationRequest, [ZSI.TC.String(pname="authorisationReq",aname="_authorisationReq",optional=1),], pname=name, aname="_%s" % name, oname=oname ) 98 94 99 class getTrustedHostInfoRequestWrapper(getTrustedHostInfoRequest):95 class authorisationRequestWrapper(authorisationRequest): 100 96 """wrapper for rpc:encoded message""" 101 97 102 typecode = getTrustedHostInfoRequest(name='getTrustedHostInfo', ns='urn:attAuthority')98 typecode = authorisationRequest(name='reqAuthorisation', ns='urn:attAuthority') 103 99 def __init__( self, name=None, ns=None, **kw ): 104 getTrustedHostInfoRequest.__init__( self, name='getTrustedHostInfo', ns='urn:attAuthority' )100 authorisationRequest.__init__( self, name='reqAuthorisation', ns='urn:attAuthority' ) 105 101 106 class getTrustedHostInfoResponse (ZSI.TCcompound.Struct):102 class authorisationResponse (ZSI.TCcompound.Struct): 107 103 def __init__(self, name=None, ns=None): 108 self._trustedHostInfo = None 109 self._errMsg = None 104 self._authorisationResp = None 110 105 111 106 oname = None … … 114 109 if ns: 115 110 oname += ' xmlns="%s"' % ns 116 ZSI.TC.Struct.__init__(self, getTrustedHostInfoResponse, [ZSI.TC.Any(pname="trustedHostInfo",aname="_trustedHostInfo",optional=1),ZSI.TC.String(pname="errMsg",aname="_errMsg",optional=1),], pname=name, aname="_%s" % name, oname=oname )111 ZSI.TC.Struct.__init__(self, authorisationResponse, [ZSI.TC.String(pname="authorisationResp",aname="_authorisationResp",optional=1),], pname=name, aname="_%s" % name, oname=oname ) 117 112 118 class getTrustedHostInfoResponseWrapper(getTrustedHostInfoResponse):113 class authorisationResponseWrapper(authorisationResponse): 119 114 """wrapper for rpc:encoded message""" 120 115 121 typecode = getTrustedHostInfoResponse(name='getTrustedHostInfoResponse', ns='urn:attAuthority')116 typecode = authorisationResponse(name='reqAuthorisationResponse', ns='urn:attAuthority') 122 117 def __init__( self, name=None, ns=None, **kw ): 123 getTrustedHostInfoResponse.__init__( self, name='getTrustedHostInfoResponse', ns='urn:attAuthority' )118 authorisationResponse.__init__( self, name='reqAuthorisationResponse', ns='urn:attAuthority' ) 124 119 125 class reqAuthorisationRequest (ZSI.TCcompound.Struct):120 class trustedHostInfoRequest (ZSI.TCcompound.Struct): 126 121 def __init__(self, name=None, ns=None): 127 self._usrProxyCert = None 128 self._usrAttCert = None 122 self._trustedHostInfoReq = None 129 123 130 124 oname = None … … 133 127 if ns: 134 128 oname += ' xmlns="%s"' % ns 135 ZSI.TC.Struct.__init__(self, reqAuthorisationRequest, [ZSI.TC.String(pname="usrProxyCert",aname="_usrProxyCert",optional=1),ZSI.TC.String(pname="usrAttCert",aname="_usrAttCert",optional=1),], pname=name, aname="_%s" % name, oname=oname )129 ZSI.TC.Struct.__init__(self, trustedHostInfoRequest, [ZSI.TC.String(pname="trustedHostInfoReq",aname="_trustedHostInfoReq",optional=1),], pname=name, aname="_%s" % name, oname=oname ) 136 130 137 class reqAuthorisationRequestWrapper(reqAuthorisationRequest):131 class trustedHostInfoRequestWrapper(trustedHostInfoRequest): 138 132 """wrapper for rpc:encoded message""" 139 133 140 typecode = reqAuthorisationRequest(name='reqAuthorisation', ns='urn:attAuthority')134 typecode = trustedHostInfoRequest(name='getTrustedHostInfo', ns='urn:attAuthority') 141 135 def __init__( self, name=None, ns=None, **kw ): 142 reqAuthorisationRequest.__init__( self, name='reqAuthorisation', ns='urn:attAuthority' )136 trustedHostInfoRequest.__init__( self, name='getTrustedHostInfo', ns='urn:attAuthority' ) 143 137 144 class reqAuthorisationResponse (ZSI.TCcompound.Struct):138 class trustedHostInfoResponse (ZSI.TCcompound.Struct): 145 139 def __init__(self, name=None, ns=None): 146 self._attCert = None 147 self._statCode = None 148 self._errMsg = None 140 self._trustedHostInfoResp = None 149 141 150 142 oname = None … … 153 145 if ns: 154 146 oname += ' xmlns="%s"' % ns 155 ZSI.TC.Struct.__init__(self, reqAuthorisationResponse, [ZSI.TC.String(pname="attCert",aname="_attCert",optional=1),ZSI.TC.String(pname="statCode",aname="_statCode",optional=1),ZSI.TC.String(pname="errMsg",aname="_errMsg",optional=1),], pname=name, aname="_%s" % name, oname=oname )147 ZSI.TC.Struct.__init__(self, trustedHostInfoResponse, [ZSI.TC.String(pname="trustedHostInfoResp",aname="_trustedHostInfoResp",optional=1),], pname=name, aname="_%s" % name, oname=oname ) 156 148 157 class reqAuthorisationResponseWrapper(reqAuthorisationResponse):149 class trustedHostInfoResponseWrapper(trustedHostInfoResponse): 158 150 """wrapper for rpc:encoded message""" 159 151 160 typecode = reqAuthorisationResponse(name='reqAuthorisationResponse', ns='urn:attAuthority')152 typecode = trustedHostInfoResponse(name='getTrustedHostInfoResponse', ns='urn:attAuthority') 161 153 def __init__( self, name=None, ns=None, **kw ): 162 reqAuthorisationResponse.__init__( self, name='reqAuthorisationResponse', ns='urn:attAuthority' )154 trustedHostInfoResponse.__init__( self, name='getTrustedHostInfoResponse', ns='urn:attAuthority' ) -
security/trunk/python/NDG/sessionMgr_services.py
r530 r533 60 60 61 61 62 def authorisation(self, request):63 """64 @param: request to authorisationRequest::65 _authorisationReq: str66 67 @return: response from authorisationResponse::68 _authorisationResp: str69 """70 71 if not isinstance(request, authorisationRequest) and\72 not issubclass(authorisationRequest, request.__class__):73 raise TypeError, "%s incorrect request type" %(request.__class__)74 kw = {}75 response = self.binding.Send(None, None, request, soapaction="urn:sessionMgr#authorisation", **kw)76 response = self.binding.Receive(authorisationResponseWrapper())77 if not isinstance(response, authorisationResponse) and\78 not issubclass(authorisationResponse, response.__class__):79 raise TypeError, "%s incorrect response type" %(response.__class__)80 return response81 82 83 62 def connect(self, request): 84 63 """ … … 102 81 103 82 83 def reqAuthorisation(self, request): 84 """ 85 @param: request to authorisationRequest:: 86 _authorisationReq: str 87 88 @return: response from authorisationResponse:: 89 _authorisationResp: str 90 """ 91 92 if not isinstance(request, authorisationRequest) and\ 93 not issubclass(authorisationRequest, request.__class__): 94 raise TypeError, "%s incorrect request type" %(request.__class__) 95 kw = {} 96 response = self.binding.Send(None, None, request, soapaction="urn:sessionMgr#reqAuthorisation", **kw) 97 response = self.binding.Receive(authorisationResponseWrapper()) 98 if not isinstance(response, authorisationResponse) and\ 99 not issubclass(authorisationResponse, response.__class__): 100 raise TypeError, "%s incorrect response type" %(response.__class__) 101 return response 102 103 104 104 105 105 class addUserRequest (ZSI.TCcompound.Struct): … … 153 153 """wrapper for rpc:encoded message""" 154 154 155 typecode = authorisationRequest(name=' authorisation', ns='urn:sessionMgr')156 def __init__( self, name=None, ns=None, **kw ): 157 authorisationRequest.__init__( self, name=' authorisation', ns='urn:sessionMgr' )155 typecode = authorisationRequest(name='reqAuthorisation', ns='urn:sessionMgr') 156 def __init__( self, name=None, ns=None, **kw ): 157 authorisationRequest.__init__( self, name='reqAuthorisation', ns='urn:sessionMgr' ) 158 158 159 159 class authorisationResponse (ZSI.TCcompound.Struct): … … 171 171 """wrapper for rpc:encoded message""" 172 172 173 typecode = authorisationResponse(name=' authorisationResponse', ns='urn:sessionMgr')174 def __init__( self, name=None, ns=None, **kw ): 175 authorisationResponse.__init__( self, name=' authorisationResponse', ns='urn:sessionMgr' )173 typecode = authorisationResponse(name='reqAuthorisationResponse', ns='urn:sessionMgr') 174 def __init__( self, name=None, ns=None, **kw ): 175 authorisationResponse.__init__( self, name='reqAuthorisationResponse', ns='urn:sessionMgr' ) 176 176 177 177 class connectRequest (ZSI.TCcompound.Struct): -
security/trunk/python/NDG/sessionMgr_services_server.py
r531 r533 1 """NDG Session Manager Web service interface. 1 """NDG Session Manager Web service server side interface. Generated and 2 adapted from: 3 4 wsdl2dispatch -f sessionMgr.wsdl 2 5 3 6 NERC Data Grid Project … … 12 15 13 16 cvsID = '$Id$' 17 14 18 from ZSI.ServiceContainer import ServiceSOAPBinding 15 19 … … 17 21 from sessionMgr_services import * 18 22 23 from SessionMgr import * 24 19 25 # Create custom XML formatted error response where needed 20 from NDG.SessionMgrIO import *26 from SessionMgrIO import * 21 27 22 debug = True#False23 28 24 29 class sessionMgr(ServiceSOAPBinding): … … 26 31 'urn:sessionMgr#addUser': 'soap_addUser', 27 32 'urn:sessionMgr#connect': 'soap_connect', 28 'urn:sessionMgr# authorisation': 'soap_authorisation',33 'urn:sessionMgr#reqAuthorisation': 'soap_reqAuthorisation', 29 34 } 30 35 31 def __init__(self, sessionMgr, post='/sessionMgr.wsdl', **kw): 36 def __init__(self, srv, debug=False, post='/sessionMgr.wsdl', **kw): 37 32 38 ServiceSOAPBinding.__init__(self, post) 33 39 34 40 # Link WS to underlying session manager class instance 35 self.__sessionMgr = sessionMgr 41 if not isinstance(srv, SessionMgr): 42 SessionMgrError("Expecting SessionMgr type") 43 44 self.__srv = srv 45 46 self.__debug = debug 36 47 37 48 … … 40 51 """SOAP interface to NDG Session Manager WS addUser.""" 41 52 42 if debug:53 if self.__debug: 43 54 import pdb 44 55 pdb.set_trace() … … 46 57 # input vals in request object 47 58 reqArgs = ps.Parse(addUserRequestWrapper) 48 encrReqTxt = str(reqArgs._addUserReq)59 reqTxt = str(reqArgs._addUserReq) 49 60 50 61 # assign return values to response object … … 54 65 # Request a connection from the Session Manager 55 66 try: 56 resp._addUserResp = self.__s essionMgr.addUser(\57 encrAddUserReqTxt=encrReqTxt)67 resp._addUserResp = self.__srv.addUser(encrAddUserReqTxt=reqTxt) 68 58 69 except Exception, e: 59 70 resp._addUserResp = str(AddUserResp(errMsg=str(e))) … … 66 77 """SOAP interface to NDG Session Manager WS connect.""" 67 78 68 if debug:79 if self.__debug: 69 80 import pdb 70 81 pdb.set_trace() … … 72 83 # input vals in request object 73 84 reqArgs = ps.Parse(connectRequestWrapper) 74 encrReqTxt = str(reqArgs._connectReq)85 reqTxt = str(reqArgs._connectReq) 75 86 76 87 # assign return values to response object … … 80 91 # Request a connection from the Session Manager 81 92 try: 82 resp._connectResp = self.__s essionMgr.connect(\83 encrConnectReqTxt=encrReqTxt)93 resp._connectResp = self.__srv.connect(encrConnectReqTxt=reqTxt) 94 84 95 except Exception, e: 85 96 resp._connectResp = str(ConnectResp(errMsg=str(e))) … … 89 100 90 101 #_________________________________________________________________________ 91 def soap_ authorisation(self, ps):102 def soap_reqAuthorisation(self, ps): 92 103 93 if debug:104 if self.__debug: 94 105 import pdb 95 106 pdb.set_trace() … … 105 116 # Make an authorisation request via the session manager 106 117 try: 107 authResp = self.__s essionMgr.authorise(reqXMLtxt=reqTxt)118 authResp = self.__srv.reqAuthorisation(reqXMLtxt=reqTxt) 108 119 109 120 except Exception, e:
Note: See TracChangeset
for help on using the changeset viewer.