for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types = 1);
/*
* This file is part of the KleijnWeb\SwaggerBundle package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace KleijnWeb\SwaggerBundle\Security;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
/**
* @author John Kleijn <[email protected]>
class RequestAuthorizationListener implements ListenerInterface
{
const ATTRIBUTE = 'swagger.request';
* @var AuthorizationCheckerInterface
private $authorizationChecker;
* @param AuthorizationCheckerInterface $authorizationChecker
public function __construct(AuthorizationCheckerInterface $authorizationChecker)
$this->authorizationChecker = $authorizationChecker;
}
* This interface must be implemented by firewall listeners.
* @param GetResponseEvent $event
public function handle(GetResponseEvent $event)
if (!$event->isMasterRequest()) {
return;
if (!$this->authorizationChecker->isGranted(self::ATTRIBUTE, $event->getRequest())) {
throw new AccessDeniedException();