Skip to content

Commit b9c79d8

Browse files
committed
Expose additional request object instances
1 parent 8708bdc commit b9c79d8

2 files changed

Lines changed: 261 additions & 0 deletions

File tree

src/RequestObject.php

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,30 @@
88
use GuzzleHttp\Client;
99
use Psr\Log\LoggerInterface;
1010
use Psr\SimpleCache\CacheInterface;
11+
use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator;
1112
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmBag;
1213
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum;
14+
use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory as ConnectRequestObjectFactory;
1315
use SimpleSAML\OpenID\Decorators\CacheDecorator;
1416
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
1517
use SimpleSAML\OpenID\Decorators\HttpClientDecorator;
18+
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
1619
use SimpleSAML\OpenID\Factories\CacheDecoratorFactory;
20+
use SimpleSAML\OpenID\Factories\ClaimFactory;
1721
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;
1822
use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory;
23+
use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory;
24+
use SimpleSAML\OpenID\Federation\Factories\RequestObjectFactory as FederationRequestObjectFactory;
25+
use SimpleSAML\OpenID\Jar\Factories\RequestObjectFactory as JarRequestObjectFactory;
26+
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
27+
use SimpleSAML\OpenID\Jws\Factories\JwsDecoratorBuilderFactory;
28+
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory;
29+
use SimpleSAML\OpenID\Jws\JwsDecoratorBuilder;
30+
use SimpleSAML\OpenID\Jws\JwsVerifierDecorator;
31+
use SimpleSAML\OpenID\RequestObject\RequestObjectFactories;
32+
use SimpleSAML\OpenID\RequestObject\RequestObjectParser;
1933
use SimpleSAML\OpenID\RequestObject\RequestUriFetcher;
34+
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;
2035
use SimpleSAML\OpenID\Utils\ArtifactFetcher;
2136

2237
class RequestObject
@@ -33,6 +48,38 @@ class RequestObject
3348

3449
protected ?CacheDecorator $cacheDecorator;
3550

51+
protected ?RequestObjectFactories $requestObjectFactories = null;
52+
53+
protected ?RequestObjectParser $requestObjectParser = null;
54+
55+
protected ?ConnectRequestObjectFactory $connectRequestObjectFactory = null;
56+
57+
protected ?JarRequestObjectFactory $jarRequestObjectFactory = null;
58+
59+
protected ?FederationRequestObjectFactory $federationRequestObjectFactory = null;
60+
61+
protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null;
62+
63+
protected ?AlgorithmManagerDecorator $algorithmManagerDecorator = null;
64+
65+
protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null;
66+
67+
protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null;
68+
69+
protected ?JwsDecoratorBuilderFactory $jwsDecoratorBuilderFactory = null;
70+
71+
protected ?JwsDecoratorBuilder $jwsDecoratorBuilder = null;
72+
73+
protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null;
74+
75+
protected ?JwsVerifierDecorator $jwsVerifierDecorator = null;
76+
77+
protected ?JwksDecoratorFactory $jwksDecoratorFactory = null;
78+
79+
protected ?ClaimFactory $claimFactory = null;
80+
81+
protected ?Helpers $helpers = null;
82+
3683

