Skip to content

Commit 1fdcba3

Browse files
committed
Upgrade xml-ws libraries
1 parent e4d5ae2 commit 1fdcba3

File tree

11 files changed

+921
-612
lines changed

11 files changed

+921
-612
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
"simplesamlphp/saml11": "^2.1",
4545
"simplesamlphp/saml2": "^6.0",
4646
"simplesamlphp/simplesamlphp": "^2.5@dev",
47-
"simplesamlphp/xml-common": "^2.5",
47+
"simplesamlphp/xml-common": "^2.6",
4848
"simplesamlphp/xml-security": "^2.1",
49-
"simplesamlphp/xml-soap": "^2.1",
49+
"simplesamlphp/xml-soap": "^2.2",
5050
"simplesamlphp/xml-wsdl": "^2.1",
5151
"simplesamlphp/xml-wss-core": "^1.2",
5252
"simplesamlphp/xml-ws-addressing": "^1.1",

phpstan-baseline.neon

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#1 \$idp of class SimpleSAML\\IdP\\IFrameLogoutHandler constructor expects SimpleSAML\\IdP, \$this\(SimpleSAML\\Module\\adfs\\IdP\\PassiveIdP\) given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/IdP/PassiveIdP.php
8+
9+
-
10+
message: '#^Parameter \#1 \$idp of class SimpleSAML\\IdP\\TraditionalLogoutHandler constructor expects SimpleSAML\\IdP, \$this\(SimpleSAML\\Module\\adfs\\IdP\\PassiveIdP\) given\.$#'
11+
identifier: argument.type
12+
count: 1
13+
path: src/IdP/PassiveIdP.php

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ parameters:
22
level: 6
33
paths:
44
- src
5+
includes:
6+
- phpstan-baseline.neon

src/Controller/Adfs.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use SimpleSAML\Module\adfs\IdP\PassiveIdP;
1616
use SimpleSAML\Module\adfs\MetadataExchange;
1717
use SimpleSAML\Session;
18-
use SimpleSAML\SOAP\XML\env_200305\Envelope;
18+
use SimpleSAML\SOAP12\XML\Envelope;
1919
use SimpleSAML\Utils;
2020
use SimpleSAML\XML\DOMDocumentFactory;
2121
use Symfony\Component\HttpFoundation\Request;
@@ -53,7 +53,7 @@ class Adfs
5353
public function __construct(Configuration $config, Session $session)
5454
{
5555
$this->config = $config;
56-
$this->metadata = Metadata\MetaDataStorageHandler::getMetadataHandler($config);
56+
$this->metadata = Metadata\MetaDataStorageHandler::getMetadataHandler();
5757
$this->session = $session;
5858
$this->cryptoUtils = new Utils\Crypto();
5959
}
@@ -227,6 +227,7 @@ public function usernamemixed(Request $request): Response
227227
throw new SspError\Error('NOACCESS');
228228
}
229229

