-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrustChainFactory.php
More file actions
93 lines (77 loc) · 2.93 KB
/
Copy pathTrustChainFactory.php
File metadata and controls
93 lines (77 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
namespace SimpleSAML\OpenID\Federation\Factories;
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
use SimpleSAML\OpenID\Exceptions\TrustChainException;
use SimpleSAML\OpenID\Federation\EntityStatement;
use SimpleSAML\OpenID\Federation\MetadataPolicyApplicator;
use SimpleSAML\OpenID\Federation\MetadataPolicyResolver;
use SimpleSAML\OpenID\Federation\TrustChain;
use SimpleSAML\OpenID\Helpers;
class TrustChainFactory
{
public function __construct(
protected readonly EntityStatementFactory $entityStatementFactory,
protected readonly DateIntervalDecorator $timestampValidationLeeway,
protected readonly MetadataPolicyResolver $metadataPolicyResolver,
protected readonly MetadataPolicyApplicator $metadataPolicyApplicator,
protected readonly Helpers $helpers,
) {
}
public function empty(): TrustChain
{
return new TrustChain(
$this->timestampValidationLeeway,
$this->metadataPolicyResolver,
$this->metadataPolicyApplicator,
$this->helpers,
);
}
/**
* @throws \SimpleSAML\OpenID\Exceptions\TrustChainException
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
*/
public function fromStatements(EntityStatement ...$statements): TrustChain
{
if (count($statements) < 3) {
throw new TrustChainException(
sprintf('TrustChain must have at least 3 statements, %s given.', count($statements)),
);
}
$trustChain = $this->empty();
// First item should be the leaf configuration.
$trustChain->addLeaf(array_shift($statements));
// Middle items should be subordinate statements.
while (count($statements) > 1) {
$trustChain->addSubordinate(array_shift($statements));
}
// Last item should be trust anchor configuration.
($trustAnchorStatement = array_shift($statements)) || throw new TrustChainException(
'No Trust Anchor statement present.',
);
$trustChain->addTrustAnchor($trustAnchorStatement);
return $trustChain;
}
/**
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
* @throws \SimpleSAML\OpenID\Exceptions\TrustChainException
*/
public function fromTokens(string ...$tokens): TrustChain
{
$statements = array_map(
fn(string $token): EntityStatement => $this->entityStatementFactory->fromToken($token),
$tokens,
);
return $this->fromStatements(...$statements);
}
/**
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
* @throws \SimpleSAML\OpenID\Exceptions\TrustChainException
*/
public function forTrustAnchor(EntityStatement $trustAnchorStatement): TrustChain
{
$trustChain = $this->empty();
$trustChain->addForTrustAnchorOnly($trustAnchorStatement);
return $trustChain;
}
}