<?php 

namespace NPS\Auth;

use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
 * Access denied handler
 * @author Lukas Korinek
 */
class AccessDeniedHandler implements AccessDeniedHandlerInterface
{
    /**
     * @inheritdoc
     */
    public function handle(Request $request, AccessDeniedException $exception)
    {
        return new JsonResponse([
            'message' => $exception->getMessage(),
            'subject' => $exception->getSubject(),
            'debug' => isset($GLOBALS['debug']) ? $GLOBALS['debug'] : []
        ], 401);
    }
}

