<commit_before><?php

namespace Oro\Bundle\SecurityBundle\EventListener;

use Doctrine\Common\Util\ClassUtils;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Oro\Bundle\SecurityBundle\SecurityFacade;

class ControllerListener
{
    /**
     * @var SecurityFacade
     */
    private $securityFacade;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * Constructor
     *
     * @param SecurityFacade  $securityFacade
     * @param LoggerInterface $logger
     */
    public function __construct(
        SecurityFacade $securityFacade,
        LoggerInterface $logger
    ) {
        $this->securityFacade = $securityFacade;
        $this->logger = $logger;
    }

    /**
     * Checks if an access to a controller action is granted or not.
     *
     * This method is executed just before any controller action.
     *
     * @param  FilterControllerEvent $event
     * @throws AccessDeniedException
     */
    public function onKernelController(FilterControllerEvent $event)
    {
        $controller = $event->getController();
        /*
         * $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen.
         * If it is a class, it comes in array format
         */
        if (is_array($controller)) {
            list($object, $method) = $controller;
            $className = ClassUtils::getClass($object);

            $this->logger->debug(
                sprintf(
                    'Invoked controller "%s::%s". (%s)',
                    $className,
                    $method,
                    $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST ? 'MASTER_REQUEST' : 'SUB_REQUEST'
                )
            );

            if (!$this->securityFacade->isClassMethodGranted($className, $method)) {
                if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
                    throw new AccessDeniedException('Access denied.');
                }
            }
        }
    }
}<commit_msg>BAP-1871: Upgrade Symfony to 2.3.6 - "Access denied" exception improved with class::method description<commit_after><?php

namespace Oro\Bundle\SecurityBundle\EventListener;

use Doctrine\Common\Util\ClassUtils;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Oro\Bundle\SecurityBundle\SecurityFacade;

class ControllerListener
{
    /**
     * @var SecurityFacade
     */
    private $securityFacade;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * Constructor
     *
     * @param SecurityFacade  $securityFacade
     * @param LoggerInterface $logger
     */
    public function __construct(
        SecurityFacade $securityFacade,
        LoggerInterface $logger
    ) {
        $this->securityFacade = $securityFacade;
        $this->logger = $logger;
    }

    /**
     * Checks if an access to a controller action is granted or not.
     *
     * This method is executed just before any controller action.
     *
     * @param  FilterControllerEvent $event
     * @throws AccessDeniedException
     */
    public function onKernelController(FilterControllerEvent $event)
    {
        $controller = $event->getController();
        /*
         * $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen.
         * If it is a class, it comes in array format
         */
        if (is_array($controller)) {
            list($object, $method) = $controller;
            $className = ClassUtils::getClass($object);

            $this->logger->debug(
                sprintf(
                    'Invoked controller "%s::%s". (%s)',
                    $className,
                    $method,
                    $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST ? 'MASTER_REQUEST' : 'SUB_REQUEST'
                )
            );

            if (!$this->securityFacade->isClassMethodGranted($className, $method)) {
                if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
                    throw new AccessDeniedException(sprintf('Access denied to %s::%s.', $className, $method));
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.10416207883726052, 'fraction_numerical': 0.001981942303457388, 'mean_word_length': 2.2235628105039034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3522929', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1178, 'n_words': 283}