Re: [SOAP] WS-Security headers in PHP::SOAP and PEAR::SOAP
| From: | Adam Maccabee Trachtenberg | Date: | Thu, 13 Apr 2006 22:35:42 +0000 |
| Subject: | Re: [SOAP] WS-Security headers in PHP::SOAP and PEAR::SOAP | ||
| References: | 1 | Groups: | php.soap |
| Request: | Send a blank email to php-soap+get-2196@lists.php.net to get a copy of this message | ||
On Thu, 13 Apr 2006, Peter De Vries wrote:
> I need to create a SOAP header that looks like this:
>
> <ns:Security>
> <ns:UsernameToken>
> <ns:Username>MYUSERNAME</ns:Username>
> <ns:Password>MYPASSWORD</ns:Password>
> </ns:UsernameToken>
> </ns:Security>
> (ns: is the Oasis WS-Security namespace,
> http://schemas.xmlsoap.org/ws/2003/06/secext.)
>
> Looks pretty straightforward, turned out to be harder than I thought...
> I tried 2 approaches: PHP::SOAP (5.0.4 on Fedora Core 4) and
> PEAR::SOAP (0.9.3)
>
> 1. PHP::SOAP
> //WSDL_URL is my WSDL file
> //WSSE_URL is http://schemas.xmlsoap.org/ws/2003/06/secext
> $kaeSoapClient_WsdlUrl = WSDL_URL;
> $kaeSoapClient_Options = array('trace' => 1, 'exceptions' => 0);
> $kaeSoapClient = new SoapClient($kaeSoapClient_WsdlUrl,
> $kaeSoapClient_Options);
>
> $kaeUsername = new SoapVar('MYUSERNAME', XSD_STRING, 'Username', WSSE_URL);
> $kaePassword = new SoapVar('MYPASSWORD', XSD_STRING, 'Password', WSSE_URL);
> $kaeHdr = new SoapVar(array('Username' => $kaeUsername,
> 'Password' => $kaePassword), SOAP_ENC_OBJECT);
>
> $kaeSoapHeader_NameSpace = WSSE_URL;
> $kaeSoapHeader_Name = "Security";
> $kaeSoapHeader_Data = $kaeHdr;
> $kaeSoapHeader_MustUnderstand = true;
> $kaeSoapHeader = new SoapHeader($kaeSoapHeader_NameSpace,
> $kaeSoapHeader_Name,
> $kaeSoapHeader_Data,
> $kaeSoapHeader_MustUnderstand);
>
> There are 2 problems here and I cannot figure out how to fix them:
> - Add the UsernameToken tags
$WSSE_NS = 'http://schemas.xmlsoap.org/ws/2003/06/secext';
class kaeUsernameToken {
public function __construct($Username, $Password) {
$this->Username = $Username;
$this->Password = $Password
}
}
$kaeUsernameToken = new kaeUsernameToken($kaeUsername, $kaePassword);
$kaeHdr = new SOAPVar($kaeUsernameToken, SOAP_ENC_OBJECT, null, null,
null, $WSSE_NS);
> - Add the correct namespace to (all) the tags
$kaeUsername = new SoapVar('MYUSERNAME', XSD_STRING,
'Username', null, null, $WSSE_NS);
Give or take. This is untested, but cribbed from similar code. You may
need to do something similar to embed the UsernameToken object to make
it named correctly.
-adam
--
adam@trachtenberg.com | http://www.trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!