feat: encrypted user passwords
This commit is contained in:
@@ -4,9 +4,9 @@ namespace App\BusProNet\Security;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\BusProNet\Model\CrmAttributes;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Security\Crypt;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -27,6 +27,7 @@ class Authenticator extends AbstractLoginFormAuthenticator implements Authentica
|
||||
public function __construct(
|
||||
private readonly UrlGeneratorInterface $urlGenerator,
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly Crypt $crypt,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
@@ -46,7 +47,7 @@ class Authenticator extends AbstractLoginFormAuthenticator implements Authentica
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->getPersonalData($email, $password);
|
||||
} catch (ApiClientException|ResponseParserException $e) {
|
||||
} catch (ApiClientException $e) {
|
||||
throw new CustomUserMessageAuthenticationException($e->getMessage());
|
||||
}
|
||||
|
||||
@@ -60,7 +61,8 @@ class Authenticator extends AbstractLoginFormAuthenticator implements Authentica
|
||||
new UserBadge($email, function () use ($email, $password, $response, $request) {
|
||||
$crmAttributes = $this->apiClient->getCrmAttributes($email, $password);
|
||||
$roles = $this->collectRoles($crmAttributes);
|
||||
$user = new User($email, $response->personId, $response->addressId, $password, $roles);
|
||||
$encryptedPassword = $this->crypt->encrypt($password);
|
||||
$user = new User($email, $response->personId, $response->addressId, $encryptedPassword, $roles);
|
||||
|
||||
$request->getSession()->set('bpn_user', $user);
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class User implements UserInterface
|
||||
return ['ROLE_USER', ...$this->roles];
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
public function eraseCredentials(): void
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,4 +48,4 @@ class User implements UserInterface
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ namespace App\BusProNet\Security;
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Controller\Traits\CredentialsTrait;
|
||||
use App\Security\Crypt;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
@@ -12,14 +14,19 @@ use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||
|
||||
class UserProvider implements UserProviderInterface
|
||||
{
|
||||
public function __construct(private readonly ApiClient $apiClient, private readonly RequestStack $requestStack)
|
||||
{
|
||||
use CredentialsTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly ApiClient $apiClient,
|
||||
private readonly RequestStack $requestStack,
|
||||
private readonly Crypt $crypt,
|
||||
) {
|
||||
}
|
||||
|
||||
public function refreshUser(UserInterface $user): UserInterface
|
||||
{
|
||||
if (null !== $activeUuser = $this->requestStack->getSession()->get('bpn_user')) {
|
||||
return $activeUuser;
|
||||
if (null !== $activeUser = $this->requestStack->getSession()->get('bpn_user')) {
|
||||
return $activeUser;
|
||||
}
|
||||
|
||||
return $this->loadUserByIdentifier($user->getUserIdentifier());
|
||||
@@ -37,7 +44,9 @@ class UserProvider implements UserProviderInterface
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->apiClient->getPersonalData($activeUser->getEmail(), $activeUser->getPassword());
|
||||
$email = $activeUser->getEmail();
|
||||
$password = $this->crypt->decrypt($activeUser->getPassword());
|
||||
$response = $this->apiClient->getPersonalData($email, $password);
|
||||
} catch (ApiClientException $e) {
|
||||
throw new UserNotFoundException();
|
||||
}
|
||||
@@ -48,4 +57,4 @@ class UserProvider implements UserProviderInterface
|
||||
|
||||
return $activeUser;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user