|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Silverback\ApiComponentBundle\Form\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use Silverback\ApiComponentBundle\Entity\User\User; |
|
6
|
|
|
use App\Security\PasswordManager; |
|
|
|
|
|
|
7
|
|
|
use App\Security\TokenAuthenticator; |
|
|
|
|
|
|
8
|
|
|
use Lexik\Bundle\JWTAuthenticationBundle\Security\Http\Authentication\AuthenticationSuccessHandler; |
|
9
|
|
|
use Silverback\ApiComponentBundle\Entity\Component\Form\Form; |
|
10
|
|
|
use Silverback\ApiComponentBundle\Exception\UnsupportedFormEntityException; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
|
14
|
|
|
|
|
15
|
|
|
class UserHandler implements FormHandlerInterface |
|
16
|
|
|
{ |
|
17
|
|
|
private $authenticationSuccessHandler; |
|
18
|
|
|
private $passwordManager; |
|
19
|
|
|
private $tokenAuthenticator; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct( |
|
22
|
|
|
AuthenticationSuccessHandler $authenticationSuccessHandler, |
|
23
|
|
|
PasswordManager $passwordManager, |
|
24
|
|
|
TokenAuthenticator $tokenAuthenticator |
|
25
|
|
|
) { |
|
26
|
|
|
$this->authenticationSuccessHandler = $authenticationSuccessHandler; |
|
27
|
|
|
$this->passwordManager = $passwordManager; |
|
28
|
|
|
$this->tokenAuthenticator = $tokenAuthenticator; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param Form $form |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
* @param Request $request |
|
35
|
|
|
* @return null|Response |
|
36
|
|
|
* @throws UnsupportedFormEntityException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function success(Form $form, $user, Request $request): ?Response |
|
39
|
|
|
{ |
|
40
|
|
|
$credentials = $this->tokenAuthenticator->getCredentials($request); |
|
41
|
|
|
$appServerTokenUser = $this->tokenAuthenticator->getUser($credentials); |
|
42
|
|
|
if (!$appServerTokenUser) { |
|
43
|
|
|
$exception = new AuthenticationException('This form can only be submitted from the app server.'); |
|
44
|
|
|
return $this->tokenAuthenticator->onAuthenticationFailure($request, $exception); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (!$user instanceof User) { |
|
|
|
|
|
|
48
|
|
|
throw new UnsupportedFormEntityException( |
|
49
|
|
|
sprintf( |
|
50
|
|
|
'`%s` only supports forms that submit the `%s` entity. Received `%s`', |
|
51
|
|
|
self::class, |
|
52
|
|
|
User::class, |
|
53
|
|
|
\is_object($user) ? \get_class($user) : $user |
|
54
|
|
|
) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
$this->passwordManager->persistPlainPassword($user); |
|
58
|
|
|
$user->eraseCredentials(); |
|
59
|
|
|
return $this->authenticationSuccessHandler->handleAuthenticationSuccess($user); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths