Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make nonce optional and soms auto formatting #66

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions examples/username-sign.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,39 @@
class MySoap extends SoapClient
{

private $_username;
private $_password;
private $_digest;

public function addUserToken($username, $password, $digest = false)
/** @var string $username */
private $username;

/** @var null|string $password */
private $password;

/** @var bool $digest */
private $digest;

/** @var bool $addNonce */
private $addNonce;

/** @var bool $addCreated */
private $addCreated;

/**
* addUserToken
*
* @param string $username
* @param null|string $password
* @param bool $digest
* @param bool $addNonce
* @param bool $addCreated
*
* @return void
*/
public function addUserToken($username, $password = null, $digest = false, $addNonce = true, $addCreated = true)
{
$this->_username = $username;
$this->_password = $password;
$this->_digest = $digest;
$this->username = $username;
$this->password = $password;
$this->digest = $digest;
$this->addNonce = $addNonce;
$this->addCreated = $addCreated;
}

public function __doRequest($request, $location, $saction, $version, $one_way = 0)
Expand All @@ -32,7 +56,7 @@ public function __doRequest($request, $location, $saction, $version, $one_way =
$objWSSE->signAllHeaders = true;

$objWSSE->addTimestamp();
$objWSSE->addUserToken($this->_username, $this->_password, $this->_digest);
$objWSSE->addUserToken($this->username, $this->password, $this->digest, $this->addNonce, $this->addCreated);

/* create new XMLSec Key using RSA SHA-1 and type is private key */
$objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'private'));
Expand Down
20 changes: 10 additions & 10 deletions src/WSASoap.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function locateHeader()
$headers = $this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header');
$header = $headers->item(0);
if (!$header) {
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX.':Header');
$header = $this->soapDoc->createElementNS($this->soapNS, $this->soapPFX . ':Header');
$this->envelope->insertBefore($header, $this->envelope->firstChild);
}
$this->header = $header;
Expand All @@ -87,7 +87,7 @@ public function __construct($doc, $ns = self::WSANS)
$this->SOAPXPath->registerNamespace('wssoap', $this->soapNS);
$this->SOAPXPath->registerNamespace('wswsa', $this->ns);

$this->envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:'.self::WSAPFX, $this->ns);
$this->envelope->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . self::WSAPFX, $this->ns);
$this->locateHeader();
}

Expand All @@ -96,7 +96,7 @@ public function addAction($action)
/* Add the WSA Action */
$header = $this->locateHeader();

$nodeAction = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':Action', $action);
$nodeAction = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':Action', $action);
$header->appendChild($nodeAction);
}

Expand All @@ -105,22 +105,22 @@ public function addFrom($location = null)
/* Add the WSA From */
$header = $this->locateHeader();

$nodeFrom = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':From');
$nodeFrom = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':From');
$header->appendChild($nodeFrom);

if (empty($location)) {
$location = 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous';
}
$nodeAddress = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':Address', $location);
$nodeAddress = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':Address', $location);
$nodeFrom->appendChild($nodeAddress);
}

public function addTo($location)
{
/* Add the WSA To */
$header = $this->locateHeader();

$nodeTo = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':To', $location);
$nodeTo = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':To', $location);
$header->appendChild($nodeTo);
}

Expand All @@ -137,7 +137,7 @@ public function addMessageID($id = null)

$header = $this->locateHeader();

$nodeID = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':MessageID', $id);
$nodeID = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':MessageID', $id);
$header->appendChild($nodeID);
$this->messageID = $id;
}
Expand All @@ -151,13 +151,13 @@ public function addReplyTo($address = null)
/* Add the WSA ReplyTo */
$header = $this->locateHeader();

$nodeReply = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':ReplyTo');
$nodeReply = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':ReplyTo');
$header->appendChild($nodeReply);

if (empty($address)) {
$address = 'http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous';
}
$nodeAddress = $this->soapDoc->createElementNS($this->ns, self::WSAPFX.':Address', $address);
$nodeAddress = $this->soapDoc->createElementNS($this->ns, self::WSAPFX . ':Address', $address);
$nodeReply->appendChild($nodeAddress);
}

Expand Down
Loading