From 0dc18e9ba8b9e5aa7dcf8c4f489507dbf23afd36 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 26 Sep 2022 12:46:58 +0200 Subject: [PATCH 01/10] work in progress --- .gitignore | 1 - LICENSE | 2 +- composer.json | 16 ++-- grumphp.yml.dist | 9 +- infection.json.dist | 8 +- phpspec.yml.dist | 5 + .../Core/User/EuLoginUserProviderSpec.php | 41 +++++++-- .../Security/Core/User/EuLoginUserSpec.php | 91 +++++++++++++------ src/Resources/config/services.php | 26 +++--- .../Core/User/EuLoginUserProvider.php | 14 ++- 10 files changed, 141 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index f0a8876..0032e3c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ grumphp.yml phpspec.yml /build/ .php_cs.cache -.envrc \ No newline at end of file diff --git a/LICENSE b/LICENSE index e8c58a0..498cf7a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2020-2022, European Union. +Copyright (c) 2019-2022, European Union. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/composer.json b/composer.json index cd83bb5..ea4c939 100644 --- a/composer.json +++ b/composer.json @@ -13,23 +13,23 @@ "sso" ], "require": { - "php": ">= 7.4", + "php": ">= 8.1", "ext-json": "*", "ext-simplexml": "*", - "ecphp/cas-bundle": "dev-master", - "ecphp/ecas": "^2", - "symfony/framework-bundle": "^5.4 || ^6" + "ecphp/cas-bundle": "dev-refactor/cas-lib-v2", + "ecphp/ecas": "^3", + "symfony/framework-bundle": "^6.1" }, "require-dev": { "ext-pcov": "*", "ecphp/php-conventions": "^1", "friends-of-phpspec/phpspec-code-coverage": "^6", - "infection/infection": "^0.24.0", - "infection/phpspec-adapter": "^0.1.2", + "infection/infection": "^0.26.0", + "infection/phpspec-adapter": "^0.2", "nyholm/psr7": "^1.5", "phpspec/phpspec": "^7", - "symfony/http-client": "^5.4 || ^6", - "symfony/security-core": "^5.4 || ^6" + "symfony/http-client": "^6.1", + "symfony/security-core": "^6.1" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 235ed71..0c85a2b 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -2,13 +2,16 @@ imports: - { resource: vendor/ecphp/php-conventions/config/php73/grumphp.yml } parameters: - tasks.license.date_from: 2020 + tasks.phpstan.configuration: phpstan.neon extra_tasks: phpspec: verbose: true + clover_coverage: + clover_file: build/logs/clover.xml + level: 50 infection: threads: 10 test_framework: phpspec configuration: infection.json.dist - min_msi: 10 - min_covered_msi: 10 + min_msi: 50 + min_covered_msi: 90 diff --git a/infection.json.dist b/infection.json.dist index 3fe5fe5..78ed0b7 100644 --- a/infection.json.dist +++ b/infection.json.dist @@ -1,17 +1,19 @@ { - "timeout": 10, + "timeout": 30, "source": { "directories": [ "src" ] }, "logs": { + "github": true, "text": "build/infection.log", "summary": "build/summary.log", "debug": "build/debug.log", "perMutator": "build/per-mutator.md", - "badge": { - "branch": "master" + "html": "build/report.html", + "stryker": { + "report": "master" } }, "testFramework":"phpspec" diff --git a/phpspec.yml.dist b/phpspec.yml.dist index 9de3cd0..85449bb 100644 --- a/phpspec.yml.dist +++ b/phpspec.yml.dist @@ -5,7 +5,12 @@ extensions: - clover - php - text + - html output: html: build/coverage clover: build/logs/clover.xml php: build/coverage.php + whitelist: + - src + blacklist: + - src/Resources diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php index 8ac2071..64ec62e 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php @@ -11,14 +11,22 @@ namespace spec\EcPhp\EuLoginBundle\Security\Core\User; +use EcPhp\CasBundle\Cas\SymfonyCasResponseBuilder; use EcPhp\CasBundle\Security\Core\User\CasUserProvider; -use EcPhp\CasLib\Introspection\Introspector; -use EcPhp\Ecas\Introspection\EcasIntrospector; +use EcPhp\CasLib\Response\CasResponseBuilder; +use EcPhp\CasLib\Response\Factory\AuthenticationFailureFactory; +use EcPhp\CasLib\Response\Factory\ProxyFactory; +use EcPhp\CasLib\Response\Factory\ProxyFailureFactory; +use EcPhp\CasLib\Response\Factory\ServiceValidateFactory as FactoryServiceValidateFactory; +use EcPhp\Ecas\Response\Factory\ServiceValidateFactory; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserInterface; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; -use Nyholm\Psr7\Response; +use loophp\psr17\Psr17; +use Nyholm\Psr7\Factory\Psr17Factory; use PhpSpec\ObjectBehavior; +use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\InMemoryUser; @@ -38,7 +46,7 @@ public function it_can_check_if_the_user_class_is_supported() public function it_can_load_a_user_from_a_response(): void { // TestBody1 - $response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody1()); + $response = new Response($this->getTestBody1(), 200, ['content-type' => 'application/xml']); $user = $this->loadUserByResponse($response); @@ -143,7 +151,7 @@ public function it_can_load_a_user_from_a_response(): void ]); // TestBody2 - $response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody2()); + $response = new Response($this->getTestBody2(), 200, ['content-type' => 'application/xml']); $user = $this->loadUserByResponse($response); @@ -256,8 +264,29 @@ public function it_is_initializable() public function let() { + $psr17Factory = new Psr17Factory(); + + $psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory); + + $casResponseBuilder = new CasResponseBuilder( + new AuthenticationFailureFactory(), + new ProxyFactory(), + new ProxyFailureFactory(), + new ServiceValidateFactory(new FactoryServiceValidateFactory(), $psr17) + ); + + $psrHttpFactory = new PsrHttpFactory( + $psr17Factory, + $psr17Factory, + $psr17Factory, + $psr17Factory + ); + $this - ->beConstructedWith(new CasUserProvider(new EcasIntrospector(new Introspector()))); + ->beConstructedWith( + new CasUserProvider($casResponseBuilder, $psrHttpFactory), + new SymfonyCasResponseBuilder($casResponseBuilder, $psrHttpFactory) + ); } private function getTestBody1() diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php index 78810dc..2c44ec8 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php @@ -11,39 +11,49 @@ namespace spec\EcPhp\EuLoginBundle\Security\Core\User; +use EcPhp\CasBundle\Cas\SymfonyCasResponseBuilder; use EcPhp\CasBundle\Security\Core\User\CasUser; -use EcPhp\CasLib\Introspection\Introspector; +use EcPhp\CasLib\Response\CasResponseBuilder; +use EcPhp\CasLib\Response\Factory\AuthenticationFailureFactory; +use EcPhp\CasLib\Response\Factory\ProxyFactory; +use EcPhp\CasLib\Response\Factory\ProxyFailureFactory; +use EcPhp\CasLib\Response\Factory\ServiceValidateFactory; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser; -use Nyholm\Psr7\Response; +use Nyholm\Psr7\Factory\Psr17Factory; use PhpSpec\ObjectBehavior; +use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; +use Symfony\Component\HttpFoundation\Response; class EuLoginUserSpec extends ObjectBehavior { public function it_can_get_groups_when_no_groups_are_available() { - $body = <<<'EOF' - - - username - bar - - foo - - - - - - rex - snoopy - - - - - - EOF; - - $response = new Response(200, ['Content-Type' => 'application/xml'], $body); - $data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess']; + $data = [ + 'user' => 'username', + 'foo' => 'bar', + 'proxies' => [ + 'proxy' => 'foo', + ], + 'attributes' => [ + 'groups' => [ + '@value' => '', + '@attributes' => [ + 'number' => '0', + ], + ], + 'extendedAttributes' => [ + 'extendedAttribute' => [ + 'attributeValue' => [ + 0 => 'rex', + 1 => 'snoopy', + ], + '@attributes' => [ + 'name' => 'http://stork.eu/motherInLawDogName', + ], + ], + ], + ], + ]; $casUser = new CasUser($data); @@ -53,6 +63,9 @@ public function it_can_get_groups_when_no_groups_are_available() $this ->getGroups() ->shouldReturn([]); + $this + ->getUserIdentifier() + ->shouldReturn('username'); } public function it_can_get_specific_attribute() @@ -295,10 +308,32 @@ public function let() EOF; - $response = new Response(200, ['Content-Type' => 'application/xml'], $body); - $data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess']; + $response = new Response($body, 200, ['Content-Type' => 'application/xml']); + + $psr17Factory = new Psr17Factory(); + + $casResponseBuilder = new CasResponseBuilder( + new AuthenticationFailureFactory(), + new ProxyFactory(), + new ProxyFailureFactory(), + new ServiceValidateFactory() + ); + + $psrHttpFactory = new PsrHttpFactory( + $psr17Factory, + $psr17Factory, + $psr17Factory, + $psr17Factory + ); + + $symfonyCasResponseBuilder = new SymfonyCasResponseBuilder( + $casResponseBuilder, + $psrHttpFactory + ); + + $responseArray = $symfonyCasResponseBuilder->fromResponse($response)->toArray(); - $this->beConstructedWith(new CasUser($data)); + $this->beConstructedWith(new CasUser($responseArray['serviceResponse']['authenticationSuccess'])); } private function getAttributesData(): array diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index d78d3fb..5cecf72 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -11,9 +11,11 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; +use EcPhp\CasBundle\Cas\SymfonyCasInterface; +use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface; +use EcPhp\CasLib\Contract\Configuration\PropertiesInterface; use EcPhp\Ecas\Ecas; use EcPhp\Ecas\EcasProperties; -use EcPhp\Ecas\Introspection\EcasIntrospector; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; return static function (ContainerConfigurator $container) { @@ -25,21 +27,17 @@ ->autowire(true); $services - ->set('ecas.introspector', EcasIntrospector::class) - ->decorate('cas.introspector') - ->arg('$introspector', service('ecas.introspector.inner')); + ->set(EuLoginUserProvider::class) + ->decorate(CasUserProviderInterface::class) + ->arg('$casUserProvider', service('.inner')); $services - ->set('eulogin.userprovider', EuLoginUserProvider::class) - ->arg('$casUserProvider', service('cas.userprovider')); + ->set(EcasProperties::class) + ->decorate(PropertiesInterface::class) + ->arg('$casProperties', service('.inner')); $services - ->set('ecas.configuration', EcasProperties::class) - ->decorate('cas.configuration') - ->arg('$casProperties', service('ecas.configuration.inner')); - - $services - ->set('ecas', Ecas::class) - ->decorate('cas') - ->arg('$cas', service('ecas.inner')); + ->set(Ecas::class) + ->decorate(SymfonyCasInterface::class) + ->arg('$cas', service('.inner')); }; diff --git a/src/Security/Core/User/EuLoginUserProvider.php b/src/Security/Core/User/EuLoginUserProvider.php index b13bd91..b3e3ab9 100644 --- a/src/Security/Core/User/EuLoginUserProvider.php +++ b/src/Security/Core/User/EuLoginUserProvider.php @@ -13,7 +13,7 @@ use EcPhp\CasBundle\Security\Core\User\CasUserInterface; use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface; -use Psr\Http\Message\ResponseInterface; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\UserInterface; @@ -21,13 +21,11 @@ final class EuLoginUserProvider implements CasUserProviderInterface { - /** - * @var CasUserProviderInterface - */ - private $casUserProvider; + private CasUserProviderInterface $casUserProvider; - public function __construct(CasUserProviderInterface $casUserProvider) - { + public function __construct( + CasUserProviderInterface $casUserProvider + ) { $this->casUserProvider = $casUserProvider; } @@ -36,7 +34,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface throw new UnsupportedUserException('Unsupported operation.'); } - public function loadUserByResponse(ResponseInterface $response): CasUserInterface + public function loadUserByResponse(Response $response): CasUserInterface { return new EuLoginUser($this->casUserProvider->loadUserByResponse($response)); } From f1b30912a0c751c044c851b36d1787787a66d377 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 26 Sep 2022 13:10:44 +0200 Subject: [PATCH 02/10] work in progress --- grumphp.yml.dist | 1 - .../Core/User/EuLoginUserProviderSpec.php | 4 +-- .../Security/Core/User/EuLoginUserSpec.php | 13 ++------ src/Security/Core/User/EuLoginUser.php | 33 +++---------------- .../Core/User/EuLoginUserProvider.php | 10 ++---- 5 files changed, 11 insertions(+), 50 deletions(-) diff --git a/grumphp.yml.dist b/grumphp.yml.dist index 0c85a2b..bd5b31a 100644 --- a/grumphp.yml.dist +++ b/grumphp.yml.dist @@ -2,7 +2,6 @@ imports: - { resource: vendor/ecphp/php-conventions/config/php73/grumphp.yml } parameters: - tasks.phpstan.configuration: phpstan.neon extra_tasks: phpspec: verbose: true diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php index 64ec62e..8af60e5 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php @@ -250,11 +250,11 @@ public function it_can_refresh_a_user(EuLoginUserInterface $user) ->shouldReturn($user); } - public function it_cannot_load_a_user_by_username() + public function it_cannot_load_a_user_by_identifier() { $this ->shouldThrow(UnsupportedUserException::class) - ->during('loadUserByUsername', ['foo']); + ->during('loadUserByIdentifier', ['foo']); } public function it_is_initializable() diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php index 2c44ec8..e23250d 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php @@ -23,6 +23,7 @@ use PhpSpec\ObjectBehavior; use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; class EuLoginUserSpec extends ObjectBehavior { @@ -188,18 +189,10 @@ public function it_is_initializable() { $this->shouldHaveType(EuLoginUser::class); - $this - ->getPassword() - ->shouldBeNull(); - $this ->getPgt() ->shouldReturn('proxyGrantingTicket'); - $this - ->getSalt() - ->shouldBeNull(); - $this ->getUserIdentifier() ->shouldReturn('username'); @@ -209,8 +202,8 @@ public function it_is_initializable() ->shouldReturn('bar'); $this - ->eraseCredentials() - ->shouldBeNull(); + ->shouldThrow(UnsupportedUserException::class) + ->during('eraseCredentials'); } public function let() diff --git a/src/Security/Core/User/EuLoginUser.php b/src/Security/Core/User/EuLoginUser.php index 66fcd41..acb524b 100644 --- a/src/Security/Core/User/EuLoginUser.php +++ b/src/Security/Core/User/EuLoginUser.php @@ -12,6 +12,7 @@ namespace EcPhp\EuLoginBundle\Security\Core\User; use EcPhp\CasBundle\Security\Core\User\CasUserInterface; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\UserInterface; use function array_key_exists; @@ -27,10 +28,10 @@ public function __construct(CasUserInterface $user) public function eraseCredentials(): void { - // null + throw new UnsupportedUserException('Unsupported method.'); } - public function get(string $key, $default = null) + public function get(string $key, mixed $default = null): mixed { return $this->user->get($key, $default); } @@ -40,7 +41,7 @@ public function getAssuranceLevel(): ?string return $this->user->getAttribute('assuranceLevel'); } - public function getAttribute(string $key, $default = null) + public function getAttribute(string $key, mixed $default = null): mixed { return $this->user->getAttribute($key, $default); } @@ -182,11 +183,6 @@ public function getOrgId(): ?string return $this->user->getAttribute('orgId'); } - public function getPassword() - { - return null; - } - public function getPgt(): ?string { return $this->user->getPgt(); @@ -204,11 +200,6 @@ public function getRoles(): array return array_merge($this->getGroups(), $default); } - public function getSalt() - { - return null; - } - public function getSso(): ?string { return $this->user->getAttribute('sso'); @@ -266,22 +257,6 @@ public function getUserManager(): ?string return $this->user->getAttribute('userManager'); } - /** - * @deprecated since Symfony 5.3, use getUserIdentifier() instead - */ - public function getUsername() - { - trigger_deprecation( - 'ecphp/eu-login-bundle', - '2.3.8', - 'The method "%s::getUsername()" is deprecated, use %s::getUserIdentifier() instead.', - EuLoginUser::class, - EuLoginUser::class - ); - - return $this->getUserIdentifier(); - } - public function isEqualTo(UserInterface $user): bool { return $this->user->isEqualTo($user); diff --git a/src/Security/Core/User/EuLoginUserProvider.php b/src/Security/Core/User/EuLoginUserProvider.php index b3e3ab9..7b7ee76 100644 --- a/src/Security/Core/User/EuLoginUserProvider.php +++ b/src/Security/Core/User/EuLoginUserProvider.php @@ -23,9 +23,8 @@ final class EuLoginUserProvider implements CasUserProviderInterface { private CasUserProviderInterface $casUserProvider; - public function __construct( - CasUserProviderInterface $casUserProvider - ) { + public function __construct(CasUserProviderInterface $casUserProvider) + { $this->casUserProvider = $casUserProvider; } @@ -39,11 +38,6 @@ public function loadUserByResponse(Response $response): CasUserInterface return new EuLoginUser($this->casUserProvider->loadUserByResponse($response)); } - public function loadUserByUsername(string $username) - { - throw new UnsupportedUserException(sprintf('Username "%s" does not exist.', $username)); - } - public function refreshUser(UserInterface $user) { if (!$user instanceof EuLoginUserInterface) { From 25f9d77ac0f2ebd73d3e0465bc8c606f946c4655 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 26 Sep 2022 14:19:52 +0200 Subject: [PATCH 03/10] work in progress --- src/DependencyInjection/EuLoginExtension.php | 5 ++++- src/Security/Core/User/EuLoginUserProvider.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/DependencyInjection/EuLoginExtension.php b/src/DependencyInjection/EuLoginExtension.php index 11aa6e6..f564974 100644 --- a/src/DependencyInjection/EuLoginExtension.php +++ b/src/DependencyInjection/EuLoginExtension.php @@ -21,7 +21,10 @@ final class EuLoginExtension extends Extension public function load(array $configs, ContainerBuilder $container): void { // Load EU Login services. - $loader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new PhpFileLoader( + $container, + new FileLocator(__DIR__ . '/../Resources/config') + ); $loader->load('services.php'); } } diff --git a/src/Security/Core/User/EuLoginUserProvider.php b/src/Security/Core/User/EuLoginUserProvider.php index 7b7ee76..6047855 100644 --- a/src/Security/Core/User/EuLoginUserProvider.php +++ b/src/Security/Core/User/EuLoginUserProvider.php @@ -30,7 +30,7 @@ public function __construct(CasUserProviderInterface $casUserProvider) public function loadUserByIdentifier(string $identifier): UserInterface { - throw new UnsupportedUserException('Unsupported operation.'); + return $this->casUserProvider->loadUserByIdentifier($identifier); } public function loadUserByResponse(Response $response): CasUserInterface @@ -44,7 +44,7 @@ public function refreshUser(UserInterface $user) throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); } - return $user; + return $this->casUserProvider->refreshUser($user); } public function supportsClass(string $class) From 74015e26454d748fbb978ab9bb23e838a7355101 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 26 Sep 2022 15:03:10 +0200 Subject: [PATCH 04/10] Work in progress --- src/Cas/SymfonyECas.php | 151 ++++++++++++++++++++++++++++++ src/Resources/config/services.php | 4 +- 2 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 src/Cas/SymfonyECas.php diff --git a/src/Cas/SymfonyECas.php b/src/Cas/SymfonyECas.php new file mode 100644 index 0000000..37cfc1e --- /dev/null +++ b/src/Cas/SymfonyECas.php @@ -0,0 +1,151 @@ +cas = $cas; + $this->httpMessageFactory = $httpMessageFactory; + } + + public function authenticate( + ServerRequestInterface|Request $request, + array $parameters = [] + ): array { + return $this + ->cas + ->authenticate( + $this->updateRequest($request), + $parameters + ); + } + + public function handleProxyCallback( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->handleProxyCallback( + $this->updateRequest($request), + $parameters + ); + } + + public function login( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->login( + $this->updateRequest($request), + $parameters + ); + } + + public function logout( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->logout( + $this->updateRequest($request), + $parameters + ); + } + + public function process( + ServerRequestInterface|Request $request, + RequestHandlerInterface $handler + ): ResponseInterface { + return $this + ->cas + ->process( + $this->updateRequest($request), + $handler + ); + } + + public function requestProxyTicket( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->requestProxyTicket( + $this->updateRequest($request), + $parameters + ); + } + + public function requestServiceValidate( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->requestServiceValidate( + $this->updateRequest($request), + $parameters + ); + } + + public function requestTicketValidation( + ServerRequestInterface|Request $request, + array $parameters = [] + ): ResponseInterface { + return $this + ->cas + ->requestTicketValidation( + $this->updateRequest($request), + $parameters + ); + } + + public function supportAuthentication( + ServerRequestInterface|Request $request, + array $parameters = [] + ): bool { + return $this + ->cas + ->supportAuthentication( + $this->updateRequest($request), + $parameters + ); + } + + private function updateRequest( + ServerRequestInterface|Request $request + ): ServerRequestInterface { + return $request instanceof Request + ? $this->httpMessageFactory->createRequest($request) + : $request; + } +} diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 5cecf72..e027595 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -14,8 +14,8 @@ use EcPhp\CasBundle\Cas\SymfonyCasInterface; use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface; use EcPhp\CasLib\Contract\Configuration\PropertiesInterface; -use EcPhp\Ecas\Ecas; use EcPhp\Ecas\EcasProperties; +use EcPhp\EuLoginBundle\Cas\SymfonyECas; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; return static function (ContainerConfigurator $container) { @@ -37,7 +37,7 @@ ->arg('$casProperties', service('.inner')); $services - ->set(Ecas::class) + ->set(SymfonyECas::class) ->decorate(SymfonyCasInterface::class) ->arg('$cas', service('.inner')); }; From c5dd7f2ea4fca0ad966bb741d7955c0b1201d9a8 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 28 Sep 2022 23:09:27 +0200 Subject: [PATCH 05/10] fix: fix signature --- src/Security/Core/User/EuLoginUserProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Security/Core/User/EuLoginUserProvider.php b/src/Security/Core/User/EuLoginUserProvider.php index 6047855..a528bd7 100644 --- a/src/Security/Core/User/EuLoginUserProvider.php +++ b/src/Security/Core/User/EuLoginUserProvider.php @@ -13,7 +13,7 @@ use EcPhp\CasBundle\Security\Core\User\CasUserInterface; use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface; -use Symfony\Component\HttpFoundation\Response; +use Psr\Http\Message\ResponseInterface; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\UserInterface; @@ -33,7 +33,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface return $this->casUserProvider->loadUserByIdentifier($identifier); } - public function loadUserByResponse(Response $response): CasUserInterface + public function loadUserByResponse(ResponseInterface $response): CasUserInterface { return new EuLoginUser($this->casUserProvider->loadUserByResponse($response)); } From 968dd624e0d7205622d75ce0413a5a76edbca3ba Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 29 Sep 2022 06:46:01 +0200 Subject: [PATCH 06/10] fix `eraseCredentials` method preventing authentication --- src/Resources/config/services.php | 5 +++++ src/Security/Core/User/EuLoginUser.php | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index e027595..16d41e0 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -31,6 +31,11 @@ ->decorate(CasUserProviderInterface::class) ->arg('$casUserProvider', service('.inner')); + $services + ->set(EuLoginUserProvider::class) + ->decorate(UserProviderInterface::class) + ->arg('$casUserProvider', service('.inner')); + $services ->set(EcasProperties::class) ->decorate(PropertiesInterface::class) diff --git a/src/Security/Core/User/EuLoginUser.php b/src/Security/Core/User/EuLoginUser.php index acb524b..7a4e672 100644 --- a/src/Security/Core/User/EuLoginUser.php +++ b/src/Security/Core/User/EuLoginUser.php @@ -12,7 +12,6 @@ namespace EcPhp\EuLoginBundle\Security\Core\User; use EcPhp\CasBundle\Security\Core\User\CasUserInterface; -use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\UserInterface; use function array_key_exists; @@ -28,7 +27,6 @@ public function __construct(CasUserInterface $user) public function eraseCredentials(): void { - throw new UnsupportedUserException('Unsupported method.'); } public function get(string $key, mixed $default = null): mixed From 7deffba758d2dc233b86ae1651f02a84aef3993c Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 29 Sep 2022 06:49:33 +0200 Subject: [PATCH 07/10] fix `eraseCredentials` method preventing authentication --- src/Resources/config/services.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 16d41e0..40dfdcd 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -17,6 +17,7 @@ use EcPhp\Ecas\EcasProperties; use EcPhp\EuLoginBundle\Cas\SymfonyECas; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; +use Symfony\Component\Security\Core\User\UserProviderInterface; return static function (ContainerConfigurator $container) { $services = $container->services(); From 3d48ec81fd8e2b3f26f5be068b06a525bd4c07f4 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 29 Sep 2022 07:54:18 +0200 Subject: [PATCH 08/10] autofix code styl --- src/Security/Core/User/EuLoginUser.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Security/Core/User/EuLoginUser.php b/src/Security/Core/User/EuLoginUser.php index 7a4e672..a9290c0 100644 --- a/src/Security/Core/User/EuLoginUser.php +++ b/src/Security/Core/User/EuLoginUser.php @@ -181,6 +181,11 @@ public function getOrgId(): ?string return $this->user->getAttribute('orgId'); } + public function getPayload(): array + { + return $this->user->getPayload(); + } + public function getPgt(): ?string { return $this->user->getPgt(); From c563ce3f432e7423eba7a09a2b84761c83ae4822 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 29 Sep 2022 13:59:41 +0200 Subject: [PATCH 09/10] fix: add missing container binding --- src/Resources/config/services.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 40dfdcd..de08621 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -14,7 +14,9 @@ use EcPhp\CasBundle\Cas\SymfonyCasInterface; use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface; use EcPhp\CasLib\Contract\Configuration\PropertiesInterface; +use EcPhp\CasLib\Contract\Response\Factory\ServiceValidateFactory as FactoryServiceValidateFactory; use EcPhp\Ecas\EcasProperties; +use EcPhp\Ecas\Response\Factory\ServiceValidateFactory; use EcPhp\EuLoginBundle\Cas\SymfonyECas; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; use Symfony\Component\Security\Core\User\UserProviderInterface; @@ -46,4 +48,9 @@ ->set(SymfonyECas::class) ->decorate(SymfonyCasInterface::class) ->arg('$cas', service('.inner')); + + $services + ->set(ServiceValidateFactory::class) + ->decorate(FactoryServiceValidateFactory::class) + ->arg('$serviceValidateFactory', service('.inner')); }; From 3dd5ee776ab8833a53a047a3ff08158f7580198e Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 29 Sep 2022 13:59:50 +0200 Subject: [PATCH 10/10] fix: remove `getPayload` method --- src/Security/Core/User/EuLoginUser.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Security/Core/User/EuLoginUser.php b/src/Security/Core/User/EuLoginUser.php index a9290c0..7a4e672 100644 --- a/src/Security/Core/User/EuLoginUser.php +++ b/src/Security/Core/User/EuLoginUser.php @@ -181,11 +181,6 @@ public function getOrgId(): ?string return $this->user->getAttribute('orgId'); } - public function getPayload(): array - { - return $this->user->getPayload(); - } - public function getPgt(): ?string { return $this->user->getPgt();