Skip to content

Commit

Permalink
Abstract finals to decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
cicnavi committed Jan 24, 2025
1 parent a9529ac commit 45ae044
Show file tree
Hide file tree
Showing 51 changed files with 611 additions and 503 deletions.
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@
},
"scripts": {
"pre-commit": [
"vendor/bin/phpcbf",
"vendor/bin/phpcs -p",
"composer update web-token/jwt-framework --with web-token/jwt-framework:^3.0",
"vendor/bin/psalm --no-cache",
"vendor/bin/rector --dry-run",
"vendor/bin/phpunit --no-coverage"
"vendor/bin/phpunit --no-coverage",
"composer update web-token/jwt-framework --with web-token/jwt-framework:^4.0",
"vendor/bin/psalm --no-cache",
"vendor/bin/phpunit --no-coverage",
"vendor/bin/rector --dry-run"
]
}
}
9 changes: 0 additions & 9 deletions src/Algorithms/AlgorithmManager.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/Algorithms/AlgorithmManagerDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\OpenID\Algorithms;

use Jose\Component\Core\AlgorithmManager;

class AlgorithmManagerDecorator
{
public function __construct(
protected readonly AlgorithmManager $algorithmManager,
) {
}

public function algorithmManager(): AlgorithmManager
{
return $this->algorithmManager;
}
}
73 changes: 37 additions & 36 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
use SimpleSAML\OpenID\Core\Factories\ClientAssertionFactory;
use SimpleSAML\OpenID\Core\Factories\RequestObjectFactory;
use SimpleSAML\OpenID\Decorators\DateIntervalDecorator;
use SimpleSAML\OpenID\Factories\AlgorithmManagerFactory;
use SimpleSAML\OpenID\Factories\AlgorithmManagerDecoratorFactory;
use SimpleSAML\OpenID\Factories\DateIntervalDecoratorFactory;
use SimpleSAML\OpenID\Factories\JwsSerializerManagerFactory;
use SimpleSAML\OpenID\Factories\JwsSerializerManagerDecoratorFactory;
use SimpleSAML\OpenID\Jwks\Factories\JwksFactory;
use SimpleSAML\OpenID\Jws\Factories\JwsParserFactory;
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierFactory;
use SimpleSAML\OpenID\Jws\Factories\JwsVerifierDecoratorFactory;
use SimpleSAML\OpenID\Jws\JwsParser;
use SimpleSAML\OpenID\Jws\JwsVerifier;
use SimpleSAML\OpenID\Serializers\JwsSerializerManager;
use SimpleSAML\OpenID\Jws\JwsVerifierDecorator;
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;

