Skip to content

Commit 0cd0d77

Browse files
committed
Introduce JWS manager
1 parent 2fb6164 commit 0cd0d77

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

src/Jws.php

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID;
6+
7+
use DateInterval;
8+
use Psr\Log\LoggerInterface;
9+
use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator;
10+
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
11+
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
12+
use SimpleSAML\OpenID\Factories\ClaimFactory;
13+
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;
14+
use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory;
15+
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
16+
use SimpleSAML\OpenID\Jws\Factories\JwsDecoratorBuilderFactory;
17+
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory;
18+
use SimpleSAML\OpenID\Jws\Factories\ParsedJwsFactory;
19+
use SimpleSAML\OpenID\Jws\JwsDecoratorBuilder;
20+
use SimpleSAML\OpenID\Jws\JwsVerifierDecorator;
21+
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;
22+
23+
class Jws
24+
{
25+
protected DateIntervalDecorator $timestampValidationLeewayDecorator;
26+
27+
protected ?DateIntervalDecoratorFactory $dateIntervalDecoratorFactory = null;
28+
29+
protected ?ParsedJwsFactory $parsedJwsFactory = null;
30+
31+
protected ?JwsDecoratorBuilderFactory $jwsDecoratorBuilderFactory = null;
32+
33+
protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null;
34+
35+
protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null;
36+
37+
protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null;
38+
39+
protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null;
40+
41+
protected ?JwsVerifierDecorator $jwsVerifierDecorator = null;
42+
43+
protected ?Helpers $helpers = null;
44+
45+
protected ?JwksDecoratorFactory $jwksDecoratorFactory = null;
46+
47+
protected ?ClaimFactory $claimFactory = null;
48+
49+
protected ?JwsDecoratorBuilder $jwsDecoratorBuilder = null;
50+
51+
protected ?AlgorithmManagerDecorator $algorithmManagerDecorator = null;
52+
53+
54+
public function __construct(
55+
protected readonly SupportedAlgorithms $supportedAlgorithms = new SupportedAlgorithms(),
56+
protected readonly SupportedSerializers $supportedSerializers = new SupportedSerializers(),
57+
DateInterval $timestampValidationLeeway = new DateInterval('PT1M'),
58+
protected readonly ?LoggerInterface $logger = null,
59+
) {
60+
$this->timestampValidationLeewayDecorator = $this->dateIntervalDecoratorFactory()
61+
->build($timestampValidationLeeway);
62+
}
63+
64+
65+
public function dateIntervalDecoratorFactory(): DateIntervalDecoratorFactory
66+
{
67+
return $this->dateIntervalDecoratorFactory ??= new DateIntervalDecoratorFactory();
68+
}
69+
70+
71+
public function parsedJwsFactory(): ParsedJwsFactory
72+
{
73+
return $this->parsedJwsFactory ??= new ParsedJwsFactory(
74+
$this->jwsDecoratorBuilder(),
75+
$this->jwsVerifierDecorator(),
76+
$this->jwksDecoratorFactory(),
77+
$this->jwsSerializerManagerDecorator(),
78+
$this->timestampValidationLeewayDecorator,
79+
$this->helpers(),
80+
$this->claimFactory(),
81+
);
82+
}
83+
84+
85+
public function jwsDecoratorBuilder(): JwsDecoratorBuilder
86+
{
87+
return $this->jwsDecoratorBuilder ??= $this->jwsDecoratorBuilderFactory()->build(
88+
$this->jwsSerializerManagerDecorator(),
89+
$this->algorithmManagerDecorator(),
90+
$this->helpers(),
91+
);
92+
}
93+
94+
95+
public function jwsDecoratorBuilderFactory(): JwsDecoratorBuilderFactory
96+
{
97+
return $this->jwsDecoratorBuilderFactory ??= new JwsDecoratorBuilderFactory();
98+
}
99+
100+
101+
public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator
102+
{
103+
return $this->jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorFactory()
104+
->build($this->supportedSerializers);
105+
}
106+
107+
108+
public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory
109+
{
110+
return $this->jwsSerializerManagerDecoratorFactory ??= new JwsSerializerManagerDecoratorFactory();
111+
}
112+
113+
114+
public function algorithmManagerDecorator(): AlgorithmManagerDecorator
115+
{
116+
return $this->algorithmManagerDecorator ??= $this->algorithmManagerDecoratorFactory()
117+
->build($this->supportedAlgorithms);
118+
}
119+
120+
121+
public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory
122+
{
123+
return $this->algorithmManagerDecoratorFactory ??= new AlgorithmManagerDecoratorFactory();
124+
}
125+
126+
127+
public function helpers(): Helpers
128+
{
129+
return $this->helpers ??= new Helpers();
130+
}
131+
132+
133+
public function jwsVerifierDecorator(): JwsVerifierDecorator
134+
{
135+
return $this->jwsVerifierDecorator ??= $this->jwsVerifierDecoratorFactory()->build(
136+
$this->algorithmManagerDecorator(),
137+
);
138+
}
139+
140+
141+
public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory
142+
{
143+
return $this->jwsVerifierDecoratorFactory ??= new JwsVerifierDecoratorFactory();
144+
}
145+
146+
147+
public function jwksDecoratorFactory(): JwksDecoratorFactory
148+
{
149+
return $this->jwksDecoratorFactory ??= new JwksDecoratorFactory();
150+
}
151+
152+
153+
public function claimFactory(): ClaimFactory
154+
{
155+
return $this->claimFactory ??= new ClaimFactory(
156+
$this->helpers(),
157+
);
158+
}
159+
}

0 commit comments

Comments
 (0)