public function onKernelRequest(GetResponseEvent $event) { $this->logger->debug('Entity builder listener: catch kernel.request event'); // If this is not a master request, skip handling if (!$event->isMasterRequest()) { $this->logger->debug('Entity builder listener: this is not master request, skip'); return; } // If content already prepared if ($event->hasResponse()) { $this->logger->debug('Entity builder listener: event already has response, skip'); return; } // Getting request $request = $event->getRequest(); // Getting action $apiServerAction = $event->getRequest()->attributes->get('apiAction'); /* @var $apiServerAction ApiServerAction */ // Something wrong if (!$apiServerAction) { $this->logger->error('Request parser listener: request has no apiAction attribute, throwing access denied exception'); throw new AccessDeniedHttpException(); } // Creating request data entity try { $apiEntity = $apiServerAction->getRequestedEntity($request->attributes->get('apiData')); } catch (\Exception $e) { $this->logger->notice(sprintf('Request parser listener: unable to convert apiData to entity ("%s"), apiEntity set tu null', $e->getMessage())); $apiEntity = null; } // Setting request attributes $request->attributes->set('requestData', $apiEntity); // Cleaning request attributes $request->attributes->remove('apiData'); }
/** * Logs master requests on event KernelEvents::REQUEST. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->logRequest($event->getRequest()); }
/** * 请求完成后执行 */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $session = $request->getSession(); // 如果有 OpenID,则放行 if ($session->has('openid')) { return; } // 排除资源文件 if (preg_match("^/(_(profiler|wdt)|css|images|js)/^", $request->getPathInfo())) { return; } // 排除不需要 openid 的 URL $currentRoute = $request->get('_route'); $currentParams = $request->get('_route_params'); if (in_array($currentRoute, $this->ignoreRoute)) { return; } // 跳转到授权页,并把当前页作为参数(授权完成后还要跳转回来) $currentUri = $this->router->generate($currentRoute, $currentParams); $authorizeUrl = $this->router->generate('wechat_authorize', ['continue' => $currentUri]); if (!$request->isXmlHttpRequest()) { return $event->setResponse(new RedirectResponse($authorizeUrl)); } $response = new JsonResponse(['failure' => '401 Unauthorized', 'redirect' => $authorizeUrl]); return $event->setResponse($response); }
/** * Add JSON handler to Whoops if Ajax request * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest() || !$event->getRequest()->isXmlHttpRequest()) { return; } $this->whoops->pushHandler(new JsonResponseHandler()); }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { // Check master request if (!$event->isMasterRequest()) { return; } // Check excluded paths $path = $event->getRequest()->getPathInfo(); if ($this->isExcludedPath($path)) { return; } // Extract token $headerToken = $this->tokenExtractor->extract($event->getRequest()); if (!is_string($headerToken)) { throw new AuthenticationExpiredException('The access token is missing'); } $token = $this->tokenVerificator->parsing($headerToken); // Validate token if (!$this->tokenVerificator->isValid($token)) { throw new AuthenticationExpiredException('The access token is invalid'); } // Store token $this->tokenStorage->setToken($token); // token $operator = $token->getClaim('operatorId'); $event->getRequest()->request->set('operator', $operator); $event->getRequest()->query->set('operator', $operator); }
/** * Resume the session if it has been started previously or debugging is enabled * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->manager->initialize($event->getRequest()); }
/** * The ThemeEngine::requestAttributes MUST be updated based on EACH Request and not only the initial Request. * @param GetResponseEvent $event */ public function setThemeEngineRequestAttributes(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->themeEngine->setRequestAttributes($event->getRequest()); }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } else { } }
/** * Reads the Security Token from the session. * * @param GetResponseEvent $event A GetResponseEvent instance */ public function handle(GetResponseEvent $event) { if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) { $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse')); $this->registered = true; } $request = $event->getRequest(); $session = $request->hasPreviousSession() ? $request->getSession() : null; if (null === $session || null === ($token = $session->get($this->sessionKey))) { $this->tokenStorage->setToken(null); return; } $token = unserialize($token); if (null !== $this->logger) { $this->logger->debug('Read existing security token from the session.', array('key' => $this->sessionKey)); } if ($token instanceof TokenInterface) { $token = $this->refreshUser($token); } elseif (null !== $token) { if (null !== $this->logger) { $this->logger->warning('Expected a security token from the session, got something else.', array('key' => $this->sessionKey, 'received' => $token)); } $token = null; } $this->tokenStorage->setToken($token); }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $routes = $this->router->getRouteCollection(); $route = $routes->get($request->attributes->get('_route')); if (!$route->getOption('requires_license')) { return; } if ('active' != $request->get('lic') && $this->kernel->getEnvironment() == 'prod') { // Checking for whitelisted users try { $user = $this->tokenStorage->getToken()->getUser(); $today = date('Y-m-d'); if ($user instanceof UserInterface) { $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist'); foreach ($whitelist as $allowed) { if ($allowed['client_key'] == $user->getClientKey() && $today <= $allowed['valid_till']) { return; } } } } catch (\Exception $e) { // Do nothing } $url = $this->router->generate('atlassian_connect_unlicensed'); $response = new RedirectResponse($url); $event->setResponse($response); } }
/** * Logs master requests on event KernelEvents::REQUEST * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->logger->info('Received request'); }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->sha = array(); }
/** * Reads the SecurityContext from the session. * * @param GetResponseEvent $event A GetResponseEvent instance */ public function handle(GetResponseEvent $event) { if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) { $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse')); $this->registered = true; } $request = $event->getRequest(); $session = $request->hasPreviousSession() ? $request->getSession() : null; if (null === $session || null === ($token = $session->get('_security_' . $this->contextKey))) { $this->context->setToken(null); return; } $token = unserialize($token); if (null !== $this->logger) { $this->logger->debug('Read SecurityContext from the session'); } if ($token instanceof TokenInterface) { $token = $this->refreshUser($token); } elseif (null !== $token) { if (null !== $this->logger) { $this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token))); } $token = null; } $this->context->setToken($token); }
/** * On Request received check the validity of the webpack cache. * * @param GetResponseEvent $event the response to send to te browser, we don't we only ensure the cache is there. */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->guard->rebuild(); }
public function onRequest(GetResponseEvent $event) { $token = $this->storage->getToken(); $request = $event->getRequest(); $blackList = ['api.server.status', 'api.characters', 'api.character_create', 'template.serverstatus', 'api.character_create.validate', 'api.character_create.finalize', 'api.character.apicredentials', 'template.slidebutton', 'template.slidemenu']; if (!$event->isMasterRequest() || $token === null || in_array('ROLE_SUPER_ADMIN', $this->getRolesArray($token->getRoles())) || in_array($request->attributes->get('_route'), $blackList) || !strstr(explode('::', $request->attributes->get('_controller'))[0], 'AppBundle')) { $this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route'))); return; } if ($request->attributes->get('_controller') === 'AppBundle\\Controller\\Admin\\CharacterController::indexAction' && $this->session->has(self::ACTIVE_API_CHECK)) { $this->session->getFlashBag()->add('danger', 'You must add a character with a valid NO EXPIRY API KEY in order to proceed'); $this->log->debug(sprintf('LISTENER Skipping %s', $request->attributes->get('_route'))); $this->session->remove(self::ACTIVE_API_CHECK); return; } if ($token->isAuthenticated() && ($user = $this->storage->getToken()->getUser()) instanceof User) { $characters = $this->doctrine->getRepository('AppBundle:Character')->findBy(['user' => $user]); $activeKeys = $this->doctrine->getRepository('AppBundle:ApiCredentials')->getActiveKeyForUser($user); if (count($characters) == 0 || count($activeKeys) <= 0) { $this->log->debug(sprintf('LISTENER REDIRECT for %s', $request->attributes->get('_route'))); $response = new RedirectResponse($this->router->generate('characters')); $this->session->set(self::ACTIVE_API_CHECK, time()); $event->setResponse($response); } } }
/** * Triggered on every request. * * See if the time since last active is larger than the maximum idle time that is allowed * * @param GetResponseEvent $event * * @return void */ public function onKernelRequest(GetResponseEvent $event) { // only need to evalute the original request from the browser if (!$event->isMasterRequest()) { return; } // do nothing if user is not logged in if ($this->securityContext->getToken() !== null && !$this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { return; } // do nothing if the post contains a systemKey and systemSecret if ($event->getRequest()->request->has('systemKey') && $event->getRequest()->request->has('systemSecret')) { return; } // assume an infinite session time is allowed if the parameter is <= 0 or not set, by doing nothing if ($this->maxIdleTime <= 0 || $this->maxIdleTime === null) { return; } // just incase a session hasn't started, otherwise it simply returns true $this->session->start(); // have we been inactive for longer than the allowed time limit..? $timeSinceActive = time() - $this->session->getMetadataBag()->getLastUsed(); if ($timeSinceActive > $this->maxIdleTime) { // log the user out $this->securityContext->setToken(null); // issue a message for the login page $this->session->getFlashBag()->set('session_timeout', 'Your session has expired due to inactivity.'); // redirect to login $event->setResponse(new RedirectResponse($this->router->generate('barbon_hostedapi_app_index_index'))); } }
public function onKernelRequest(GetResponseEvent $event) { if ($event->isMasterRequest()) { $this->serverData = $event->getRequest()->server->all(); $this->serverData['REMOTE_ADDR'] = $event->getRequest()->getClientIp(); } }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $this->factory->setRequest($event->getRequest()); return true; }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if (!$event->isMasterRequest() || '/' !== $request->getPathInfo()) { return; } $this->twig->addGlobal('random_quote_event', $this->quoteRepository->findRandom()); }
public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $request->attributes->set('_locale', $request->getPreferredLanguage(['fr', 'en'])); }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $route = $this->getRoute($event->getRequest()); $this->logger->info('PROCESS START', array($route)); }
public function onKernelRequest(GetResponseEvent $event) { if ($event->isMasterRequest() && $event->getRequest()->attributes->has('page_id')) { // Notify listeners (eg. RoutePageListener) about Page associated to requested route $this->eventDispatcher->dispatch('swp.context.page', new GenericEvent(null, ['pageId' => $event->getRequest()->attributes->get('page_id'), 'route_name' => $event->getRequest()->attributes->get('_route')])); } return; }
public function onKernelRequest(\Symfony\Component\HttpKernel\Event\GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $request->setLocale($request->getPreferredLanguage(['en', 'fr'])); }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); if ($event->isMasterRequest() && $this->protectedRequest($request)) { $providedToken = $this->extractProvidedTokenFrom($request); $this->throwExceptionIfInvalidToken($providedToken); } }
public function onEarlyKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } // reset flushed state on each request, since kernel may not be rebooted $this->sub->flushed = false; $this->sub->inRequest = true; }
/** * Set the cookie_path from the current request's path * * @param GetResponseEvent $event */ public function onRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $path = $request->getBaseUrl() . $request->getPathInfo(); $this->options->set('cookie_path', $path); }
public function onKernelRequest(GetResponseEvent $event) { if ($event->isMasterRequest()) { $route = $event->getRequest()->attributes->get('_route'); if ($route != 'ad_perfil_menu') { $this->menuManager->setMenuActualSinceRoute($route); } } }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $format = $request->getFormat($request->headers->get('Accept')); $request->setRequestFormat($format); }
public function onKernelRequest(GetResponseEvent $event) { $this->request = $event->getRequest(); $this->session = $event->getRequest()->getSession(); if ($event->isMasterRequest()) { $this->journalService->setSelectedJournal(); $this->loadClientUsers(); } }
/** * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $span = $this->httpFoundationSpanFactory->fromIncomingRequest($event->getRequest()); $this->stack->push($span); $this->tracer->trace([$span]); }