Skip to content

Commit

Permalink
fix: restore the use of a UserProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 15, 2022
1 parent 44fb8d2 commit b6b5841
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use EcPhp\CasBundle\Controller\ProxyCallback;
use EcPhp\CasBundle\Security\CasAuthenticator;
use EcPhp\CasBundle\Security\Core\User\CasUserProvider;
use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface;
use EcPhp\CasLib\Cas;
use EcPhp\CasLib\CasInterface;
use EcPhp\CasLib\Configuration\PropertiesInterface;
Expand All @@ -44,7 +45,7 @@
$services->alias(PropertiesInterface::class, 'cas.configuration');

$services->set('cas.userprovider', CasUserProvider::class);
$services->alias(CasUserProvider::class, 'cas.userprovider');
$services->alias(CasUserProviderInterface::class, 'cas.userprovider');

$services->set('cas.authenticator', CasAuthenticator::class);
$services->alias(CasAuthenticator::class, 'cas.authenticator');
Expand Down
10 changes: 7 additions & 3 deletions src/Security/CasAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace EcPhp\CasBundle\Security;

use EcPhp\CasBundle\Security\Core\User\CasUser;
use EcPhp\CasBundle\Security\Core\User\CasUserProviderInterface;
use EcPhp\CasLib\CasInterface;
use EcPhp\CasLib\Introspection\Contract\ServiceValidate;
use EcPhp\CasLib\Utils\Uri;
Expand All @@ -33,14 +33,18 @@ final class CasAuthenticator extends AbstractAuthenticator
{
private CasInterface $cas;

private CasUserProviderInterface $casUserProvider;

private HttpMessageFactoryInterface $httpMessageFactory;

public function __construct(
CasInterface $cas,
HttpMessageFactoryInterface $httpMessageFactory
HttpMessageFactoryInterface $httpMessageFactory,
CasUserProviderInterface $casUserProvider
) {
$this->cas = $cas;
$this->httpMessageFactory = $httpMessageFactory;
$this->casUserProvider = $casUserProvider;
}

public function authenticate(Request $request): Passport
Expand Down Expand Up @@ -71,7 +75,7 @@ public function authenticate(Request $request): Passport
return new SelfValidatingPassport(
new UserBadge(
$payload['user'],
static fn (string $identifier): UserInterface => new CasUser($payload)
fn (string $identifier): UserInterface => $this->casUserProvider->loadUserByResponse($response)
)
);
}
Expand Down

0 comments on commit b6b5841

Please sign in to comment.