Skip to content

Commit

Permalink
Version 3 - Use upcoming version of ecas.
Browse files Browse the repository at this point in the history
Integrate latest changes from ecphp/ecas.
  • Loading branch information
drupol committed Aug 1, 2022
1 parent fa5b2dc commit fdcde3f
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 35 deletions.
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@
"sso"
],
"require": {
"php": ">= 7.2.5",
"php": ">= 7.4",
"ext-json": "*",
"ext-simplexml": "*",
"ecphp/cas-bundle": "2.2.* || ^2.3",
"ecphp/ecas": "2.1.*",
"symfony/framework-bundle": "^5.1"
"ecphp/cas-bundle": "dev-refactor/symfony-gte-54",
"ecphp/ecas": "dev-refactor/version-3",
"symfony/framework-bundle": "^5.4"
},
"require-dev": {
"ext-xdebug": "*",
"ecphp/php-conventions": "^1",
"friends-of-phpspec/phpspec-code-coverage": "^6.1.0",
"friends-of-phpspec/phpspec-code-coverage": "^6",
"infection/infection": "^0.24.0",
"infection/phpspec-adapter": "^0.1.2",
"phpspec/phpspec": "^7",
"symfony/security-core": "^5.3"
"symfony/http-client": "^6.0",
"symfony/security-core": "^5.4",
"nyholm/psr7": "^1.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
"psr-4": {
"EcPhp\\EuLoginBundle\\": "src/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@
namespace spec\EcPhp\EuLoginBundle\Security\Core\User;

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 loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response;
use PhpSpec\ObjectBehavior;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
Expand All @@ -40,7 +46,19 @@ public function it_can_load_a_user_from_a_response(): void
// TestBody1
$response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody1());

$user = $this->loadUserByResponse($response);
$psr17f = new Psr17Factory;
$psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f);
$responseBuilder = new CasResponseBuilder(
new AuthenticationFailureFactory,
new ProxyFactory,
new ProxyFailureFactory,
new ServiceValidateFactory(new FactoryServiceValidateFactory, $psr17)
);

$user = $this
->loadUserByResponse(
$responseBuilder->fromResponse($response)
);

$user
->getAttributes()
Expand Down Expand Up @@ -143,9 +161,16 @@ 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(
200,
['content-type' => 'application/xml'],
$this->getTestBody2()
);

$user = $this->loadUserByResponse($response);
$user = $this
->loadUserByResponse(
$responseBuilder->fromResponse($response)
);

$user
->getAttributes()
Expand Down Expand Up @@ -257,7 +282,7 @@ public function it_is_initializable()
public function let()
{
$this
->beConstructedWith(new CasUserProvider(new EcasIntrospector(new Introspector())));
->beConstructedWith(new CasUserProvider());
}

private function getTestBody1()
Expand Down
39 changes: 35 additions & 4 deletions spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@

use EcPhp\CasBundle\Security\Core\User\CasUser;
use EcPhp\CasBundle\Security\Core\User\CasUserInterface;
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 as FactoryServiceValidateFactory;
use EcPhp\Ecas\Response\EcasResponseBuilder;
use EcPhp\Ecas\Response\Factory\ServiceValidateFactory;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser;
use loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Response;
use PhpSpec\ObjectBehavior;

Expand Down Expand Up @@ -43,8 +51,18 @@ public function it_can_get_groups_when_no_groups_are_available()
</cas:serviceResponse>
EOF;

$psr17f = new Psr17Factory;
$psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f);
$response = new Response(200, ['Content-Type' => 'application/xml'], $body);
$data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess'];
$responseBuilder = new CasResponseBuilder(
new AuthenticationFailureFactory,
new ProxyFactory,
new ProxyFailureFactory,
new ServiceValidateFactory(new FactoryServiceValidateFactory, $psr17)
);
$data = $responseBuilder
->fromResponse($response)
->toArray()['serviceResponse']['authenticationSuccess'];

$casUser = new CasUser($data);

