Skip to content

Commit 1b59b88

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 67ba2bf + a29207e commit 1b59b88

File tree

5 files changed

+107
-29
lines changed

5 files changed

+107
-29
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.2.0
4+
- Merged PR #5
5+
- Fix minor typo
6+
37
## 1.1.0
48
- Provide Docker settings
59
- Merged PR #2 and #4

composer.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"name": "Tom Vaughan",
2121
"email": "tom.vaughan@farpoint.com",
2222
"role": "Contributor"
23+
},
24+
{
25+
"name": "NtlBldrv",
26+
"role": "Contributor"
2327
}
2428
],
2529
"support" : {
@@ -31,11 +35,11 @@
3135
},
3236
"scripts": {
3337
"test": "vendor/bin/phpunit",
34-
"lint": "vendor/bin/php-cs-fixer fix"
38+
"lint": "vendor/bin/php-cs-fixer fix --ansi --diff --verbose"
3539
},
3640
"require-dev": {
37-
"phpunit/phpunit": "^4.8 || ^6.0",
38-
"friendsofphp/php-cs-fixer": "^2.0"
41+
"friendsofphp/php-cs-fixer": "^2.0",
42+
"phpunit/phpunit": "^4.8 || ^6.0"
3943
},
4044
"autoload" : {
4145
"psr-4" : {
@@ -46,6 +50,9 @@
4650
"psr-4" : {
4751
"WsdlToPhp\\WsSecurity\\Tests\\": "tests"
4852
}
53+
},
54+
"config": {
55+
"sort-packages": true
4956
}
5057
}
5158

src/Security.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ class Security extends Element
1313
* Element attribute mustunderstand name
1414
* @var string
1515
*/
16-
const ATTRIBUTE_MUST_UNDERSTAND = 'SOAP-ENV:mustunderstand';
16+
const ATTRIBUTE_MUST_UNDERSTAND = ':mustunderstand';
1717
/**
1818
* Element attribute mustunderstand name
1919
* @var string
2020
*/
21-
const ATTRIBUTE_ACTOR = 'SOAP-ENV:actor';
21+
const ATTRIBUTE_ACTOR = ':actor';
22+
/**
23+
* Envelop namespace
24+
* @var string
25+
*/
26+
const ENV_NAMESPACE = 'SOAP-ENV';
2227
/**
2328
* UsernameToken element
2429
* @var UsernameToken
@@ -29,23 +34,26 @@ class Security extends Element
2934
* @var Timestamp
3035
*/
3136
protected $timestamp;
37+
3238
/**
3339
* Constructor for Nonce element
34-
* @param bool $mustunderstand
40+
*
41+
* @param bool $mustunderstand
3542
* @param string $actor
43+
* @param string $envelopeNamespace
3644
* @param string $namespace the namespace
3745
*/
38-
public function __construct($mustunderstand = false, $actor = null, $namespace = self::NS_WSSE)
46+
public function __construct($mustunderstand = false, $actor = null, $namespace = self::NS_WSSE, $envelopeNamespace = self::ENV_NAMESPACE)
3947
{
4048
parent::__construct(self::NAME, $namespace);
4149
/**
4250
* Sets attributes
4351
*/
4452
if ($mustunderstand === true) {
45-
$this->setAttribute(self::ATTRIBUTE_MUST_UNDERSTAND, $mustunderstand);
53+
$this->setAttribute($envelopeNamespace. self::ATTRIBUTE_MUST_UNDERSTAND, $mustunderstand);
4654
}
4755
if (!empty($actor)) {
48-
$this->setAttribute(self::ATTRIBUTE_ACTOR, $actor);
56+
$this->setAttribute($envelopeNamespace . self::ATTRIBUTE_ACTOR, $actor);
4957
}
5058
}
5159
/**
@@ -83,7 +91,7 @@ public function setTimestamp(Timestamp $timestamp)
8391
/**
8492
* Overrides methods in order to set the values
8593
* @param bool $asDomElement returns elements as a DOMElement or as a string
86-
* @return string
94+
* @return string|\DOMElement
8795
*/
8896
protected function __toSend($asDomElement = false)
8997
{

src/WsSecurity.php

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,50 @@ class WsSecurity
88
* @var Security
99
*/
1010
protected $security;
11+
1112
/**
1213
* @param string $username
1314
* @param string $password
14-
* @param bool $passwordDigest
15-
* @param int $addCreated
16-
* @param int $addExpires
17-
* @param bool $mustunderstand
15+
* @param bool $passwordDigest
16+
* @param int $addCreated
17+
* @param int $addExpires
18+
* @param bool $mustunderstand
1819
* @param string $actor
1920
* @param string $usernameId
20-
* @param bool $addNonce
21+
* @param bool $addNonce
22+
* @param string $envelopeNamespace
2123
*/
22-
protected function __construct($username, $password, $passwordDigest = false, $addCreated = 0, $addExpires = 0, $mustunderstand = false, $actor = null, $usernameId = null, $addNonce = true)
23-
{
24+
protected function __construct(
25+
$username,
26+
$password,
27+
$passwordDigest = false,
28+
$addCreated = 0,
29+
$addExpires = 0,
30+
$mustunderstand = false,
31+
$actor = null,
32+
$usernameId = null,
33+
$addNonce = true,
34+
$envelopeNamespace = Security::ENV_NAMESPACE
35+
) {
2436
$this
25-
->initSecurity($mustunderstand, $actor)
37+
->initSecurity($mustunderstand, $actor, $envelopeNamespace)
2638
->setUsernameToken($username, $usernameId)
2739
->setPassword($password, $passwordDigest, $addCreated)
2840
->setNonce($addNonce)
2941
->setCreated($addCreated)
3042
->setTimestamp($addCreated, $addExpires);
3143
}
44+
3245
/**
33-
* @param bool $mustunderstand
46+
* @param bool $mustunderstand
3447
* @param string $actor
48+
* @param string $envelopeNamespace
49+
*
3550
* @return WsSecurity
3651
*/
37-
protected function initSecurity($mustunderstand = false, $actor = null)
52+
protected function initSecurity($mustunderstand = false, $actor = null, $envelopeNamespace = Security::ENV_NAMESPACE)
3853
{
39-
$this->security = new Security($mustunderstand, $actor);
54+
$this->security = new Security($mustunderstand, $actor, Security::NS_WSSE, $envelopeNamespace);
4055
return $this;
4156
}
4257
/**
@@ -46,22 +61,38 @@ public function getSecurity()
4661
{
4762
return $this->security;
4863
}
64+
4965
/**
5066
* Create the SoapHeader object to send as SoapHeader in the SOAP request.
67+
*
5168
* @param string $username
5269
* @param string $password
53-
* @param bool $passwordDigest
54-
* @param int $addCreated
55-
* @param int $addExpires
56-
* @param bool $mustunderstand
70+
* @param bool $passwordDigest
71+
* @param int $addCreated
72+
* @param int $addExpires
73+
* @param bool $returnSoapHeader
74+
* @param bool $mustunderstand
5775
* @param string $actor
5876
* @param string $usernameId
59-
* @param bool $addNonce
77+
* @param bool $addNonce
78+
* @param string $envelopeNamespace
79+
*
6080
* @return \SoapHeader|\SoapVar
6181
*/
62-
public static function createWsSecuritySoapHeader($username, $password, $passwordDigest = false, $addCreated = 0, $addExpires = 0, $returnSoapHeader = true, $mustunderstand = false, $actor = null, $usernameId = null, $addNonce = true)
63-
{
64-
$self = new WsSecurity($username, $password, $passwordDigest, $addCreated, $addExpires, $mustunderstand, $actor, $usernameId, $addNonce);
82+
public static function createWsSecuritySoapHeader(
83+
$username,
84+
$password,
85+
$passwordDigest = false,
86+
$addCreated = 0,
87+
$addExpires = 0,
88+
$returnSoapHeader = true,
89+
$mustunderstand = false,
90+
$actor = null,
91+
$usernameId = null,
92+
$addNonce = true,
93+
$envelopeNamespace = Security::ENV_NAMESPACE
94+
) {
95+
$self = new WsSecurity($username, $password, $passwordDigest, $addCreated, $addExpires, $mustunderstand, $actor, $usernameId, $addNonce, $envelopeNamespace);
6596
if ($returnSoapHeader) {
6697
if (!empty($actor)) {
6798
return new \SoapHeader(Element::NS_WSSE, 'Security', new \SoapVar($self->getSecurity()->toSend(), XSD_ANYXML), $mustunderstand, $actor);

tests/WsSecurityTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,32 @@ public function testCreateWithoutNonce()
121121
</wsse:UsernameToken>
122122
</wsse:Security>'), $header->data->enc_value);
123123
}
124+
125+
public function testCreateWithEnvelopeNamespace()
126+
{
127+
$header = WsSecurity::createWsSecuritySoapHeader(
128+
'foo',
129+
'bar',
130+
false,
131+
1459451824,
132+
0,
133+
true,
134+
true,
135+
'BAR',
136+
null,
137+
true,
138+
'env'
139+
);
140+
141+
$this->assertInstanceOf('\SoapHeader', $header);
142+
$this->assertMatches(self::innerTrim('
143+
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" env:mustunderstand="1" env:actor="BAR">
144+
<wsse:UsernameToken>
145+
<wsse:Username>foo</wsse:Username>
146+
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bar</wsse:Password>
147+
<wssu:Created xmlns:wssu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2016-03-31T19:17:04Z</wssu:Created>
148+
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">([a-zA-Z0-9=]*)</wsse:Nonce>
149+
</wsse:UsernameToken>
150+
</wsse:Security>'), $header->data->enc_value);
151+
}
124152
}

0 commit comments

Comments
 (0)