Skip to content

Commit ab11e0f

Browse files
committed
WIP: Create metadata configuration classes
1 parent da4ca3b commit ab11e0f

3 files changed

Lines changed: 236 additions & 0 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\Metadata;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
9+
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
10+
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
11+
use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey};
12+
13+
/**
14+
* Class holding common configuration for SAML2 entities.
15+
*
16+
* @package simplesamlphp/saml2
17+
*/
18+
abstract class AbstractProvider
19+
{
20+
/**
21+
*/
22+
protected function __construct(
23+
protected string $entityId,
24+
protected EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null $encryptionAlgorithmFactory,
25+
protected SignatureAlgorithmFactory|null $signatureAlgorithmFactory,
26+
protected string $signatureAlgorithm,
27+
protected array $validatingKeys,
28+
protected PrivateKey|null $signingKey,
29+
protected PublicKey|SymmetricKey|null $encryptionKey,
30+
protected array $decryptionKeys,
31+
protected array $IDPList,
32+
) {
33+
Assert::validURI($entityId);
34+
Assert::validURI($signatureAlgorithm);
35+
Assert::allIsInstanceOfAny($decryptionKeys, [SymmetricKey::class, PrivateKey::class]);
36+
Assert::allIsInstanceOf($validatingKeys, PublicKey::class);
37+
Assert::allValidURI($IDPList);
38+
}
39+
40+
41+
/**
42+
* Retrieve the SignatureAlgorithmFactory used for signing and verifying messages.
43+
*/
44+
public function getSignatureAlgorithmFactory(): ?SignatureAlgorithmFactory
45+
{
46+
return $this->signatureAlgorithmFactory;
47+
}
48+
49+
50+
/**
51+
* Retrieve the EncryptionAlgorithmFactory used for encrypting and decrypting messages.
52+
*/
53+
public function getEncryptionAlgorithmFactory(): EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null
54+
{
55+
return $this->encryptionAlgorithmFactory;
56+
}
57+
58+
59+
/**
60+
* Retrieve the signature slgorithm to be used for signing messages.
61+
*/
62+
public function getSignatureAlgorithm(): string
63+
{
64+
return $this->signatureAlgorithm;
65+
}
66+
67+
68+
/**
69+
* Get the private key to use for signing messages.
70+
*
71+
* @return \SimpleSAML\XMLSecurity\Key\PrivateKey|null
72+
*/
73+
public function getSigningKey(): ?PrivateKey
74+
{
75+
return $this->signingKey;
76+
}
77+
78+
79+
/**
80+
* Get the validating keys to verify a message signature with.
81+
*
82+
* @return array<\SimpleSAML\XMLSecurity\Key\PublicKey>
83+
*/
84+
public function getValidatingKeys(): array
85+
{
86+
return $this->validatingKeys;
87+
}
88+
89+
90+
/**
91+
* Get the private key to use for signing messages.
92+
*
93+
* @return \SimpleSAML\XMLSecurity\Key\PublicKey|\SimpleSAML\XMLSecurity\Key\SymmetricKey|null
94+
*/
95+
public function getEncryptionKey(): PublicKey|SymmetricKey|null
96+
{
97+
return $this->encryptionKey;
98+
}
99+
100+
101+
/**
102+
* Get the decryption keys to decrypt the assertion with.
103+
*
104+
* @return array<\SimpleSAML\XMLSecurity\Key\PrivateKey|\SimpleSAML\XMLSecurity\Key\SymmetricKey>
105+
*/
106+
public function getDecryptionKeys(): array
107+
{
108+
return $this->decryptionKeys;
109+
}
110+
111+
112+
/**
113+
* Retrieve the configured entity ID for this entity
114+
*/
115+
public function getEntityId(): string
116+
{
117+
return $this->entityId;
118+
}
119+
120+
121+
/**
122+
* Retrieve the configured IDPList for this entity.
123+
*
124+
* @return string[]
125+
*/
126+
public function getIDPList(): array
127+
{
128+
return $this->IDPList;
129+
}
130+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\Metadata;
6+
7+
use SimpleSAML\XMLSecurity\Constants as C;
8+
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
9+
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
10+
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
11+
use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey};
12+
13+
/**
14+
* Class holding configuration for a SAML 2 Identity Provider.
15+
*
16+
* @package simplesamlphp/saml2
17+
*/
18+
class IdentityProvider extends AbstractProvider
19+
{
20+
/**
21+
*/
22+
public function __construct(
23+
string $entityId,
24+
EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null $encryptionAlgorithmFactory = null,
25+
SignatureAlgorithmFactory|null $signatureAlgorithmFactory = null,
26+
string $signatureAlgorithm = C::SIG_RSA_SHA256,
27+
array $validatingKeys = [],
28+
PrivateKey|null $signingKey = null,
29+
PublicKey|SymmetricKey|null $encryptionKey = null,
30+
array $decryptionKeys = [],
31+
array $IDPList = [],
32+
) {
33+
parent::__construct(
34+
$entityId,
35+
$encryptionAlgorithmFactory,
36+
$signatureAlgorithmFactory,
37+
$signatureAlgorithm,
38+
$validatingKeys,
39+
$signingKey,
40+
$encryptionKey,
41+
$decryptionKeys,
42+
$IDPList,
43+
);
44+
}
45+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2\Metadata;
6+
7+
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\SAML2\XML\md\AssertionConsumerService;
9+
use SimpleSAML\XMLSecurity\Constants as C;
10+
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
11+
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
12+
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
13+
use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey};
14+
15+
/**
16+
* Class holding configuration for a SAML 2 Service Provider.
17+
*
18+
* @package simplesamlphp/saml2
19+
*/
20+
class ServiceProvider extends AbstractProvider
21+
{
22+
/**
23+
*/
24+
public function __construct(
25+
string $entityId,
26+
EncryptionAlgorithmFactory|KeyTransportAlgorithmFactory|null $encryptionAlgorithmFactory = null,
27+
SignatureAlgorithmFactory|null $signatureAlgorithmFactory = null,
28+
string $signatureAlgorithm = C::SIG_RSA_SHA256,
29+
array $validatingKeys = [],
30+
PrivateKey|null $signingKey = null,
31+
PublicKey|SymmetricKey|null $encryptionKey = null,
32+
protected array $assertionConsumerService = [],
33+
array $decryptionKeys = [],
34+
array $IDPList = [],
35+
) {
36+
Assert::allIsInstanceOf($assertionConsumerService, AssertionConsumerService::class);
37+
38+
parent::__construct(
39+
$entityId,
40+
$encryptionAlgorithmFactory,
41+
$signatureAlgorithmFactory,
42+
$signatureAlgorithm,
43+
$validatingKeys,
44+
$signingKey,
45+
$encryptionKey,
46+
$decryptionKeys,
47+
$IDPList,
48+
);
49+
}
50+
51+
52+
/**
53+
* Retrieve the configured ACS-endpoints for this Service Provider.
54+
*
55+
* @return array<\SimpleSAML\SAML2\XML\md\AssertionConsumerService>
56+
*/
57+
public function getAssertionConsumerService(): array
58+
{
59+
return $this->assertionConsumerService;
60+
}
61+
}

0 commit comments

Comments
 (0)