Skip to content

Commit cbbe427

Browse files
committed
Create MetadataProviderInterface
1 parent 540c26c commit cbbe427

2 files changed

Lines changed: 120 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\SAML2;
6+
7+
use SimpleSAML\SAML2\Metadata\IdentityProvider;
8+
use SimpleSAML\SAML2\Metadata\ServiceProvider;
9+
10+
interface MetadataProviderInterface
11+
{
12+
/**
13+
* Find IdP-metadata based on a SHA-1 hash of the entityID. Return `null` if not found.
14+
*/
15+
public function getIdPMetadataForSha1(string $hash): ?IdentityProvider;
16+
17+
18+
/**
19+
* Find SP-metadata based on a SHA-1 hash of the entityID. Return `null` if not found.
20+
*/
21+
public function getSPMetadataForSha1(string $hash): ?ServiceProvider;
22+
23+
24+
/**
25+
* Find IdP-metadata based on an entityID. Return `null` if not found.
26+
*/
27+
public function getIdPMetadata(string $entityId): ?IdentityProvider;
28+
29+
30+
/**
31+
* Find SP-metadata based on an entityID. Return `null` if not found.
32+
*/
33+
public function getSPMetadata(string $entityId): ?ServiceProvider;
34+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\SAML2;
6+
7+
use SimpleSAML\SAML2\Metadata\IdentityProvider;
8+
use SimpleSAML\SAML2\Metadata\ServiceProvider;
9+
use SimpleSAML\SAML2\MetadataProviderInterface;
10+
11+
use function sha1;
12+
13+
final class MockMetadataProvider implements MetadataProviderInterface
14+
{
15+
/** @var \SimpleSAML\SAML2\Metadata\AbstractProvider[] $entities */
16+
protected array $entities;
17+
18+
19+
/**
20+
* @param \SimpleSAML\SAML2\Metadata\AbstractProvider[] $entities
21+
*/
22+
public function __construct(array $entities)
23+
{
24+
$this->entities = $entities;
25+
}
26+
27+
28+
/**
29+
* Find IdP-metadata based on a SHA-1 hash of the entityID. Return `null` if not found.
30+
*/
31+
public function getIdPMetadataForSha1(string $hash): ?IdentityProvider
32+
{
33+
foreach ($this->entities as $entity) {
34+
if (($entity instanceof IdentityProvider) && ($hash === sha1($entity->getEntityId()))) {
35+
return $entity;
36+
}
37+
}
38+
39+
return null;
40+
}
41+
42+
43+
/**
44+
* Find SP-metadata based on a SHA-1 hash of the entityID. Return `null` if not found.
45+
*/
46+
public function getSPMetadataForSha1(string $hash): ?ServiceProvider
47+
{
48+
foreach ($this->entities as $entity) {
49+
if (($entity instanceof ServiceProvider) && ($hash === sha1($entity->getEntityId()))) {
50+
return $entity;
51+
}
52+
}
53+
54+
return null;
55+
}
56+
57+
58+
/**
59+
* Find IdP-metadata based on an entityID. Return `null` if not found.
60+
*/
61+
public function getIdPMetadata(string $entityId): ?IdentityProvider
62+
{
63+
foreach ($this->entities as $entity) {
64+
if (($entity instanceof IdentityProvider) && ($entityId === $entity->getEntityId())) {
65+
return $entity;
66+
}
67+
}
68+
69+
return null;
70+
}
71+
72+
73+
/**
74+
* Find SP-metadata based on an entityID. Return `null` if not found.
75+
*/
76+
public function getSPMetadata(string $entityId): ?ServiceProvider
77+
{
78+
foreach ($this->entities as $entity) {
79+
if (($entity instanceof ServiceProvider) && ($entityId === $entity->getEntityId())) {
80+
return $entity;
81+
}
82+
}
83+
84+
return null;
85+
}
86+
}

0 commit comments

Comments
 (0)