@param Request $request

@throws AccessDeniedException
@throws NotFoundHttpException

@return Response
178912
public function composeAction(Request $request)
    {
        $admin = $this->getAdmin();

        $admin->checkAccess('compose');
        if (false === $this->get('sonata.dashboard.admin.block')->isGranted('LIST')) {
            throw $this->createAccessDeniedException();
        }

        $id = $request->get($admin->getIdParameter());
        $dashboard = $admin->getObject($id);
        if (!$dashboard) {
            throw $this->createNotFoundException(sprintf('unable to find the dashboard with id : %s', $id));
        }

        $containers = [];

        // separate containers.
        /** @var array $blocks */
        $blocks = $dashboard->getBlocks();

        foreach ($blocks as $block) {
            /** @var Block $block */
            $blockCode = $block->getSetting('code');
            if (null === $block->getParent()) {
                $containers[$blockCode]['block'] = $block;
            }
        }

        return $this->renderWithExtraParams($template = $admin->getTemplate('compose'), [
            'object' => $dashboard,
            'action' => 'edit',
            'containers' => $containers,
            'csrfTokens' => [
                'remove' => $this->getCsrfToken('sonata.delete'),
            ],
        ]);
    }
1152092
public function apiAction(Request $request)
    {
        if ($request->isXmlHttpRequest() or $request->headers->get('Content-Type') =='application/json') {
            $pathInfo = $request->getPathInfo();
            if(!$this->getApiRequestAllow()->isAllow($pathInfo)){
                throw new NotFoundHttpException('No route allow for " '.$request->getMethod().' '.$pathInfo.'"');
            }
            $query_string = null;
            if ($request->server->get('QUERY_STRING')){
                $query_string = '?' .$request->server->get('QUERY_STRING');
            }

            $url_api = $pathInfo . $query_string;

            /*
             * Only is configurable the first folder
             * internalapi/users/username-available
             * is changed to api/users/username-available
             */
            $array = explode("/", $url_api);
            unset($array[1]);
            $text = implode("/", $array);

            $url_api = "/api".$text;

            $apiUri = trim($url_api,'/');
            try{
                return $this->container->get('antwebes_chateaclient_bundle.http.api_client')->sendRequest('GET',$apiUri);
            }catch (ClientErrorResponseException $e){
                $headersGuzzle = $e->getResponse()->getHeaders()->toArray();
                $headersSymfony = array();
                foreach($headersGuzzle as $key=>$value){
//this header is not suporter in symfony
                    if($key != 'Transfer-Encoding' && $value !== 'chunked'){
                        $headersSymfony[$key] = $value[0];
                    }
                }
                return new Response($e->getResponse()->getBody(true),
                    $e->getResponse()->getStatusCode(),
                    $headersSymfony
                );
            }
        }else{
            throw new NotFoundHttpException();
        }
    }
1139400
public function handle($request, Closure $next, ...$requestedScopes)
    {
        if (! $this->token->exists()) {
            return $next($request);
        }

        $providedScopes = $this->token->scopes;

        // If any of the requested scopes were not provided, throw an exception.
        $missingScopes = array_diff($requestedScopes, $providedScopes);
        if (count($missingScopes)) {
            $message = 'Requires a token with the following scopes: '.implode(', ', $missingScopes);
            throw new AccessDeniedHttpException($message);
        }

        return $next($request);
    }
66680
public function postRequestAsync( Request $request ) {
		$promise = $this->getClient()->requestAsync(
			'POST',
			$this->apiUrl,
			$this->getClientRequestOptions( $request, $this->getPostRequestEncoding( $request ) )
		);

		return $promise->then( function ( ResponseInterface $response ) {
			return call_user_func( [ $this, 'decodeResponse' ], $response );
		} );
	}
464439
public function send(Request $request)
    {
        $response     = new PutSchemaResponse();
        $httpRequest  = $this->createHttpRequest($request);

        $this->client->send($httpRequest);

        return $response;
    }