230+
/** @var string|false $soapMessage */
230231
$soapMessage = $request->getContent();
231232
if ($soapMessage === false) {
232233
throw new SspError\BadRequest('Missing SOAP-content.');

src/IdP/ADFS.php

Lines changed: 148 additions & 99 deletions
Large diffs are not rendered by default.

src/IdP/MetadataBuilder.php

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
use SimpleSAML\Configuration;
1212
use SimpleSAML\Logger;
1313
use SimpleSAML\Module;
14+
use SimpleSAML\SAML2\Constants as C_SAML2;
1415
use SimpleSAML\SAML2\Exception\ArrayValidationException;
16+
use SimpleSAML\SAML2\Type\EntityIDValue;
17+
use SimpleSAML\SAML2\Type\KeyTypesValue;
18+
use SimpleSAML\SAML2\Type\SAMLAnyURIListValue;
19+
use SimpleSAML\SAML2\Type\SAMLAnyURIValue;
20+
use SimpleSAML\SAML2\Type\SAMLStringValue;
1521
use SimpleSAML\SAML2\XML\md\AbstractMetadataDocument;
1622
use SimpleSAML\SAML2\XML\md\ContactPerson;
1723
use SimpleSAML\SAML2\XML\md\EntityDescriptor;
@@ -26,16 +32,23 @@
2632
use SimpleSAML\SAML2\XML\saml\AttributeValue;
2733
use SimpleSAML\SAML2\XML\shibmd\Scope;
2834
use SimpleSAML\Utils;
29-
use SimpleSAML\WSSecurity\Constants as C;
30-
use SimpleSAML\WSSecurity\XML\fed\PassiveRequestorEndpoint;
31-
use SimpleSAML\WSSecurity\XML\fed\SecurityTokenServiceEndpoint;
32-
use SimpleSAML\WSSecurity\XML\fed\SecurityTokenServiceType;
33-
use SimpleSAML\WSSecurity\XML\fed\TokenType;
34-
use SimpleSAML\WSSecurity\XML\fed\TokenTypesOffered;
35-
use SimpleSAML\WSSecurity\XML\wsa_200508\Address;
36-
use SimpleSAML\WSSecurity\XML\wsa_200508\EndpointReference;
35+
use SimpleSAML\WebServices\Addressing\XML\wsa_200508\Address;
36+
use SimpleSAML\WebServices\Addressing\XML\wsa_200508\EndpointReference;
37+
use SimpleSAML\WebServices\Federation\Constants as C_FED;
38+
use SimpleSAML\WebServices\Federation\XML\fed\PassiveRequestorEndpoint;
39+
use SimpleSAML\WebServices\Federation\XML\fed\SecurityTokenServiceEndpoint;
40+
use SimpleSAML\WebServices\Federation\XML\fed\SecurityTokenServiceType;
41+
use SimpleSAML\WebServices\Federation\XML\fed\TokenType;
42+
use SimpleSAML\WebServices\Federation\XML\fed\TokenTypesOffered;
43+
use SimpleSAML\WebServices\Trust\Constants as C_TRUST;
3744
use SimpleSAML\XML\Chunk;
45+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
46+
use SimpleSAML\XMLSchema\Type\BooleanValue;
47+
use SimpleSAML\XMLSchema\Type\IDValue;
48+
use SimpleSAML\XMLSchema\Type\NCNameValue;
49+
use SimpleSAML\XMLSchema\Type\QNameValue;
3850
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
51+
use SimpleSAML\XMLSecurity\Constants as C_XMLSEC;
3952
use SimpleSAML\XMLSecurity\Key\PrivateKey;
4053
use SimpleSAML\XMLSecurity\XML\ds\KeyInfo;
4154
use SimpleSAML\XMLSecurity\XML\ds\KeyName;
@@ -81,11 +94,13 @@ public function buildDocument(): EntityDescriptor
8194
$contactPerson = $this->getContactPerson();
8295
$organization = $this->getOrganization();
8396
$roleDescriptor = $this->getRoleDescriptor();
97+
$extensions = $this->getExtensions();
8498

8599
$randomUtils = new Utils\Random();
86100
$entityDescriptor = new EntityDescriptor(
87-
id: $randomUtils->generateID(),
88-
entityId: $entityId,
101+
id: IDValue::fromString($randomUtils->generateID()),
102+
extensions: $extensions,
103+
entityId: EntityIDValue::fromString($entityId),
89104
contactPerson: $contactPerson,
90105
organization: $organization,
91106
roleDescriptor: $roleDescriptor,
@@ -110,7 +125,7 @@ protected function signDocument(AbstractMetadataDocument $document): AbstractMet
110125
/** @var array<mixed> $keyArray */
111126
$keyArray = $cryptoUtils->loadPrivateKey($this->config, true, 'metadata.sign.');
112127
$certArray = $cryptoUtils->loadPublicKey($this->config, false, 'metadata.sign.');
113-
$algo = $this->config->getOptionalString('metadata.sign.algorithm', C::SIG_RSA_SHA256);
128+
$algo = $this->config->getOptionalString('metadata.sign.algorithm', C_XMLSEC::SIG_RSA_SHA256);
114129

115130
$key = PrivateKey::fromFile($keyArray['PEM'], $keyArray['password'] ?? '');
116131
$signer = (new SignatureAlgorithmFactory())->getAlgorithm($algo, $key);
@@ -124,7 +139,7 @@ protected function signDocument(AbstractMetadataDocument $document): AbstractMet
124139
]);
125140
}
126141