3784
public function __construct(
3885
protected readonly SupportedAlgorithms $supportedAlgorithms = new SupportedAlgorithms(
@@ -96,4 +143,148 @@ public function cacheDecorator(): ?CacheDecorator
96143
{
97144
return $this->cacheDecorator;
98145
}
146+
147+
148+
public function requestObjectFactories(): RequestObjectFactories
149+
{
150+
return $this->requestObjectFactories ??= new RequestObjectFactories(
151+
$this->connectRequestObjectFactory(),
152+
$this->jarRequestObjectFactory(),
153+
$this->federationRequestObjectFactory(),
154+
);
155+
}
156+
157+
158+
public function requestObjectParser(): RequestObjectParser
159+
{
160+
return $this->requestObjectParser ??= new RequestObjectParser(
161+
$this->requestObjectFactories(),
162+
$this->requestUriFetcher(),
163+
$this->logger,
164+
);
165+
}
166+
167+
168+
public function connectRequestObjectFactory(): ConnectRequestObjectFactory
169+
{
170+
return $this->connectRequestObjectFactory ??= new ConnectRequestObjectFactory(
171+
$this->jwsDecoratorBuilder(),
172+
$this->jwsVerifierDecorator(),
173+
$this->jwksDecoratorFactory(),
174+
$this->jwsSerializerManagerDecorator(),
175+
$this->timestampValidationLeewayDecorator(),
176+
$this->helpers(),
177+
$this->claimFactory(),
178+
);
179+
}
180+
181+
182+
public function jarRequestObjectFactory(): JarRequestObjectFactory
183+
{
184+
return $this->jarRequestObjectFactory ??= new JarRequestObjectFactory(
185+
$this->jwsDecoratorBuilder(),
186+
$this->jwsVerifierDecorator(),
187+
$this->jwksDecoratorFactory(),
188+
$this->jwsSerializerManagerDecorator(),
189+
$this->timestampValidationLeewayDecorator(),
190+
$this->helpers(),
191+
$this->claimFactory(),
192+
);
193+
}
194+
195+
196+
public function federationRequestObjectFactory(): FederationRequestObjectFactory
197+
{
198+
return $this->federationRequestObjectFactory ??= new FederationRequestObjectFactory(
199+
$this->jwsDecoratorBuilder(),
200+
$this->jwsVerifierDecorator(),
201+
$this->jwksDecoratorFactory(),
202+
$this->jwsSerializerManagerDecorator(),
203+
$this->timestampValidationLeewayDecorator(),
204+
$this->helpers(),
205+
$this->claimFactory(),
206+
);
207+
}
208+
209+
210+
public function jwsDecoratorBuilder(): JwsDecoratorBuilder
211+
{
212+
return $this->jwsDecoratorBuilder ??= $this->jwsDecoratorBuilderFactory()->build(
213+
$this->jwsSerializerManagerDecorator(),
214+
$this->algorithmManagerDecorator(),
215+
$this->helpers(),
216+
);
217+
}
218+
219+
220+
public function jwsVerifierDecorator(): JwsVerifierDecorator
221+
{
222+
return $this->jwsVerifierDecorator ??= $this->jwsVerifierDecoratorFactory()->build(
223+
$this->algorithmManagerDecorator(),
224+
);
225+
}
226+
227+
228+
public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator
229+
{
230+
return $this->jwsSerializerManagerDecorator ??= $this->jwsSerializerManagerDecoratorFactory()
231+
->build($this->supportedSerializers);
232+
}
233+
234+
235+
public function algorithmManagerDecorator(): AlgorithmManagerDecorator
236+
{
237+
return $this->algorithmManagerDecorator ??= $this->algorithmManagerDecoratorFactory()
238+
->build($this->supportedAlgorithms);
239+
}
240+
241+
242+
public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory
243+
{
244+
return $this->algorithmManagerDecoratorFactory ??= new AlgorithmManagerDecoratorFactory();
245+
}
246+
247+
248+
public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory
249+
{
250+
return $this->jwsSerializerManagerDecoratorFactory ??= new JwsSerializerManagerDecoratorFactory();
251+
}
252+
253+
254+
public function jwsDecoratorBuilderFactory(): JwsDecoratorBuilderFactory
255+
{
256+
return $this->jwsDecoratorBuilderFactory ??= new JwsDecoratorBuilderFactory();
257+
}
258+
259+
260+
public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory
261+
{
262+
return $this->jwsVerifierDecoratorFactory ??= new JwsVerifierDecoratorFactory();
263+
}
264+
265+
266+
public function jwksDecoratorFactory(): JwksDecoratorFactory
267+
{
268+
return $this->jwksDecoratorFactory ??= new JwksDecoratorFactory();
269+
}
270+
271+
272+
public function claimFactory(): ClaimFactory
273+
{
274+
return $this->claimFactory ??= new ClaimFactory(
275+
$this->helpers(),
276+
);
277+
}
278+
279+
280+
public function helpers(): Helpers
281+
{
282+
return $this->helpers ??= new Helpers();
283+
}
284+
285+
286+
public function timestampValidationLeewayDecorator(): DateIntervalDecorator
287+
{
288+
return $this->timestampValidationLeewayDecorator;
289+
}
99290
}

tests/src/RequestObjectTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,34 @@
1111
use PHPUnit\Framework\TestCase;
1212
use Psr\Log\LoggerInterface;
1313
use Psr\SimpleCache\CacheInterface;
14+
use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator;
1415
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmBag;
1516
use SimpleSAML\OpenID\Algorithms\SignatureAlgorithmEnum;
17+
use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory as ConnectRequestObjectFactory;
1618
use SimpleSAML\OpenID\Decorators\CacheDecorator;
1719
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
1820
use SimpleSAML\OpenID\Decorators\HttpClientDecorator;
21+
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
1922
use SimpleSAML\OpenID\Factories\CacheDecoratorFactory;
23+
use SimpleSAML\OpenID\Factories\ClaimFactory;
2024
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;
2125
use SimpleSAML\OpenID\Factories\HttpClientDecoratorFactory;
26+
use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory;
27+
use SimpleSAML\OpenID\Federation\Factories\RequestObjectFactory as FederationRequestObjectFactory;
28+
use SimpleSAML\OpenID\Helpers;
29+
use SimpleSAML\OpenID\Jar\Factories\RequestObjectFactory as JarRequestObjectFactory;
30+
use SimpleSAML\OpenID\Jwks\Factories\JwksDecoratorFactory;
31+
use SimpleSAML\OpenID\Jws\Factories\JwsDecoratorBuilderFactory;
32+
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory;
33+
use SimpleSAML\OpenID\Jws\JwsDecoratorBuilder;
34+
use SimpleSAML\OpenID\Jws\JwsVerifierDecorator;
2235
use SimpleSAML\OpenID\RequestObject;
36+
use SimpleSAML\OpenID\RequestObject\RequestObjectFactories;
37+
use SimpleSAML\OpenID\RequestObject\RequestObjectParser;
2338
use SimpleSAML\OpenID\RequestObject\RequestUriFetcher;
2439
use SimpleSAML\OpenID\Serializers\JwsSerializerBag;
2540
use SimpleSAML\OpenID\Serializers\JwsSerializerEnum;
41+
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;
2642
use SimpleSAML\OpenID\SupportedAlgorithms;
2743
use SimpleSAML\OpenID\SupportedSerializers;
2844
use SimpleSAML\OpenID\Utils\ArtifactFetcher;
@@ -42,6 +58,22 @@
4258
#[UsesClass(SignatureAlgorithmEnum::class)]
4359
#[UsesClass(JwsSerializerBag::class)]
4460
#[UsesClass(JwsSerializerEnum::class)]
61+
#[UsesClass(RequestObjectFactories::class)]
62+
#[UsesClass(RequestObjectParser::class)]
63+
#[UsesClass(ConnectRequestObjectFactory::class)]
64+
#[UsesClass(JarRequestObjectFactory::class)]
65+
#[UsesClass(FederationRequestObjectFactory::class)]
66+
#[UsesClass(AlgorithmManagerDecorator::class)]
67+
#[UsesClass(AlgorithmManagerDecoratorFactory::class)]
68+
#[UsesClass(JwsSerializerManagerDecoratorFactory::class)]
69+
#[UsesClass(JwsSerializerManagerDecorator::class)]
70+
#[UsesClass(JwsDecoratorBuilderFactory::class)]
71+
#[UsesClass(JwsDecoratorBuilder::class)]
72+
#[UsesClass(JwsVerifierDecoratorFactory::class)]
73+
#[UsesClass(JwsVerifierDecorator::class)]
74+
#[UsesClass(JwksDecoratorFactory::class)]
75+
#[UsesClass(ClaimFactory::class)]
76+
#[UsesClass(Helpers::class)]
4577
final class RequestObjectTest extends TestCase
4678
{
4779
protected function sut(
@@ -90,6 +122,27 @@ public function testGettersReturnCorrectInstances(): void
90122
// Call fetcher getters which build fetchers
91123
$this->assertInstanceOf(ArtifactFetcher::class, $jar->artifactFetcher());
92124
$this->assertInstanceOf(RequestUriFetcher::class, $jar->requestUriFetcher());
125+
126+
$this->assertInstanceOf(RequestObjectFactories::class, $jar->requestObjectFactories());
127+
$this->assertInstanceOf(RequestObjectParser::class, $jar->requestObjectParser());
128+
$this->assertInstanceOf(ConnectRequestObjectFactory::class, $jar->connectRequestObjectFactory());
129+
$this->assertInstanceOf(JarRequestObjectFactory::class, $jar->jarRequestObjectFactory());
130+
$this->assertInstanceOf(FederationRequestObjectFactory::class, $jar->federationRequestObjectFactory());
131+
$this->assertInstanceOf(JwsDecoratorBuilder::class, $jar->jwsDecoratorBuilder());
132+
$this->assertInstanceOf(JwsVerifierDecorator::class, $jar->jwsVerifierDecorator());
133+
$this->assertInstanceOf(JwsSerializerManagerDecorator::class, $jar->jwsSerializerManagerDecorator());
134+
$this->assertInstanceOf(AlgorithmManagerDecorator::class, $jar->algorithmManagerDecorator());
135+
$this->assertInstanceOf(AlgorithmManagerDecoratorFactory::class, $jar->algorithmManagerDecoratorFactory());
136+
$this->assertInstanceOf(
137+
JwsSerializerManagerDecoratorFactory::class,
138+
$jar->jwsSerializerManagerDecoratorFactory(),
139+
);
140+
$this->assertInstanceOf(JwsDecoratorBuilderFactory::class, $jar->jwsDecoratorBuilderFactory());
141+
$this->assertInstanceOf(JwsVerifierDecoratorFactory::class, $jar->jwsVerifierDecoratorFactory());
142+
$this->assertInstanceOf(JwksDecoratorFactory::class, $jar->jwksDecoratorFactory());
143+
$this->assertInstanceOf(ClaimFactory::class, $jar->claimFactory());
144+
$this->assertInstanceOf(Helpers::class, $jar->helpers());
145+
$this->assertInstanceOf(DateIntervalDecorator::class, $jar->timestampValidationLeewayDecorator());
93146
}
94147

95148

@@ -102,6 +155,23 @@ public function testGettersReturnCachedInstances(): void
102155
$this->assertSame($jar->cacheDecoratorFactory(), $jar->cacheDecoratorFactory());
103156
$this->assertSame($jar->artifactFetcher(), $jar->artifactFetcher());
104157
$this->assertSame($jar->requestUriFetcher(), $jar->requestUriFetcher());
158+
159+
$this->assertSame($jar->requestObjectFactories(), $jar->requestObjectFactories());
160+
$this->assertSame($jar->requestObjectParser(), $jar->requestObjectParser());
161+
$this->assertSame($jar->connectRequestObjectFactory(), $jar->connectRequestObjectFactory());
162+
$this->assertSame($jar->jarRequestObjectFactory(), $jar->jarRequestObjectFactory());
163+
$this->assertSame($jar->federationRequestObjectFactory(), $jar->federationRequestObjectFactory());
164+
$this->assertSame($jar->jwsDecoratorBuilder(), $jar->jwsDecoratorBuilder());
165+
$this->assertSame($jar->jwsVerifierDecorator(), $jar->jwsVerifierDecorator());
166+
$this->assertSame($jar->jwsSerializerManagerDecorator(), $jar->jwsSerializerManagerDecorator());
167+
$this->assertSame($jar->algorithmManagerDecorator(), $jar->algorithmManagerDecorator());
168+
$this->assertSame($jar->algorithmManagerDecoratorFactory(), $jar->algorithmManagerDecoratorFactory());
169+
$this->assertSame($jar->jwsSerializerManagerDecoratorFactory(), $jar->jwsSerializerManagerDecoratorFactory());
170+
$this->assertSame($jar->jwsDecoratorBuilderFactory(), $jar->jwsDecoratorBuilderFactory());
171+
$this->assertSame($jar->jwsVerifierDecoratorFactory(), $jar->jwsVerifierDecoratorFactory());
172+
$this->assertSame($jar->jwksDecoratorFactory(), $jar->jwksDecoratorFactory());
173+
$this->assertSame($jar->claimFactory(), $jar->claimFactory());
174+
$this->assertSame($jar->helpers(), $jar->helpers());
105175
}
106176

107177

0 commit comments

Comments
 (0)