コード例 #1
0
 /**
  * @test
  */
 public function shouldCreateTokenFromIDPResponseAndPassItToAuthenticationManager()
 {
     $requestMock = $this->createRequestStub($hasSessionReturn = true, $hasPreviousSessionReturn = true, $duplicateReturn = $this->createRequestMock(), $getSessionReturn = $this->createSessionMock());
     $duplicateReturn->attributes = new ParameterBag();
     $nameID = new NameID();
     $nameID->setValue('name.id');
     $attribute1 = new Attribute();
     $attribute1->setName('common.name');
     $attribute1->setValues(array('my common name'));
     $authnStatement = new AuthnStatement();
     $authnStatement->setSessionIndex('1234567890');
     $relyingPartyMock = $this->createRelyingPartyStub($supportsReturn = true, $manageReturnSamlSpInfo = new SamlSpInfo('idp1', $nameID, array($attribute1), $authnStatement));
     $httpUtilsStub = $this->createHttpUtilsStub($checkRequestPathReturn = true, $createRedirectResponseReturn = new RedirectResponse('uri'));
     $testCase = $this;
     $authenticationManagerMock = $this->createAuthenticationManagerMock();
     $authenticationManagerMock->expects($this->once())->method('authenticate')->with($this->isInstanceOf('AerialShip\\SamlSPBundle\\Security\\Core\\Authentication\\Token\\SamlSpToken'))->will($this->returnCallback(function (SamlSpToken $actualToken) use($testCase, $manageReturnSamlSpInfo) {
         $samlInfo = $actualToken->getSamlSpInfo();
         $testCase->assertNotNull($samlInfo);
         $testCase->assertNotNull($samlInfo->getNameID());
         $testCase->assertEquals('name.id', $samlInfo->getNameID()->getValue());
         $testCase->assertNotNull($samlInfo->getAttributes());
         $testCase->assertCount(1, $samlInfo->getAttributes());
         $testCase->assertEquals($manageReturnSamlSpInfo, $actualToken->getSamlSpInfo());
         return $actualToken;
     }));
     $eventMock = $this->createGetResponseEventStub($requestMock);
     $listener = new SamlSpAuthenticationListener($this->createSecurityContextMock(), $authenticationManagerMock, $this->createSessionAuthenticationStrategyMock(), $httpUtilsStub, 'providerKey', $this->createAuthenticationSuccessHandlerStub(), $this->createAuthenticationFailureHandlerMock(), $options = array());
     $listener->setRelyingParty($relyingPartyMock);
     $listener->handle($eventMock);
 }
コード例 #2
0
 /**
  * @param string $nameIDValue
  * @param string $nameIDFormat
  * @return NameID
  */
 public function getNameID($nameIDValue = 'nameID', $nameIDFormat = 'nameIDFormat')
 {
     $nameID = new NameID();
     $nameID->setValue($nameIDValue);
     $nameID->setFormat($nameIDFormat);
     return $nameID;
 }
コード例 #3
0
 /**
  * @param string $nameIDValue
  * @param string|null $nameIDFormat
  * @param string|null $sessionIndex
  * @param string|null $reason
  * @return LogoutRequest
  */
 public function build($nameIDValue, $nameIDFormat = null, $sessionIndex = null, $reason = null)
 {
     $result = new LogoutRequest();
     $edSP = $this->getEdSP();
     $result->setID(Helper::generateID());
     $result->setDestination($this->getDestination());
     $result->setIssueInstant(time());
     if ($reason) {
         $result->setReason($reason);
     }
     if ($sessionIndex) {
         $result->setSessionIndex($sessionIndex);
     }
     $nameID = new NameID();
     $nameID->setValue($nameIDValue);
     if ($nameIDFormat) {
         $nameID->setFormat($nameIDFormat);
     }
     $result->setNameID($nameID);
     $result->setIssuer($edSP->getEntityID());
     return $result;
 }
コード例 #4
0
 /**
  * @param \DOMElement $xml
  * @throws \AerialShip\LightSaml\Error\InvalidXmlException
  */
 function loadFromXml(\DOMElement $xml)
 {
     parent::loadFromXml($xml);
     if ($xml->hasAttribute('Reason')) {
         $this->setReason($xml->getAttribute('Reason'));
     }
     if ($xml->hasAttribute('NotOnOrAfter')) {
         $this->setNotOnOrAfter($xml->getAttribute('NotOnOrAfter'));
     }
     $signatureNode = null;
     $this->iterateChildrenElements($xml, function (\DOMElement $node) use(&$signatureNode) {
         if ($node->localName == 'NameID') {
             $nameID = new NameID();
             $nameID->loadFromXml($node);
             $this->setNameID($nameID);
         }
         if ($node->localName == 'SessionIndex') {
             $this->setSessionIndex($node->textContent);
         }
         if ($node->localName == 'Signature' && $node->namespaceURI == Protocol::NS_XMLDSIG) {
             $signatureNode = $node;
         }
     });
     if (null !== $signatureNode) {
         $signature = new SignatureXmlValidator();
         $signature->loadFromXml($signatureNode);
         $this->setSignature($signature);
     }
 }