Expand Down Expand Up @@ -296,10 +314,22 @@ public function let()
</cas:serviceResponse>
EOF;

$psr17f = new Psr17Factory;
$psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f);
$response = new Response(200, ['Content-Type' => 'application/xml'], $body);
$data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess'];
$responseBuilder = new CasResponseBuilder(
new AuthenticationFailureFactory,
new ProxyFactory,
new ProxyFailureFactory,
new ServiceValidateFactory(new FactoryServiceValidateFactory, $psr17)
);

$this->beConstructedWith(new CasUser($data));
$data = $responseBuilder
->fromResponse($response)
->getCredentials();

$this
->beConstructedWith(new CasUser($data));
}

private function getAttributesData(): array
Expand Down Expand Up @@ -378,6 +408,7 @@ private function getAttributesData(): array
'proxyGrantingProtocol' => 'proxyGrantingProtocol',
'timeZone' => 'timeZone',
'userManager' => 'userManager',
'foo' => 'bar',
];
}
}
5 changes: 1 addition & 4 deletions src/DependencyInjection/EuLoginExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Class EuLoginExtension.
*/
class EuLoginExtension extends Extension
final class EuLoginExtension extends Extension
{
/**
* @param array<string> $configs
Expand Down
5 changes: 1 addition & 4 deletions src/EuLoginBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Class EuLoginBundle.
*/
class EuLoginBundle extends Bundle
final class EuLoginBundle extends Bundle
{
}
23 changes: 13 additions & 10 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use EcPhp\CasLib\Contract\CasInterface;
use EcPhp\CasLib\Contract\Configuration\PropertiesInterface;
use EcPhp\CasLib\Contract\Response\CasResponseBuilderInterface;
use EcPhp\Ecas\Ecas;
use EcPhp\Ecas\EcasProperties;
use EcPhp\Ecas\Introspection\EcasIntrospector;
use EcPhp\Ecas\Response\EcasResponseBuilder;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider;

return static function (ContainerConfigurator $container) {
Expand All @@ -25,21 +28,21 @@
->autowire(true);

$services
->set('ecas.introspector', EcasIntrospector::class)
->decorate('cas.introspector')
->arg('$introspector', service('ecas.introspector.inner'));
->set(EcasResponseBuilder::class)
->decorate(CasResponseBuilderInterface::class)
->arg('$casResponseBuilder', service('.inner'));

$services
->set('eulogin.userprovider', EuLoginUserProvider::class)
->arg('$casUserProvider', service('cas.userprovider'));

$services
->set('ecas.configuration', EcasProperties::class)
->decorate('cas.configuration')
->arg('$casProperties', service('ecas.configuration.inner'));
->set(EcasProperties::class)
->decorate(PropertiesInterface::class)
->arg('$casProperties', service('.inner'));

$services
->set('ecas', Ecas::class)
->decorate('cas')
->arg('$cas', service('ecas.inner'));
->set(Ecas::class)
->decorate(CasInterface::class)
->arg('$cas', service('.inner'));
};
3 changes: 2 additions & 1 deletion src/Security/Core/User/EuLoginUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ public function getUsername()
'ecphp/eu-login-bundle',
'2.3.8',
'The method "%s::getUsername()" is deprecated, use %s::getUserIdentifier() instead.',
EuLoginUser::class,
EuLoginUser::class
);

return $this->user->getUsername();
return $this->getUserIdentifier();
}

public function isEqualTo(UserInterface $user)
Expand Down
5 changes: 5 additions & 0 deletions src/Security/Core/User/EuLoginUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public function __construct(CasUserProviderInterface $casUserProvider)
$this->casUserProvider = $casUserProvider;
}

public function loadUserByIdentifier($identifier)
{
throw new UnsupportedUserException('Unsupported operation.');
}

public function loadUserByResponse(ResponseInterface $response): CasUserInterface
{
return new EuLoginUser($this->casUserProvider->loadUserByResponse($response));
Expand Down

0 comments on commit fdcde3f

Please sign in to comment.