note 97273 modified in soapclient.soapclient by danbrown
| From: | danbrown@php.net | Date: | Mon, 12 Apr 2010 15:03:12 +0000 |
| Subject: | note 97273 modified in soapclient.soapclient by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168159@lists.php.net to get a copy of this message | ||
It took me longer than a week to figure out how to implement WSSE (Web Service Security) headers in
native PHP SOAP. There are no much resource available on this, so thought to add this here for
community benefit.
Step1: Create two classes to create a structure for WSSE headers
<?php
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($innerVal){
$this->UsernameToken = $innerVal;
}
}
?>
Step2: Create Soap Variables for UserName and Password
<?php
$username = 1111;
$password = 1111;
//Check with your provider which security name-space they are using.
$strWSSENS = "http://schemas.xmlsoap.org/ws/2002/07/secext";
$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
?>
Step3: Create Object for Auth Class and pass in soap var
<?php
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
?>
Step4: Create SoapVar out of object of Auth class
<?php
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
?>
Step5: Create object for Token Class
<?php
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
?>
Step6: Create SoapVar out of object of Token class
<?php
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
?>
Step7: Create SoapVar for 'Security' node
<?php
$objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'Security', $strWSSENS);
?>
Step8: Create header object out of security soapvar
<?php
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true,
'http://abce.com');
//Third parameter here makes 'mustUnderstand=1
//Forth parameter generates 'actor="http://abce.com"'
?>
Step9: Create object of Soap Client
<?php
$objClient = new SoapClient($WSDL, $arrOptions);
?>
Step10: Set headers for soapclient object
<?php
$objClient->__setSoapHeaders(array($objSoapVarWSSEHeader));
?>
Step 11: Final call to method
<?php
$objResponse = $objClient->__soapCall($strMethod, $requestPayloadString);
?>
--was--
It took me longer than a week to figure out how to implement WSSE (Web Service Security) headers in
native PHP SOAP. There are no much resource available on this, so thought to add this here for
community benefit.
Step1: Create two classes to create a structure for WSSE headers
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($innerVal){
$this->UsernameToken = $innerVal;
}
}
Step2: Create Soap Variables for UserName and Password
$username = 1111;
$password = 1111;
//Check with your provider which security name-space they are using.
$strWSSENS = "http://schemas.xmlsoap.org/ws/2002/07/secext";
$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
Step3: Create Object for Auth Class and pass in soap var
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
Step4: Create SoapVar out of object of Auth class
$objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
Step5: Create object for Token Class
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
Step6: Create SoapVar out of object of Token class
$objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'UsernameToken', $strWSSENS);
Step7: Create SoapVar for 'Security' node
$objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS,
'Security', $strWSSENS);
Step8: Create header object out of security soapvar
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true,
'http://abce.com');
//Third parameter here makes 'mustUnderstand=1
//Forth parameter generates 'actor="http://abce.com"'
Step9: Create object of Soap Client
$objClient = new SoapClient($WSDL, $arrOptions);
Step10: Set headers for soapclient object
$objClient->__setSoapHeaders(array($objSoapVarWSSEHeader));
Step 11: Final call to method
$objResponse = $objClient->__soapCall($strMethod, $requestPayloadString);
http://php.net/manual/en/soapclient.soapclient.php