diff --git a/src/Security/Trait/RequestTrait.php b/src/Security/Trait/RequestTrait.php index c465c2eae..a8ec31ec3 100644 --- a/src/Security/Trait/RequestTrait.php +++ b/src/Security/Trait/RequestTrait.php @@ -46,6 +46,7 @@ private function getAuthToken(Request $request): string private function getCurrentRequest(RequestStack $requestStack): Request { $request = $requestStack->getCurrentRequest(); + if(!$request) { throw new NoRequestException('No request found'); } diff --git a/src/Security/Voter/PublicTokenVoter.php b/src/Security/Voter/PublicTokenVoter.php index 10c80aaf0..06474f4d3 100644 --- a/src/Security/Voter/PublicTokenVoter.php +++ b/src/Security/Voter/PublicTokenVoter.php @@ -49,7 +49,6 @@ protected function supports(string $attribute, mixed $subject): bool /** * @throws NoRequestException - * @throws NoAuthTokenFound * @throws NonPublicTranslationException */ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool @@ -57,10 +56,13 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter $request = $this->getCurrentRequest($this->requestStack); - $authToken = $this->getAuthToken($request); - - if ($this->securityService->checkAuthToken($authToken)) { - return true; + try { + $authToken = $this->getAuthToken($request); + if ($this->securityService->checkAuthToken($authToken)) { + return true; + } + } catch (NoAuthTokenFound) { + return $this->voteOnRequest($request, $subject); } return $this->voteOnRequest($request, $subject);