/** * @param \Symfony\Component\HttpFoundation\Request $request * @throws \InvalidArgumentException if cannot manage the Request * @return \Symfony\Component\HttpFoundation\Response|SamlSpInfo */ public function manage(Request $request) { if (false == $this->supports($request)) { throw new \InvalidArgumentException('Unsupported request'); } $serviceInfo = $this->serviceInfoCollection->findByAS($request->query->get('as')); if (!$serviceInfo) { return new RedirectResponse($this->httpUtils->generateUri($request, $request->attributes->get('discovery_path'))); } $serviceInfo->getSpProvider()->setRequest($request); $spED = $serviceInfo->getSpProvider()->getEntityDescriptor(); $idpED = $serviceInfo->getIdpProvider()->getEntityDescriptor(); $spMeta = $serviceInfo->getSpMetaProvider()->getSpMeta(); $builder = new AuthnRequestBuilder($spED, $idpED, $spMeta); $message = $builder->build(); if ($serviceInfo->getSpSigningProvider()->isEnabled()) { $message->sign($serviceInfo->getSpSigningProvider()->getCertificate(), $serviceInfo->getSpSigningProvider()->getPrivateKey()); } $binding = $this->bindingManager->instantiate($spMeta->getAuthnRequestBinding()); $bindingResponse = $binding->send($message); if ($bindingResponse instanceof \AerialShip\LightSaml\Binding\RedirectResponse) { $result = new RedirectResponse($bindingResponse->getDestination()); } else { if ($bindingResponse instanceof \AerialShip\LightSaml\Binding\PostResponse) { $result = new Response($bindingResponse->render()); } else { throw new \RuntimeException('Unrecognized binding response ' . get_class($bindingResponse)); } } $state = new RequestState(); $state->setId($message->getID()); $state->setDestination($serviceInfo->getIdpProvider()->getEntityDescriptor()->getEntityID()); $this->requestStore->set($state); return $result; }
protected function getPath(Request $request) { $type = $request->query->get('type'); switch ($type) { case 'metadata': $path = $request->attributes->get('metadata_path'); break; case 'logout': $path = $request->attributes->get('logout_path'); break; default: $path = $request->attributes->get('login_path'); } $path = $this->httpUtils->generateUri($request, $path); return $path; }
/** * @param Request $request * @param string $name * * @return string */ public function getLoginUrl(Request $request, $name) { // Just to check that this resource owner exists $this->getResourceOwner($name); $request->attributes->set('service', $name); return $this->httpUtils->generateUri($request, 'hwi_oauth_service_redirect'); }
public function generateUri($request, $path) { if ($this->isRouteName($path)) { // Remove siteaccess attribute to avoid triggering reverse siteaccess lookup during link generation. $request->attributes->remove('siteaccess'); } return parent::generateUri($request, $this->analyzeLink($path)); }
/** * Builds the target URL according to the defined options. * * @param Request $request * * @return string */ protected function determineTargetUrl(Request $request) { if ($this->options['always_use_default_target_path']) { return $this->options['default_target_path']; } if ($targetUrl = $request->get($this->options['target_path_parameter'], null, true)) { return $targetUrl; } if (null !== $this->providerKey && ($targetUrl = $request->getSession()->get('_security.' . $this->providerKey . '.target_path'))) { $request->getSession()->remove('_security.' . $this->providerKey . '.target_path'); return $targetUrl; } if ($this->options['use_referer'] && ($targetUrl = $request->headers->get('Referer')) && $targetUrl !== $this->httpUtils->generateUri($request, $this->options['login_path'])) { return $targetUrl; } return $this->options['default_target_path']; }
/** * @param Request $request * @param string $name * * @return string */ public function getLoginUrl(Request $request, $name, $url) { // Just to check that this resource owner exists $this->getResourceOwner($name); $request->attributes->set('service', $name); $session = new Session(); // définit et récupère des attributs de session $session->set('name', $url); return $this->httpUtils->generateUri($request, 'hwi_oauth_service_redirect'); }
/** * @param string $path * @return string * @throws \RuntimeException */ protected function buildPath($path) { if (isset($this->config['base_url']) && $this->config['base_url']) { return $this->config['base_url'] . $path; } else { if (!$this->request) { throw new \RuntimeException('Request not set'); } return $this->httpUtils->generateUri($this->request, $path); } }
/** * @expectedException \LogicException * @expectedExceptionMessage You must provide a UrlGeneratorInterface instance to be able to use routes. */ public function testUrlGeneratorIsRequiredToGenerateUrl() { $utils = new HttpUtils(); $utils->generateUri(new Request(), 'route_name'); }
/** * {@inheritdoc} */ public function start(Request $request, AuthenticationException $authException = null) { $returnUrl = $request->getSchemeAndHttpHost() . $request->getRequestUri(); $url = $this->loginUrl . '?' . http_build_query(['application' => $this->applicationName, 'returnUrl' => $returnUrl, 'loginUrl' => $this->httpUtils->generateUri($request, $this->loginPath)]); return $this->httpUtils->createRedirectResponse($request, $url); }