127-
$document->sign($signer, C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, $keyInfo);
142+
$document->sign($signer, C_XMLSEC::C14N_EXCLUSIVE_WITHOUT_COMMENTS, $keyInfo);
128143
return $document;
129144
}
130145

@@ -190,24 +205,35 @@ private function getRoleDescriptor(): array
190205
/**
191206
* This method builds the SecurityTokenService element
192207
*
193-
* @return \SimpleSAML\WSSecurity\XML\fed\SecurityTokenServiceType
208+
* @return \SimpleSAML\WebServices\Federation\XML\fed\SecurityTokenServiceType
194209
*/
195210
public function getSecurityTokenService(): SecurityTokenServiceType
196211
{
197212
$defaultEndpoint = Module::getModuleURL('adfs') . '/idp/prp.php';
198213

199214
return new SecurityTokenServiceType(
200-
protocolSupportEnumeration: [C::NS_TRUST_200512, C::NS_TRUST_200502, C::NS_FED],
215+
QNameValue::fromParts(
216+
NCNameValue::fromString(SecurityTokenServiceType::getLocalName()),
217+
AnyURIValue::fromString(SecurityTokenServiceType::NS),
218+
NCNameValue::fromString(SecurityTokenServiceType::NS_PREFIX),
219+
),
220+
protocolSupportEnumeration: SAMLAnyURIListValue::fromArray(
221+
[C_TRUST::NS_TRUST_200512, C_TRUST::NS_TRUST_200502, C_FED::NS_FED],
222+
),
201223
keyDescriptors: $this->getKeyDescriptor(),
202-
tokenTypesOffered: new TokenTypesOffered([new TokenType('urn:oasis:names:tc:SAML:1.0:assertion')]),
224+
tokenTypesOffered: new TokenTypesOffered(
225+
[
226+
new TokenType(AnyURIValue::fromString('urn:oasis:names:tc:SAML:1.0:assertion')),
227+
],
228+
),
203229
securityTokenServiceEndpoint: [
204230
new SecurityTokenServiceEndpoint([
205-
new EndpointReference(new Address($defaultEndpoint)),
231+
new EndpointReference(new Address(AnyURIValue::fromString($defaultEndpoint))),
206232
]),
207233
],
208234
passiveRequestorEndpoint: [
209235
new PassiveRequestorEndpoint([
210-
new EndpointReference(new Address($defaultEndpoint)),
236+
new EndpointReference(new Address(AnyURIValue::fromString($defaultEndpoint))),
211237
]),
212238
],
213239
);
@@ -282,8 +308,11 @@ private function getExtensions(): ?Extensions
282308

283309
if ($this->metadata->hasValue('scope')) {
284310
foreach ($this->metadata->getArray('scope') as $scopetext) {
285-
$isRegexpScope = (1 === preg_match('/[\$\^\)\(\*\|\\\\]/', $scopetext));
286-
$extensions[] = new Scope($scopetext, $isRegexpScope);
311+
$isRegexpScope = 1 === preg_match('/[\$\^\)\(\*\|\\\\]/', $scopetext);
312+
$extensions[] = new Scope(
313+
SAMLStringValue::fromString($scopetext),
314+
BooleanValue::fromBoolean($isRegexpScope),
315+
);
287316
}
288317
}
289318

@@ -298,14 +327,16 @@ private function getExtensions(): ?Extensions
298327
// Attribute names that is not URI is prefixed as this: '{nameformat}name'
299328
if (preg_match('/^\{(.*?)\}(.*)$/', $attributeName, $matches)) {
300329
$attr[] = new Attribute(
301-
name: $matches[2],
302-
nameFormat: $matches[1] === C::NAMEFORMAT_UNSPECIFIED ? null : $matches[1],
330+
name: SAMLStringValue::fromString($matches[2]),
331+
nameFormat: SAMLAnyURIValue::fromString(
332+
$matches[1] === C_SAML2::NAMEFORMAT_UNSPECIFIED ? null : $matches[1],
333+
),
303334
attributeValue: $attrValues,
304335
);
305336
} else {
306337
$attr[] = new Attribute(
307-
name: $attributeName,
308-
nameFormat: C::NAMEFORMAT_UNSPECIFIED,
338+
name: SAMLStringValue::fromString($attributeName),
339+
nameFormat: SAMLAnyURIValue::fromString(C_SAML2::NAMEFORMAT_UNSPECIFIED),
309340
attributeValue: $attrValues,
310341
);
311342
}
@@ -364,17 +395,17 @@ private static function buildKeyDescriptor(string $use, string $x509Cert, ?strin
364395
Assert::oneOf($use, ['encryption', 'signing']);
365396
$info = [
366397
new X509Data([
367-
new X509Certificate($x509Cert),
398+
X509Certificate::fromString($x509Cert),
368399
]),
369400
];
370401

371402
if ($keyName !== null) {
372-
$info[] = new KeyName($keyName);
403+
$info[] = KeyName::fromString($keyName);
373404
}
374405

375406
return new KeyDescriptor(
376407
new KeyInfo($info),
377-
$use,
408+
KeyTypesValue::fromString($use),
378409
);
379410
}
380411
}

