* extra/modules/liberty.py:
- (mspProxyEndpoint) produce a common end block, remote multiple return statements, print returned body. - (do_modify_msp_for_pp) add code to query MSP and only update changed fields.
This commit is contained in:
parent
7481556f30
commit
7d5030c8d3
|
@ -512,6 +512,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
def mspProxyEndpoint(self):
|
||||
request = get_request()
|
||||
ctype = request.environ.get("CONTENT_TYPE")
|
||||
body = None
|
||||
if not ctype:
|
||||
get_logger().warn('SOAP Endpoint got message without content-type')
|
||||
return
|
||||
|
@ -555,7 +556,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
if '/ad:PersonalDocument' in query_items:
|
||||
resource, redirect_url, messageId = self.get_msp_document(identity, messageId)
|
||||
else:
|
||||
resource = self.query_msp_for_pp(service_href, identity, query_items)
|
||||
resource = self.query_msp_for_pp(service_href, identity)
|
||||
redirect_url = None
|
||||
if resource:
|
||||
service.resourceData = resource
|
||||
|
@ -571,7 +572,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
raise Exception('No Resource!!!')
|
||||
|
||||
service.buildResponseMsg()
|
||||
return service.msgBody
|
||||
body = service.msgBody
|
||||
|
||||
|
||||
if request_type == lasso.REQUEST_TYPE_DST_MODIFY:
|
||||
|
@ -594,10 +595,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
except:
|
||||
pass # XXX: build deny request
|
||||
resource = self.init_modify_msp_for_pp(service_href, modify_items)
|
||||
if resource:
|
||||
service.resourceData = resource
|
||||
else:
|
||||
return 'ERROR'
|
||||
service.resourceData = resource
|
||||
service.buildModifyResponseMsg()
|
||||
result, messageId = self.do_modify_msp_for_pp(service_href, identity, service.resourceData, messageId)
|
||||
if result and result != 'Ok':
|
||||
|
@ -611,15 +609,15 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
service.needRedirectUser(result)
|
||||
|
||||
service.buildModifyResponseMsg()
|
||||
return service.msgBody
|
||||
body = service.msgBody
|
||||
except RedirectException, redirect_exception:
|
||||
soap_fault = self.get_redirect_soap_fault(redirect_exception.redirect_url, messageId)
|
||||
body = soap_fault.exportToXml()
|
||||
return body
|
||||
except:
|
||||
except Exception, exception:
|
||||
fp = StringIO.StringIO()
|
||||
traceback.print_exc(file=fp)
|
||||
msg = fp.getvalue()
|
||||
print msg
|
||||
body = '''<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
|
||||
<Header/>
|
||||
<Body>
|
||||
|
@ -630,7 +628,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
</Fault>
|
||||
</Body>
|
||||
</Envelope>''' % xml.sax.saxutils.escape(msg)
|
||||
return body
|
||||
return body
|
||||
|
||||
msp_oids = {
|
||||
'OID.1.1.1' : { 'name': 'lbNomFamille'},
|
||||
|
@ -714,7 +712,7 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
</PP>
|
||||
'''
|
||||
|
||||
def query_msp_for_pp(self, service_type, identity, query_items):
|
||||
def query_msp_for_pp(self, service_type, identity, wsc_proxy_service = None):
|
||||
# 1st, get current user session
|
||||
sessions = [x for x in get_session_manager().values() if x.user == identity.id]
|
||||
sessions.sort(lambda x,y: cmp(x.get_creation_time(), y.get_creation_time()))
|
||||
|
@ -725,7 +723,8 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
# 2nd, query MSP
|
||||
|
||||
# Init ReadOid request
|
||||
wsc_proxy_service = self.msp_disco_query(latest_session)
|
||||
if not wsc_proxy_service:
|
||||
wsc_proxy_service = self.msp_disco_query(latest_session)
|
||||
wsc_proxy_service.initReadOidRequest(lasso.SECURITY11_MECH_TLS_SAML)
|
||||
# FIXME: set appropriate teleserviceId
|
||||
wsc_proxy_service.request.teleserviceId = '1001'
|
||||
|
@ -807,21 +806,40 @@ class AlternateLibertyDirectory(authentic.liberty.root.RootDirectory):
|
|||
|
||||
# Init UpdateOid request
|
||||
wsc_proxy_service = self.msp_disco_query(latest_session)
|
||||
wsc_proxy_service.initUpdateOidRequest(lasso.SECURITY11_MECH_TLS_SAML)
|
||||
wsc_proxy_service.request.teleserviceId = '1001'
|
||||
if service_type == adeline_urn:
|
||||
modify_oids = []
|
||||
pp = ET.XML(resource_data)
|
||||
for oid in self.msp_oids:
|
||||
name = self.msp_oids[oid]['name']
|
||||
item = pp.findall('{%s}%s' % (adeline_urn, name))
|
||||
if item:
|
||||
item = item[0]
|
||||
if item.text != dummy_value:
|
||||
text = item.text
|
||||
if text == None:
|
||||
text = ""
|
||||
wsc_proxy_service.addUpdateOidItem(oid, text.encode('utf-8'))
|
||||
try:
|
||||
# Get previous datas
|
||||
old_datas = self.query_msp_for_pp(service_type, identity)
|
||||
wsc_proxy_service.initUpdateOidRequest(lasso.SECURITY11_MECH_TLS_SAML)
|
||||
wsc_proxy_service.request.teleserviceId = '1001'
|
||||
if service_type == adeline_urn:
|
||||
modify_oids = []
|
||||
pp = ET.XML(resource_data)
|
||||
if old_datas:
|
||||
oldpp = ET.XML(old_datas)
|
||||
else:
|
||||
oldpp = None
|
||||
for oid in self.msp_oids:
|
||||
name = self.msp_oids[oid]['name']
|
||||
item = pp.findall('{%s}%s' % (adeline_urn, name))
|
||||
olditem = oldpp.findall('{%s}%s' % (adeline_urn, name))
|
||||
if item:
|
||||
item = item[0]
|
||||
if item.text != dummy_value:
|
||||
text = item.text
|
||||
if text == None:
|
||||
text = ""
|
||||
if olditem:
|
||||
olditem = olditem[0]
|
||||
if olditem is not None:
|
||||
olditem = olditem.text
|
||||
if olditem is None:
|
||||
olditem = ""
|
||||
if olditem is not None and text != olditem:
|
||||
wsc_proxy_service.addUpdateOidItem(oid, text.encode('utf-8'))
|
||||
except Exception, exception:
|
||||
print 'Got an exception in new code'
|
||||
print exception
|
||||
raise exception
|
||||
if service_type == lasso.PP_HREF:
|
||||
pass # FIXME
|
||||
# Add interaction service header
|
||||
|
|
Reference in New Issue