35890
public function switchAction(Request $request)
    {
        $theme = $request->get('theme');

        if (!in_array($theme, $this->themes)) {
            throw new NotFoundHttpException(sprintf('The theme "%s" does not exist', $theme));
        }

        $this->activeTheme->setName($theme);

        $url = $request->headers->get('Referer', '/');
        $response = new RedirectResponse($url);

        if (!empty($this->cookieOptions)) {
            $cookie = new Cookie(
                $this->cookieOptions['name'],
                $theme,
                time() + $this->cookieOptions['lifetime'],
                $this->cookieOptions['path'],
                $this->cookieOptions['domain'],
                (bool) $this->cookieOptions['secure'],
                (bool) $this->cookieOptions['http_only']
            );

            $response->headers->setCookie($cookie);
        }

        return $response;
    }
504834
public function saveAction(Request $request, $id = null)
    {
        // check access
        if (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            throw $this->createAccessDeniedException();
        }

        // create command
        if (empty($id)) {
            // check permission
            if (!$this->isGranted('ROLE_USER_MANAGER')) {
                throw new AccessDeniedHttpException('Not allowed to insert user');
            }
            // create user instance
            $user = new User();
            // create command
            $command = new CreateUserCommand($user);
        } else {
            // find user
            $user = $this->getDoctrine()->getRepository('UserBundle:User')->find($id);
            if (empty($user)) {
                throw new NotFoundHttpException('User not found');
            }
            // check permissions
            if (!$this->isGranted(UserVoter::PERMISSION_EDIT, $user)) {
                throw new AccessDeniedHttpException('Not allowed to update user');
            }
            // create command
            $command = new UpdateUserCommand($user);
        }

        // set user params to handle
        $email = $request->get('email');
        if ($email) {
            $command->setEmail($email);
        }

        $password = $request->get('password');
        if ($password) {
            $command->setPassword($password);
        }

        $name = $request->get('name');
        if ($name) {
            $command->setName($name);
        }

        $roles = $request->get('roles');
        if (is_array($roles)) {
            $command->setRoles($roles);
        }

        $groups = $request->get('groups');
        if (is_array($groups)) {
            $command->setGroups($request->get('groups'));
        }

        $attributeValues = $request->get('attributeValues');
        if ($attributeValues) {
            $command->setAttributeValues($request->get('attributeValues'));
        }

        // handle command
        try {
            $this->get('user.command_bus')->handle($command);
        } catch (InvalidCommandException $e) {
            return new JsonResponse(
                [
                    'validation' => $this
                        ->get('user.validation_errors_converter')
                        ->constraintViolationListToArray($e->getConstraintViolationList())
                ],
                JsonResponse::HTTP_BAD_REQUEST
            );
        } catch(\Exception $e) {
            return new JsonResponse(
                [
                    'message'       => $e->getMessage(),
                ],
                JsonResponse::HTTP_INTERNAL_SERVER_ERROR
            );
        }

        // show success response
        return new JsonResponse([
            'id' => $user->getId(),
        ]);
    }
882230
public function httpPost(Request $request) : Response
    {
        $response = new Response();
        $response->headers->set('Content-Type', 'application/json');

        $response->setContent(
            $this->sdkEndpoint->index(
                $request->getContent()
            )
        );

        return $response;
    }
169800
public function callback(Request $request)
    {
        if ($request->has('error')) {
            switch ($request->get('error')) {
                case 'access_denied':
                    abort(401);
                    break;
                case 'temporarily_unavailable':
                    abort(503);
                    break;
                case 'invalid_request':
                case 'unauthorized_client':
                case 'unsupported_response_type':
                case 'invalid_scope':
                case 'server_error':
                default:
                    abort($request->server->get('REDIRECT_STATUS', 500));
                    break;
            }
        }

        $code = $request->get('code');
        $http = new Client();

        try {
            $response = $http->post(config('openid.server') . '/oauth/token', [
                'form_params' => [
                    'grant_type'    => 'authorization_code',
                    'client_id'     => config('openid.client.id'),
                    'client_secret' => config('openid.client.secret'),
                    'redirect_uri'  => route('openid.callback'),
                    'code'          => $code,
                ],
            ]);

            $this->checkError($response);
            $response = json_decode($response->getBody());

            session([
                'openid_token'  => $response->id_token,
                'access_token'  => $response->access_token,
                'refresh_token' => $response->refresh_token,
                'expires_at'    => Carbon::now()->addSeconds($response->expires_in),
            ]);
        } catch (\Exception $exception) {
            if ($exception instanceof ServerException || $exception instanceof ClientException) {
                $this->checkError($exception->getResponse());
            }

            abort($exception->getCode() !== 0 ? $exception->getCode() : 500);
        }

        return redirect()->intended();
    }
926838
public function addAction(Request $request): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('state', 'administrate'));
        $defaultLanguageCode = reset($this->languages);

        $form = $this->formFactory->createObjectStateGroup(
            new ObjectStateGroupCreateData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form,
                function (ObjectStateGroupCreateData $data) use ($defaultLanguageCode) {
                    $createStruct = $this->objectStateService->newObjectStateGroupCreateStruct(
                        $data->getIdentifier()
                    );
                    $createStruct->defaultLanguageCode = $defaultLanguageCode;
                    $createStruct->names = [$defaultLanguageCode => $data->getName()];
                    $group = $this->objectStateService->createObjectStateGroup($createStruct);

                    $this->notificationHandler->success(
                        $this->translator->trans(
                            /** @Desc("Object state group '%name%' created.") */
                            'object_state_group.create.success',
                            ['%name%' => $data->getName()],
                            'object_state'
                        )
                    );

                    return $this->redirectToRoute('ezplatform.object_state.group.view', [
                        'objectStateGroupId' => $group->id,
                    ]);
                });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/object_state_group/add.html.twig', [
            'form' => $form->createView(),
        ]);
    }
1028569
public function createFromRequest(Request $request)
    {
        $notFound = new $this->class(
            $request->getPathInfo(),
            $request->getUri(),
            $request->server->get('HTTP_REFERER')
        );

        $this->om->persist($notFound);
        $this->om->flush();

        return $notFound;
    }
901276
public function treeListAction(Request $request)
    {
        if (!$this->getMenuAccess()->canAccessMenuAdmin($this->getCurrentUser())) {
            throw $this->createAccessDeniedException();
        }

        return $this->renderPage('ucms_tree.list_all', $request);
    }
229320
public function auth($request)
    {
        if (Str::startsWith($request->channel_name, ['private-', 'presence-']) &&
            ! $request->user()) {
            throw new AccessDeniedHttpException;
        }

        $channelName = Str::startsWith($request->channel_name, 'private-')
                            ? Str::replaceFirst('private-', '', $request->channel_name)
                            : Str::replaceFirst('presence-', '', $request->channel_name);

        return parent::verifyUserCanAccessChannel(
            $request, $channelName
        );
    }
816523
protected function accessDeniedException(Request $request, Response $response, $message = 'Access denied.')
    {
        return new AccessDeniedException($request, $response, $message);
    }
955740
public function blockIllegalRequests(ActionRequest $request)
    {
        $filterMatched = array_reduce($this->filters, function (bool $filterMatched, RequestFilter $filter) use ($request) {
            return ($filter->filterRequest($request) ? true : $filterMatched);
        }, false);

        if ($this->rejectAll && !$filterMatched) {
            throw new AccessDeniedException('The request was blocked, because no request filter explicitly allowed it.', 1216923741);
        }
    }
162456
public function apply(Request $request, ParamConverter $configuration)
    {
        if (null === $parameter = $configuration->getName()) {
            throw new InvalidConfigurationException(InvalidConfigurationException::MISSING_NAME);
        }

        $token = $this->tokenStorage->getToken();

        if ($token && ($user = $token->getUser()) instanceof User) {
            $request->attributes->set($parameter, $user);

            return true;
        }

        throw new AccessDeniedHttpException();
    }
363623
public function ajaxControllerAction(Request $request)
    {
        $operation = $request->request->get('operation') ? $request->request->get('operation') : $request->query->get(
            'operation'
        );

        if (!$operation) {
            throw new NotFoundHttpException();
        }

        return new JsonResponse($this->$operation());
    }