/** * Handles specific route requirements. * * @param string $pathinfo The path * @param string $name The route name * @param string $route The route * * @return array The first element represents the status, the second contains additional information */ protected function handleRouteRequirements($pathinfo, $name, Route $route) { $pathinfo = File::normalizePath($pathinfo, '/', false); $status = parent::handleRouteRequirements($pathinfo, $name, $route); if (self::REQUIREMENT_MATCH == $status[0] && 0 < count($route->getRequirements('HTTP-'))) { if (null === ($request = $this->getContext()->getRequest())) { return array(self::REQUIREMENT_MISMATCH, null); } $requestMatcher = new RequestMatcher(null, null, null, null, array(), $route->getRequirements('HTTP-')); $status = array($requestMatcher->matches($request) ? self::REQUIREMENT_MATCH : self::REQUIREMENT_MISMATCH, null); } return $status; }
public function createFirewall($name, $config) { $config['firewall_name'] = $name; $listeners = array(); if (null === $this->firewallmap) { return $this; } $requestMatcher = new RequestMatcher(); if (array_key_exists('pattern', $config)) { $requestMatcher->matchPath($config['pattern']); } if (array_key_exists('requirements', $config)) { foreach ($config['requirements'] as $key => $value) { if (0 === strpos($key, 'HTTP-')) { $requestMatcher->matchHeader(substr($key, 5), $value); } } } if (array_key_exists('security', $config) && false === $config['security']) { $this->firewallmap->add($requestMatcher, array(), null); return $this; } $defaultProvider = reset($this->userproviders); if (array_key_exists('provider', $config) && array_key_exists($config['provider'], $this->userproviders)) { $defaultProvider = $this->userproviders[$config['provider']]; } if (array_key_exists('contexts', $this->config)) { $listeners = $this->loadContexts($config); } if (null !== $this->logout_listener && false === $this->logout_listener_added) { $this->application->getContainer()->set('security.logout_listener', $this->logout_listener); if (false === $this->dispatcher->isRestored()) { $this->dispatcher->addListener('frontcontroller.request.logout', array('@security.logout_listener', 'handle')); } $this->logout_listener_added = true; } if (0 == count($listeners)) { throw new SecurityException(sprintf('No authentication listener registered for firewall "%s".', $name)); } $this->firewallmap->add($requestMatcher, $listeners, null); return $this; }