mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Remove custom Messenger authentication logic (WIP)
Eliminated the `AuthenticationMiddleware`, `AuthenticatedMessengerToken`, and `AuthenticationStamp` classes, along with their service declarations. This cleanup removes unused or unnecessary code, simplifying the project and reducing maintenance overhead.
This commit is contained in:
parent
2c812fc5fe
commit
791f5bb4be
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Messenger\Authentication;
|
|
||||||
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
|
||||||
|
|
||||||
class AuthenticatedMessengerToken extends AbstractToken
|
|
||||||
{
|
|
||||||
public function __construct(UserInterface $user, array $roles = [])
|
|
||||||
{
|
|
||||||
parent::__construct($roles);
|
|
||||||
$this->setUser($user);
|
|
||||||
$this->setAuthenticated(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCredentials(): null
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Messenger\Middleware;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Messenger\Authentication\AuthenticatedMessengerToken;
|
|
||||||
use Chill\MainBundle\Messenger\Stamp\AuthenticationStamp;
|
|
||||||
use Symfony\Component\Messenger\Envelope;
|
|
||||||
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
|
|
||||||
use Symfony\Component\Messenger\Middleware\StackInterface;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
||||||
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
|
||||||
|
|
||||||
final readonly class AuthenticationMiddleware implements MiddlewareInterface
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private TokenStorageInterface $tokenStorage,
|
|
||||||
private UserProviderInterface $userProvider,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function handle(Envelope $envelope, StackInterface $stack): Envelope
|
|
||||||
{
|
|
||||||
dump(__METHOD__);
|
|
||||||
if (null !== $authenticationStamp = $envelope->last(AuthenticationStamp::class)) {
|
|
||||||
return;
|
|
||||||
/** @var AuthenticationStamp $authenticationStamp */
|
|
||||||
dump("authenticate user", $authenticationStamp->getUserId());
|
|
||||||
if (null !== $this->tokenStorage->getToken()) {
|
|
||||||
dump("token already present");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$user = $this->userProvider->loadUserByUsername($authenticationStamp->getUserId());
|
|
||||||
$this->tokenStorage->setToken(new AuthenticatedMessengerToken($user, [...$user->getRoles(), 'IS_AUTHENTICATED_FULLY']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $stack->next()->handle($envelope, $stack);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Chill is a software for social workers
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the LICENSE file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Messenger\Stamp;
|
|
||||||
|
|
||||||
use Symfony\Component\Messenger\Stamp\StampInterface;
|
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stamp which will add a user as authenticated during the message handling.
|
|
||||||
*/
|
|
||||||
final readonly class AuthenticationStamp implements StampInterface
|
|
||||||
{
|
|
||||||
private string $userId;
|
|
||||||
|
|
||||||
public function __construct(UserInterface $user)
|
|
||||||
{
|
|
||||||
$this->userId = $user->getUserIdentifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUserId(): string
|
|
||||||
{
|
|
||||||
return $this->userId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -101,11 +101,6 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
Chill\MainBundle\Messenger\:
|
|
||||||
resource: '../Messenger/'
|
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
|
|
||||||
Chill\MainBundle\Cron\:
|
Chill\MainBundle\Cron\:
|
||||||
resource: '../Cron'
|
resource: '../Cron'
|
||||||
autowire: true
|
autowire: true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user