diff --git a/src/Exception/NoAuthTokenFound.php b/src/Exception/NoAuthTokenFound.php index 2997af57e..38ccdfe95 100644 --- a/src/Exception/NoAuthTokenFound.php +++ b/src/Exception/NoAuthTokenFound.php @@ -16,8 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Exception; -use RuntimeException; +use Exception; -final class NoAuthTokenFound extends RuntimeException +final class NoAuthTokenFound extends Exception { } diff --git a/src/Exception/NoRequestException.php b/src/Exception/NoRequestException.php index b30b0f247..f7ae21213 100644 --- a/src/Exception/NoRequestException.php +++ b/src/Exception/NoRequestException.php @@ -16,8 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Exception; -use RuntimeException; +use Exception; -final class NoRequestException extends RuntimeException +final class NoRequestException extends Exception { } diff --git a/src/Exception/NonPublicTranslationException.php b/src/Exception/NonPublicTranslationException.php index 6acd9130c..39213eebd 100644 --- a/src/Exception/NonPublicTranslationException.php +++ b/src/Exception/NonPublicTranslationException.php @@ -16,8 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Exception; -use RuntimeException; +use Exception; -final class NonPublicTranslationException extends RuntimeException +final class NonPublicTranslationException extends Exception { } diff --git a/src/Security/Trait/PublicTranslationTrait.php b/src/Security/Trait/PublicTranslationTrait.php index e35620455..d3c082822 100644 --- a/src/Security/Trait/PublicTranslationTrait.php +++ b/src/Security/Trait/PublicTranslationTrait.php @@ -24,6 +24,9 @@ trait PublicTranslationTrait { private const ARRAY_KEYS_INDEX = 'keys'; + /** + * @throws NonPublicTranslationException + */ private function voteOnTranslation(InputBag $payload): bool { $parameters = $payload->all(); diff --git a/src/Security/Trait/RequestTrait.php b/src/Security/Trait/RequestTrait.php index 03faa44cb..c465c2eae 100644 --- a/src/Security/Trait/RequestTrait.php +++ b/src/Security/Trait/RequestTrait.php @@ -27,6 +27,9 @@ trait RequestTrait private const AUTHORIZATION_HEADER = 'Authorization'; + /** + * @throws NoAuthTokenFound + */ private function getAuthToken(Request $request): string { $authToken = $request->headers->get(self::AUTHORIZATION_HEADER); @@ -37,6 +40,9 @@ private function getAuthToken(Request $request): string return $this->removeBearerPrefix($authToken); } + /** + * @throws NoRequestException + */ private function getCurrentRequest(RequestStack $requestStack): Request { $request = $requestStack->getCurrentRequest(); diff --git a/src/Security/Voter/PublicTokenVoter.php b/src/Security/Voter/PublicTokenVoter.php index 6c050e936..10c80aaf0 100644 --- a/src/Security/Voter/PublicTokenVoter.php +++ b/src/Security/Voter/PublicTokenVoter.php @@ -16,6 +16,9 @@ namespace Pimcore\Bundle\StudioApiBundle\Security\Voter; +use Pimcore\Bundle\StudioApiBundle\Exception\NoAuthTokenFound; +use Pimcore\Bundle\StudioApiBundle\Exception\NonPublicTranslationException; +use Pimcore\Bundle\StudioApiBundle\Exception\NoRequestException; use Pimcore\Bundle\StudioApiBundle\Security\Trait\PublicTranslationTrait; use Pimcore\Bundle\StudioApiBundle\Security\Trait\RequestTrait; use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface; @@ -44,6 +47,11 @@ protected function supports(string $attribute, mixed $subject): bool return $attribute === self::SUPPORTED_ATTRIBUTE && in_array((string)$subject, self::SUPPORTED_SUBJECTS, true); } + /** + * @throws NoRequestException + * @throws NoAuthTokenFound + * @throws NonPublicTranslationException + */ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool { @@ -58,6 +66,9 @@ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInter return $this->voteOnRequest($request, $subject); } + /** + * @throws NonPublicTranslationException + */ private function voteOnRequest(Request $request, string $subject): bool { return match ($subject) { diff --git a/src/Security/Voter/TokenVoter.php b/src/Security/Voter/TokenVoter.php index 9f70f11d8..e92f5c81b 100644 --- a/src/Security/Voter/TokenVoter.php +++ b/src/Security/Voter/TokenVoter.php @@ -16,6 +16,8 @@ namespace Pimcore\Bundle\StudioApiBundle\Security\Voter; +use Pimcore\Bundle\StudioApiBundle\Exception\NoAuthTokenFound; +use Pimcore\Bundle\StudioApiBundle\Exception\NoRequestException; use Pimcore\Bundle\StudioApiBundle\Security\Trait\RequestTrait; use Pimcore\Bundle\StudioApiBundle\Service\SecurityServiceInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -44,7 +46,8 @@ protected function supports(string $attribute, mixed $subject): bool } /** - * @inheritDoc + * @throws NoRequestException + * @throws NoAuthTokenFound */ protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool {