/** * @param Message $message * @return \AerialShip\LightSaml\Binding\Response */ public function send(Message $message) { $bindingType = $this->spMeta->getAuthnRequestBinding(); if ($bindingType) { $detector = new BindingDetector(); $binding = $detector->instantiate($bindingType); } else { $binding = new HttpRedirect(); } $result = $binding->send($message); return $result; }
function testAuthnRequest() { $authnRequest = $this->getRequest(); $id = $authnRequest->getID(); $time = $authnRequest->getIssueInstant(); $binding = new HttpRedirect(); /** @var RedirectResponse $response */ $response = $binding->send($authnRequest); $this->assertNotNull($response); $this->assertTrue($response instanceof RedirectResponse); $pos = strpos($response->getDestination(), '?'); $destination = substr($response->getDestination(), 0, $pos); $queryString = substr($response->getDestination(), $pos + 1); $this->assertEquals($this->destination, $destination); $bindingRequest = new Request(); $data = $bindingRequest->parseQueryString($queryString, true); $this->checkData($data); /** @var AuthnRequest $authnRequest */ $authnRequest = $binding->receive($bindingRequest); $this->assertTrue($authnRequest instanceof AuthnRequest); $this->checkRequest($authnRequest, $id, $time); }
/** * @param \Symfony\Component\HttpFoundation\Request $request * @throws \RuntimeException * @throws \InvalidArgumentException if cannot manage the Request * @return \Symfony\Component\HttpFoundation\Response|SamlSpInfo|null */ public function manage(Request $request) { if (!$this->supports($request)) { throw new \InvalidArgumentException('Unsupported request'); } $logoutRequest = $this->receiveRequest($request); $serviceInfo = $this->getServiceInfo($logoutRequest, $request); $this->validateLogoutRequest($serviceInfo, $logoutRequest); $arrStates = $this->getSSOState($serviceInfo, $logoutRequest->getNameID()->getValue(), $logoutRequest->getSessionIndex()); $this->deleteSSOState($arrStates); $logoutResponse = new LogoutResponse(); $logoutResponse->setID(Helper::generateID()); $logoutResponse->setIssuer($serviceInfo->getSpProvider()->getEntityDescriptor()->getEntityID()); $logoutResponse->setInResponseTo($logoutRequest->getID()); $logoutResponse->setRelayState($logoutRequest->getRelayState()); $arrSLO = $serviceInfo->getIdpProvider()->getEntityDescriptor()->getFirstIdpSsoDescriptor()->findSingleLogoutServices(); /** @var $slo SingleLogoutService */ $slo = array_pop($arrSLO); $logoutResponse->setDestination($slo->getLocation()); $status = new Status(); $status->setSuccess(); $logoutResponse->setStatus($status); // Log the user out $request->getSession()->invalidate(); $this->securityContext->setToken(null); // Return the response to SLO Service $bindingType = $serviceInfo->getSpMetaProvider()->getSpMeta()->getResponseBinding(); if ($bindingType) { $detector = new BindingDetector(); $binding = $detector->instantiate($bindingType); } else { $binding = new HttpRedirect(); } $bindingResponse = $binding->send($logoutResponse); if ($bindingResponse instanceof PostResponse) { return new Response($bindingResponse->render()); } else { if ($bindingResponse instanceof RedirectResponse) { return new RedirectResponse($bindingResponse->getDestination()); } else { $context = new SerializationContext(); $logoutResponse->getXml($context->getDocument(), $context); $xml = $context->getDocument()->saveXML(); return new Response($xml, 200, array('Content-Type' => 'application/xml')); } } }