Tcl
Tcl
SOAP WS-Security Username Authentication
See more XML Examples
Demonstrates creating SOAP XML for WS-Security Username Authentication. The client user name and password are encapsulated in a WS-Security <wsse:UsernameToken>.Chilkat Tcl Downloads
load ./chilkat.dll
# Generate this XML with the code that follows:
# <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
# <soap:Header>
# <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
# <wsse:UsernameToken wsu:Id="sample"
# xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
# <wsse:Username>sample</wsse:Username>
# <wsse:Password Type="wsse:PasswordText">oracle</wsse:Password>
# <wsu:Created>2004-05-19T08:44:51Z</wsu:Created>
# </wsse:UsernameToken>
# </wsse:Security>
# <wsse:Security soap:actor="oracle"
# xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext">
# <wsse:UsernameToken wsu:Id="oracle"
# xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility">
# <wsse:Username>myUsername</wsse:Username>
# <wsse:Password Type="wsse:PasswordText">myPassword</wsse:Password>
# <wsu:Created>2004-05-19T08:46:04Z</wsu:Created>
# </wsse:UsernameToken>
# </wsse:Security>
# </soap:Header>
# <soap:Body>
# <getHello xmlns="http://www.oracle.com"/>
# </soap:Body>
# </soap:Envelope>
#
# First build the outer housing:
set xml [new_CkXml]
CkXml_put_Tag $xml "soap:Envelope"
CkXml_AddAttribute $xml "xmlns:soap" "http://schemas.xmlsoap.org/soap/envelope/"
CkXml_UpdateChildContent $xml "soap:Header" ""
CkXml_UpdateAttrAt $xml "soap:Body|getHello" 1 "xmlns" "http://www.oracle.com"
# Get the current date/time in a string with this format: 2004-05-19T08:46:04Z
set dt [new_CkDateTime]
CkDateTime_SetFromCurrentSystemTime $dt
set bLocal 0
set created [CkDateTime_getAsTimestamp $dt $bLocal]
# Now build each UsernameToken block:
set wsse1 [new_CkXml]
CkXml_put_Tag $wsse1 "wsse:Security"
CkXml_AddAttribute $wsse1 "xmlns:wsse" "http://schemas.xmlsoap.org/ws/2003/06/secext"
CkXml_UpdateAttrAt $wsse1 "wsse:UsernameToken" 1 "wsu:Id" "sample"
CkXml_UpdateAttrAt $wsse1 "wsse:UsernameToken" 1 "xmlns:wsu" "http://schemas.xmlsoap.org/ws/2003/06/utility"
CkXml_UpdateChildContent $wsse1 "wsse:UsernameToken|wsse:Username" "sample"
CkXml_UpdateAttrAt $wsse1 "wsse:UsernameToken|wsse:Password" 1 "Type" "wsse:PasswordText"
CkXml_UpdateChildContent $wsse1 "wsse:UsernameToken|wsse:Password" "oracle"
CkXml_UpdateChildContent $wsse1 "wsse:UsernameToken|wsu:Created" $created
set wsse2 [new_CkXml]
CkXml_put_Tag $wsse2 "wsse:Security"
CkXml_AddAttribute $wsse2 "soap:actor" "oracle"
CkXml_AddAttribute $wsse2 "xmlns:wsse" "http://schemas.xmlsoap.org/ws/2003/06/secext"
CkXml_UpdateAttrAt $wsse2 "wsse:UsernameToken" 1 "wsu:Id" "oracle"
CkXml_UpdateAttrAt $wsse2 "wsse:UsernameToken" 1 "xmlns:wsu" "http://schemas.xmlsoap.org/ws/2003/06/utility"
CkXml_UpdateChildContent $wsse2 "wsse:UsernameToken|wsse:Username" "oracle"
CkXml_UpdateAttrAt $wsse2 "wsse:UsernameToken|wsse:Password" 1 "Type" "wsse:PasswordText"
CkXml_UpdateChildContent $wsse2 "wsse:UsernameToken|wsse:Password" "oracle"
CkXml_UpdateChildContent $wsse2 "wsse:UsernameToken|wsu:Created" $created
# Insert the UsernameToken blocks:
# xHeader is a CkXml
set xHeader [CkXml_GetChildWithTag $xml "soap:Header"]
CkXml_AddChildTree $xHeader $wsse1
CkXml_AddChildTree $xHeader $wsse2
delete_CkXml $xHeader
# Show the XML:
puts [CkXml_getXml $xml]
delete_CkXml $xml
delete_CkDateTime $dt
delete_CkXml $wsse1
delete_CkXml $wsse2