Skip to content

Commit 6b26c9c

Browse files
committed
Allow test authentication to pass through Saml bundle authn
1 parent 2cdc23f commit 6b26c9c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Surfnet/StepupSelfService/SelfServiceBundle/Controller/SamlController.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
use Surfnet\StepupBundle\Service\LoaResolutionService;
3434
use Surfnet\StepupBundle\Value\Loa;
3535
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\SelfVet\SelfVetController;
36+
use Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication\SamlAuthenticationStateHandler;
37+
use Surfnet\StepupSelfService\SelfServiceBundle\Security\Authentication\Session\SessionStorage;
3638
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService;
3739
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\RecoveryTokenState;
3840
use Surfnet\StepupSelfService\SelfServiceBundle\Service\TestSecondFactor\TestAuthenticationRequestFactory;
@@ -63,6 +65,7 @@ public function __construct(
6365
private readonly LoaResolutionService $loaResolutionService,
6466
private readonly MetadataFactory $metadataFactory,
6567
private readonly SamlAuthenticationLogger $samlAuthenticationLogger,
68+
private readonly SessionStorage $authenticationStateHandler,
6669
private readonly TestAuthenticationRequestFactory $testAuthenticationRequestFactory,
6770
private readonly RedirectBinding $redirectBinding,
6871
private readonly PostBinding $postBinding,
@@ -103,7 +106,7 @@ public function testSecondFactor(): RedirectResponse
103106
$this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED),
104107
);
105108

106-
$this->requestStack->getSession()->set('second_factor_test_request_id', $authenticationRequest->getRequestId());
109+
$this->authenticationStateHandler->setRequestId($authenticationRequest->getRequestId());
107110

108111
$samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId());
109112
$samlLogger->notice('Sending authentication request to the second factor test IDP');
@@ -135,17 +138,17 @@ public function consumeAssertion(Request $httpRequest): Response
135138
// verification a different session id is used to mark the authentication.
136139
return $this->forward('Surfnet\StepupSelfService\SelfServiceBundle\Controller\RecoveryTokenController::stepUpConsumeAssertion');
137140
}
138-
if (!$session->has('second_factor_test_request_id')) {
141+
if (!$this->authenticationStateHandler->hasRequestId()) {
139142
$this->logger->error(
140143
'Received an authentication response for testing a second factor, but no second factor test response was expected',
141144
);
142145

143146
throw new AccessDeniedHttpException('Did not expect an authentication response');
144147
}
145148
$this->logger->notice('Received an authentication response for testing a second factor');
146-
$initiatedRequestId = $session->get('second_factor_test_request_id');
149+
$initiatedRequestId = $this->authenticationStateHandler->getRequestId();
147150
$samlLogger = $this->samlAuthenticationLogger->forAuthentication($initiatedRequestId);
148-
$session->remove('second_factor_test_request_id');
151+
$this->authenticationStateHandler->clearRequestId();
149152
try {
150153
$assertion = $this->postBinding->processResponse(
151154
$httpRequest,

0 commit comments

Comments
 (0)