/** * @param string $sessionIndex * @return AuthnStatement */ public function getAuthnStatement($sessionIndex = 'session_index') { $authnStatement = new AuthnStatement(); $authnStatement->setSessionIndex($sessionIndex); return $authnStatement; }
/** * @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); }