src/IdP/PassiveIdP.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ class PassiveIdP
7878
private function __construct(Configuration $config, string $id)
7979
{
8080
$this->id = $id;
81-
8281
$this->globalConfig = $config;
83-
$metadata = MetaDataStorageHandler::getMetadataHandler($this->globalConfig);
82+
83+
$metadata = MetaDataStorageHandler::getMetadataHandler();
8484

8585
if (substr($id, 0, 5) === 'adfs:') {
8686
if (!$this->globalConfig->getOptionalBoolean('enable.adfs-idp', false)) {
@@ -200,7 +200,7 @@ public static function postAuthProc(array $state): void
200200
*
201201
* @throws \SimpleSAML\Error\Exception If we are not authenticated.
202202
*/
203-
public static function postAuth(array $state): Response
203+
public static function postAuth(array $state): void
204204
{
205205
$idp = PassiveIdP::getByState(Configuration::getInstance(), $state);
206206

@@ -234,7 +234,7 @@ public static function postAuth(array $state): Response
234234

235235
$pc->processState($state);
236236

237-
return self::postAuthProc($state);
237+
self::postAuthProc($state);
238238
}
239239

240240

@@ -245,9 +245,9 @@ public static function postAuth(array $state): Response
245245
*
246246
* @param array<mixed> &$state The authentication request state.
247247
*/
248-
private function authenticate(array &$state): Response
248+
private function authenticate(array &$state): void
249249
{
250-
return $this->authSource->login($state);
250+
$this->authSource->login($state);
251251
}
252252

253253

@@ -275,7 +275,7 @@ public function handleAuthenticationRequest(array &$state): Response
275275
$state['ReturnCallback'] = ['\SimpleSAML\Module\adfs\IdP\PassiveIdP', 'postAuth'];
276276

277277
try {
278-
return $this->authenticate($state);
278+
$this->authenticate($state);
279279
} catch (Error\Exception $e) {
280280
Auth\State::throwException($state, $e);
281281
} catch (Exception $e) {
@@ -309,7 +309,6 @@ public function getLogoutHandler(): LogoutHandlerInterface
309309
throw new Error\Exception('Unknown logout handler: ' . var_export($logouttype, true));
310310
}
311311

312-
/** @var \SimpleSAML\IdP\LogoutHandlerInterface */
313312
return new $handler($this);
314313
}
315314

0 commit comments

Comments
 (0)