class Core
{
protected DateIntervalDecorator $timestampValidationLeewayDecorator;
protected ?JwsSerializerManager $jwsSerializerManager = null;
protected ?JwsSerializerManagerDecorator $jwsSerializerManagerDecorator = null;
protected ?JwsParser $jwsParser = null;
protected ?JwsVerifier $jwsVerifier = null;
protected ?JwsVerifierDecorator $jwsVerifierDecorator = null;
protected ?RequestObjectFactory $requestObjectFactory = null;
protected ?ClientAssertionFactory $clientAssertionFactory = null;
protected ?Helpers $helpers = null;
protected ?AlgorithmManagerFactory $algorithmManagerFactory = null;
protected ?JwsSerializerManagerFactory $jwsSerializerManagerFactory = null;
protected ?AlgorithmManagerDecoratorFactory $algorithmManagerDecoratorFactory = null;
protected ?JwsSerializerManagerDecoratorFactory $jwsSerializerManagerDecoratorFactory = null;
protected ?JwsParserFactory $jwsParserFactory = null;
protected ?JwsVerifierFactory $jwsVerifierFactory = null;
protected ?JwsVerifierDecoratorFactory $jwsVerifierDecoratorFactory = null;
protected ?JwksFactory $jwksFactory = null;
protected ?DateIntervalDecoratorFactory $dateIntervalDecoratorFactory = null;

Expand All @@ -56,9 +56,9 @@ public function requestObjectFactory(): RequestObjectFactory
{
return $this->requestObjectFactory ??= new RequestObjectFactory(
$this->jwsParser(),
$this->jwsVerifier(),
$this->jwsVerifierDecorator(),
$this->jwksFactory(),
$this->jwsSerializerManager(),
$this->jwsSerializerManagerDecorator(),
$this->timestampValidationLeewayDecorator,
$this->helpers(),
);
Expand All @@ -68,9 +68,9 @@ public function clientAssertionFactory(): ClientAssertionFactory
{
return $this->clientAssertionFactory ??= new ClientAssertionFactory(
$this->jwsParser(),
$this->jwsVerifier(),
$this->jwsVerifierDecorator(),
$this->jwksFactory(),
$this->jwsSerializerManager(),
$this->jwsSerializerManagerDecorator(),
$this->timestampValidationLeewayDecorator,
$this->helpers(),
);
Expand All @@ -81,20 +81,20 @@ public function helpers(): Helpers
return $this->helpers ??= new Helpers();
}

public function algorithmManagerFactory(): AlgorithmManagerFactory
public function algorithmManagerDecoratorFactory(): AlgorithmManagerDecoratorFactory
{
if (is_null($this->algorithmManagerFactory)) {
$this->algorithmManagerFactory = new AlgorithmManagerFactory();
if (is_null($this->algorithmManagerDecoratorFactory)) {
$this->algorithmManagerDecoratorFactory = new AlgorithmManagerDecoratorFactory();
}
return $this->algorithmManagerFactory;
return $this->algorithmManagerDecoratorFactory;
}

public function jwsSerializerManagerFactory(): JwsSerializerManagerFactory
public function jwsSerializerManagerDecoratorFactory(): JwsSerializerManagerDecoratorFactory
{
if (is_null($this->jwsSerializerManagerFactory)) {
$this->jwsSerializerManagerFactory = new JwsSerializerManagerFactory();
if (is_null($this->jwsSerializerManagerDecoratorFactory)) {
$this->jwsSerializerManagerDecoratorFactory = new JwsSerializerManagerDecoratorFactory();
}
return $this->jwsSerializerManagerFactory;
return $this->jwsSerializerManagerDecoratorFactory;
}

public function jwsParserFactory(): JwsParserFactory
Expand All @@ -105,12 +105,12 @@ public function jwsParserFactory(): JwsParserFactory
return $this->jwsParserFactory;
}

public function jwsVerifierFactory(): JwsVerifierFactory
public function jwsVerifierDecoratorFactory(): JwsVerifierDecoratorFactory
{
if (is_null($this->jwsVerifierFactory)) {
$this->jwsVerifierFactory = new JwsVerifierFactory();
if (is_null($this->jwsVerifierDecoratorFactory)) {
$this->jwsVerifierDecoratorFactory = new JwsVerifierDecoratorFactory();
}
return $this->jwsVerifierFactory;
return $this->jwsVerifierDecoratorFactory;
}

public function jwksFactory(): JwksFactory
Expand All @@ -127,29 +127,30 @@ public function dateIntervalDecoratorFactory(): DateIntervalDecoratorFactory
return $this->dateIntervalDecoratorFactory;
}

public function jwsSerializerManager(): JwsSerializerManager
public function jwsSerializerManagerDecorator(): JwsSerializerManagerDecorator
{
if (is_null($this->jwsSerializerManager)) {
$this->jwsSerializerManager = $this->jwsSerializerManagerFactory()->build($this->supportedSerializers);
if (is_null($this->jwsSerializerManagerDecorator)) {
$this->jwsSerializerManagerDecorator = $this->jwsSerializerManagerDecoratorFactory()
->build($this->supportedSerializers);
}
return $this->jwsSerializerManager;
return $this->jwsSerializerManagerDecorator;
}

public function jwsParser(): JwsParser
{
if (is_null($this->jwsParser)) {
$this->jwsParser = $this->jwsParserFactory()->build($this->jwsSerializerManager());
$this->jwsParser = $this->jwsParserFactory()->build($this->jwsSerializerManagerDecorator());
}
return $this->jwsParser;
}

public function jwsVerifier(): JwsVerifier
public function jwsVerifierDecorator(): JwsVerifierDecorator
{
if (is_null($this->jwsVerifier)) {
$this->jwsVerifier = $this->jwsVerifierFactory()->build(
$this->algorithmManagerFactory()->build($this->supportedAlgorithms),
if (is_null($this->jwsVerifierDecorator)) {
$this->jwsVerifierDecorator = $this->jwsVerifierDecoratorFactory()->build(
$this->algorithmManagerDecoratorFactory()->build($this->supportedAlgorithms),
);
}
return $this->jwsVerifier;
return $this->jwsVerifierDecorator;
}
}
4 changes: 2 additions & 2 deletions src/Core/Factories/ClientAssertionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function fromToken(string $token): ClientAssertion
{
return new ClientAssertion(
$this->jwsParser->parse($token),
$this->jwsVerifier,
$this->jwsVerifierDecorator,
$this->jwksFactory,
$this->jwsSerializerManager,
$this->jwsSerializerManagerDecorator,
$this->timestampValidationLeeway,
$this->helpers,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Factories/RequestObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function fromToken(string $token): RequestObject
{
return new RequestObject(
$this->jwsParser->parse($token),
$this->jwsVerifier,
$this->jwsVerifierDecorator,
$this->jwksFactory,
$this->jwsSerializerManager,
$this->jwsSerializerManagerDecorator,
$this->timestampValidationLeeway,
$this->helpers,
);
Expand Down
21 changes: 21 additions & 0 deletions src/Factories/AlgorithmManagerDecoratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\OpenID\Factories;

use Jose\Component\Core\AlgorithmManager;
use SimpleSAML\OpenID\Algorithms\AlgorithmManagerDecorator;
use SimpleSAML\OpenID\SupportedAlgorithms;

class AlgorithmManagerDecoratorFactory
{
public function build(SupportedAlgorithms $supportedAlgorithms): AlgorithmManagerDecorator
{
return new AlgorithmManagerDecorator(
new AlgorithmManager(
$supportedAlgorithms->getSignatureAlgorithmBag()->getAllInstances(),
),
);
}
}
16 changes: 0 additions & 16 deletions src/Factories/AlgorithmManagerFactory.php

This file was deleted.

21 changes: 21 additions & 0 deletions src/Factories/JwsSerializerManagerDecoratorFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\OpenID\Factories;

use Jose\Component\Signature\Serializer\JWSSerializerManager;
use SimpleSAML\OpenID\Serializers\JwsSerializerManagerDecorator;
use SimpleSAML\OpenID\SupportedSerializers;

class JwsSerializerManagerDecoratorFactory
{
public function build(SupportedSerializers $supportedSerializers): JwsSerializerManagerDecorator
{
return new JwsSerializerManagerDecorator(
new JWSSerializerManager(
$supportedSerializers->getJwsSerializerBag()->getAllInstances(),
),
);
}
}
16 changes: 0 additions & 16 deletions src/Factories/JwsSerializerManagerFactory.php

This file was deleted.

Loading

0 comments on commit 45ae044

Please sign in to comment.