Total Complexity | 53 |
Total Lines | 609 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 0 |
Complex classes like SecondFactorController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SecondFactorController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
53 | class SecondFactorController extends Controller |
||
54 | { |
||
55 | const MODE_SFO = 'sfo'; |
||
56 | const MODE_SSO = 'sso'; |
||
57 | |||
58 | public function selectSecondFactorForVerificationSsoAction(Request $request) |
||
59 | { |
||
60 | return $this->selectSecondFactorForVerificationAction(self::MODE_SSO, $request); |
||
61 | } |
||
62 | |||
63 | public function selectSecondFactorForVerificationSfoAction(Request $request) |
||
64 | { |
||
65 | return $this->selectSecondFactorForVerificationAction(self::MODE_SFO, $request); |
||
66 | } |
||
67 | |||
68 | public function selectSecondFactorForVerificationAction($authenticationMode, Request $request) |
||
69 | { |
||
70 | $this->supportsAuthenticationMode($authenticationMode); |
||
71 | $context = $this->getResponseContext($authenticationMode); |
||
72 | |||
73 | $originalRequestId = $context->getInResponseTo(); |
||
74 | |||
75 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
76 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
77 | $logger->notice('Determining which second factor to use...'); |
||
78 | |||
79 | try { |
||
80 | // Retrieve all requirements to determine the required LoA |
||
81 | $requestedLoa = $context->getRequiredLoa(); |
||
82 | $spConfiguredLoas = $context->getServiceProvider()->get('configuredLoas'); |
||
83 | |||
84 | $identityNameId = $context->getIdentityNameId(); |
||
85 | $normalizedIdpSho = $context->getNormalizedSchacHomeOrganization(); |
||
86 | $normalizedUserSho = $this->getStepupService()->getNormalizedUserShoByIdentityNameId($identityNameId); |
||
87 | |||
88 | $requiredLoa = $this |
||
89 | ->getStepupService() |
||
90 | ->resolveHighestRequiredLoa( |
||
91 | $requestedLoa, |
||
92 | $spConfiguredLoas, |
||
93 | $normalizedIdpSho, |
||
94 | $normalizedUserSho |
||
95 | ); |
||
96 | } catch (LoaCannotBeGivenException $e) { |
||
97 | // Log the message of the domain exception, this contains a meaningful message. |
||
98 | $logger->notice($e->getMessage()); |
||
99 | |||
100 | return $this->forward( |
||
101 | 'SurfnetStepupGatewayGatewayBundle:Gateway:sendLoaCannotBeGiven', |
||
102 | ['authenticationMode' => $authenticationMode] |
||
103 | ); |
||
104 | } |
||
105 | |||
106 | $logger->notice(sprintf('Determined that the required Loa is "%s"', $requiredLoa)); |
||
107 | |||
108 | if ($this->getStepupService()->isIntrinsicLoa($requiredLoa)) { |
||
109 | $this->get('gateway.authentication_logger')->logIntrinsicLoaAuthentication($originalRequestId); |
||
110 | return $this->forward($context->getResponseAction()); |
||
111 | } |
||
112 | |||
113 | $secondFactorCollection = $this |
||
114 | ->getStepupService() |
||
115 | ->determineViableSecondFactors( |
||
116 | $context->getIdentityNameId(), |
||
117 | $requiredLoa, |
||
118 | $this->get('gateway.service.whitelist') |
||
119 | ); |
||
120 | |||
121 | /** |
||
122 | * @var CookieService $ssoCookieService |
||
123 | */ |
||
124 | $ssoCookieService = $this->get('gateway.service.sso_2fa_cookie'); |
||
125 | if ($ssoCookieService->shouldSkip2faAuthentication( |
||
126 | $context, |
||
127 | $requiredLoa->getLevel(), |
||
128 | $identityNameId, |
||
129 | $secondFactorCollection, |
||
130 | $request |
||
131 | )) { |
||
132 | $logger->notice('Skipping second factor authentication. Required LoA was met by the LoA recorded in the cookie'); |
||
133 | $this->getResponseContext($authenticationMode)->markSecondFactorVerified(); |
||
134 | $this->getResponseContext($authenticationMode)->markVerifiedBySsoOn2faCookie($ssoCookieService->getCookieFingerprint($request)); |
||
135 | $this->getAuthenticationLogger()->logSecondFactorAuthentication($originalRequestId, $authenticationMode); |
||
136 | return $this->forward($context->getResponseAction()); |
||
137 | } |
||
138 | switch (count($secondFactorCollection)) { |
||
139 | case 0: |
||
140 | $logger->notice('No second factors can give the determined Loa'); |
||
141 | |||
142 | return $this->forward( |
||
143 | 'SurfnetStepupGatewayGatewayBundle:Gateway:sendLoaCannotBeGiven', |
||
144 | ['authenticationMode' => $authenticationMode] |
||
145 | ); |
||
146 | break; |
||
147 | |||
148 | case 1: |
||
149 | $secondFactor = $secondFactorCollection->first(); |
||
150 | $logger->notice(sprintf( |
||
151 | 'Found "%d" second factors, using second factor of type "%s"', |
||
152 | count($secondFactorCollection), |
||
153 | $secondFactor->secondFactorType |
||
154 | )); |
||
155 | |||
156 | return $this->selectAndRedirectTo($secondFactor, $context, $authenticationMode); |
||
157 | break; |
||
158 | |||
159 | default: |
||
160 | return $this->forward( |
||
161 | 'SurfnetStepupGatewayGatewayBundle:SecondFactor:chooseSecondFactor', |
||
162 | ['authenticationMode' => $authenticationMode, 'secondFactors' => $secondFactorCollection] |
||
163 | ); |
||
164 | break; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * The main WAYG screen |
||
170 | * - Shows the token selection screen if you own > 1 token |
||
171 | * - Directly goes to SF auth when identity owns 1 token |
||
172 | * |
||
173 | * @Template |
||
174 | * @param Request $request |
||
175 | * @param string $authenticationMode |
||
176 | * @return array|RedirectResponse|Response |
||
177 | * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
||
178 | */ |
||
179 | public function chooseSecondFactorAction(Request $request, $authenticationMode) |
||
180 | { |
||
181 | $this->supportsAuthenticationMode($authenticationMode); |
||
182 | $context = $this->getResponseContext($authenticationMode); |
||
183 | $originalRequestId = $context->getInResponseTo(); |
||
184 | |||
185 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
186 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
187 | $logger->notice('Ask the user which one of his suitable second factor tokens to use...'); |
||
188 | |||
189 | try { |
||
190 | // Retrieve all requirements to determine the required LoA |
||
191 | $requestedLoa = $context->getRequiredLoa(); |
||
192 | $spConfiguredLoas = $context->getServiceProvider()->get('configuredLoas'); |
||
193 | |||
194 | $normalizedIdpSho = $context->getNormalizedSchacHomeOrganization(); |
||
195 | $normalizedUserSho = $this->getStepupService()->getNormalizedUserShoByIdentityNameId($context->getIdentityNameId()); |
||
196 | |||
197 | $requiredLoa = $this |
||
198 | ->getStepupService() |
||
199 | ->resolveHighestRequiredLoa( |
||
200 | $requestedLoa, |
||
201 | $spConfiguredLoas, |
||
202 | $normalizedIdpSho, |
||
203 | $normalizedUserSho |
||
204 | ); |
||
205 | } catch (LoaCannotBeGivenException $e) { |
||
206 | // Log the message of the domain exception, this contains a meaningful message. |
||
207 | $logger->notice($e->getMessage()); |
||
208 | return $this->forward('SurfnetStepupGatewayGatewayBundle:Gateway:sendLoaCannotBeGiven'); |
||
209 | } |
||
210 | |||
211 | $logger->notice(sprintf('Determined that the required Loa is "%s"', $requiredLoa)); |
||
212 | |||
213 | $secondFactors = $this |
||
214 | ->getStepupService() |
||
215 | ->determineViableSecondFactors( |
||
216 | $context->getIdentityNameId(), |
||
217 | $requiredLoa, |
||
218 | $this->get('gateway.service.whitelist') |
||
219 | ); |
||
220 | |||
221 | $command = new ChooseSecondFactorCommand(); |
||
222 | $command->secondFactors = $secondFactors; |
||
223 | |||
224 | $form = $this |
||
225 | ->createForm( |
||
226 | ChooseSecondFactorType::class, |
||
227 | $command, |
||
228 | ['action' => $this->generateUrl('gateway_verify_second_factor_choose_second_factor', ['authenticationMode' => $authenticationMode])] |
||
229 | ) |
||
230 | ->handleRequest($request); |
||
231 | $cancelForm = $this->buildCancelAuthenticationForm($authenticationMode)->handleRequest($request); |
||
232 | |||
233 | if ($form->isSubmitted() && $form->isValid()) { |
||
234 | $buttonName = $form->getClickedButton()->getName(); |
||
235 | $formResults = $request->request->get('gateway_choose_second_factor', false); |
||
236 | |||
237 | if (!isset($formResults[$buttonName])) { |
||
238 | throw new InvalidArgumentException( |
||
239 | sprintf( |
||
240 | 'Second factor type "%s" could not be found in the posted form results.', |
||
241 | $buttonName |
||
242 | ) |
||
243 | ); |
||
244 | } |
||
245 | |||
246 | $secondFactorType = $formResults[$buttonName]; |
||
247 | |||
248 | // Filter the selected second factor from the array collection |
||
249 | $secondFactorFiltered = $secondFactors->filter( |
||
250 | function ($secondFactor) use ($secondFactorType) { |
||
251 | return $secondFactorType === $secondFactor->secondFactorType; |
||
252 | } |
||
253 | ); |
||
254 | |||
255 | if ($secondFactorFiltered->isEmpty()) { |
||
256 | throw new InvalidArgumentException( |
||
257 | sprintf( |
||
258 | 'Second factor type "%s" could not be found in the collection of available second factors.', |
||
259 | $secondFactorType |
||
260 | ) |
||
261 | ); |
||
262 | } |
||
263 | |||
264 | $secondFactor = $secondFactorFiltered->first(); |
||
265 | |||
266 | $logger->notice(sprintf('User chose "%s" to use as second factor', $secondFactorType)); |
||
267 | |||
268 | // Forward to action to verify possession of second factor |
||
269 | return $this->selectAndRedirectTo($secondFactor, $context, $authenticationMode); |
||
270 | } else if ($form->isSubmitted() && !$form->isValid()) { |
||
271 | $form->addError( |
||
272 | new FormError( |
||
273 | $this->get('translator') |
||
274 | ->trans('gateway.form.gateway_choose_second_factor.unknown_second_factor_type') |
||
275 | ) |
||
276 | ); |
||
277 | } |
||
278 | |||
279 | return [ |
||
280 | 'form' => $form->createView(), |
||
281 | 'cancelForm' => $cancelForm->createView(), |
||
282 | 'secondFactors' => $secondFactors, |
||
283 | ]; |
||
284 | } |
||
285 | |||
286 | public function verifyGssfAction(Request $request) |
||
287 | { |
||
288 | if (!$request->get('authenticationMode', false)) { |
||
289 | throw new RuntimeException('Unable to determine the authentication mode in the GSSP verification action'); |
||
290 | } |
||
291 | $authenticationMode = $request->get('authenticationMode'); |
||
292 | $this->supportsAuthenticationMode($authenticationMode); |
||
293 | $context = $this->getResponseContext($authenticationMode); |
||
294 | |||
295 | $originalRequestId = $context->getInResponseTo(); |
||
296 | |||
297 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
298 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
299 | $logger->info('Received request to verify GSSF'); |
||
300 | |||
301 | $selectedSecondFactor = $this->getSelectedSecondFactor($context, $logger); |
||
302 | |||
303 | $logger->info(sprintf( |
||
304 | 'Selected GSSF "%s" for verfication, forwarding to Saml handling', |
||
305 | $selectedSecondFactor |
||
306 | )); |
||
307 | |||
308 | /** @var \Surfnet\StepupGateway\GatewayBundle\Service\SecondFactorService $secondFactorService */ |
||
309 | $secondFactorService = $this->get('gateway.service.second_factor_service'); |
||
310 | /** @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor $secondFactor */ |
||
311 | $secondFactor = $secondFactorService->findByUuid($selectedSecondFactor); |
||
312 | if (!$secondFactor) { |
||
313 | throw new RuntimeException(sprintf( |
||
314 | 'Requested verification of GSSF "%s", however that Second Factor no longer exists', |
||
315 | $selectedSecondFactor |
||
316 | )); |
||
317 | } |
||
318 | |||
319 | // Also send the response context service id, as later we need to know if this is regular SSO or SFO authn. |
||
320 | $responseContextServiceId = $context->getResponseContextServiceId(); |
||
321 | |||
322 | return $this->forward( |
||
323 | 'SurfnetStepupGatewaySamlStepupProviderBundle:SamlProxy:sendSecondFactorVerificationAuthnRequest', |
||
324 | [ |
||
325 | 'provider' => $secondFactor->secondFactorType, |
||
326 | 'subjectNameId' => $secondFactor->secondFactorIdentifier, |
||
327 | 'responseContextServiceId' => $responseContextServiceId, |
||
328 | ] |
||
329 | ); |
||
330 | } |
||
331 | |||
332 | public function gssfVerifiedAction(Request $request) |
||
333 | { |
||
334 | $authenticationMode = $request->get('authenticationMode'); |
||
335 | $this->supportsAuthenticationMode($authenticationMode); |
||
336 | $context = $this->getResponseContext($authenticationMode); |
||
337 | |||
338 | $originalRequestId = $context->getInResponseTo(); |
||
339 | |||
340 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
341 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
342 | $logger->info('Attempting to mark GSSF as verified'); |
||
343 | |||
344 | $selectedSecondFactor = $this->getSelectedSecondFactor($context, $logger); |
||
345 | |||
346 | /** @var \Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor $secondFactor */ |
||
347 | $secondFactor = $this->get('gateway.service.second_factor_service')->findByUuid($selectedSecondFactor); |
||
348 | if (!$secondFactor) { |
||
349 | throw new RuntimeException( |
||
350 | sprintf( |
||
351 | 'Verification of GSSF "%s" succeeded, however that Second Factor no longer exists', |
||
352 | $selectedSecondFactor |
||
353 | ) |
||
354 | ); |
||
355 | } |
||
356 | |||
357 | $context->markSecondFactorVerified(); |
||
358 | $this->getAuthenticationLogger()->logSecondFactorAuthentication($originalRequestId, $authenticationMode); |
||
359 | |||
360 | $logger->info(sprintf( |
||
361 | 'Marked GSSF "%s" as verified, forwarding to Gateway controller to respond', |
||
362 | $selectedSecondFactor |
||
363 | )); |
||
364 | return $this->forward($context->getResponseAction()); |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @Template |
||
369 | * @param Request $request |
||
370 | * @return array|Response |
||
371 | */ |
||
372 | public function verifyYubiKeySecondFactorAction(Request $request) |
||
373 | { |
||
374 | if (!$request->get('authenticationMode', false)) { |
||
375 | throw new RuntimeException('Unable to determine the authentication mode in Yubikey verification action'); |
||
376 | } |
||
377 | $authenticationMode = $request->get('authenticationMode'); |
||
378 | $this->supportsAuthenticationMode($authenticationMode); |
||
379 | $context = $this->getResponseContext($authenticationMode); |
||
380 | $originalRequestId = $context->getInResponseTo(); |
||
381 | |||
382 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
383 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
384 | |||
385 | $selectedSecondFactor = $this->getSelectedSecondFactor($context, $logger); |
||
386 | |||
387 | $logger->notice('Verifying possession of Yubikey second factor'); |
||
388 | |||
389 | $command = new VerifyYubikeyOtpCommand(); |
||
390 | $command->secondFactorId = $selectedSecondFactor; |
||
391 | |||
392 | $form = $this->createForm(VerifyYubikeyOtpType::class, $command)->handleRequest($request); |
||
393 | $cancelForm = $this->buildCancelAuthenticationForm($authenticationMode)->handleRequest($request); |
||
394 | |||
395 | if ($form->isSubmitted() && $form->isValid()) { |
||
396 | $result = $this->getStepupService()->verifyYubikeyOtp($command); |
||
397 | if ($result->didOtpVerificationFail()) { |
||
398 | $form->addError( |
||
399 | new FormError($this->get('translator')->trans('gateway.form.verify_yubikey.otp_verification_failed')) |
||
400 | ); |
||
401 | |||
402 | // OTP field is rendered empty in the template. |
||
403 | return ['form' => $form->createView(), 'cancelForm' => $cancelForm->createView()]; |
||
404 | } elseif (!$result->didPublicIdMatch()) { |
||
405 | $form->addError( |
||
406 | new FormError($this->get('translator')->trans('gateway.form.verify_yubikey.public_id_mismatch')) |
||
407 | ); |
||
408 | |||
409 | // OTP field is rendered empty in the template. |
||
410 | return ['form' => $form->createView(), 'cancelForm' => $cancelForm->createView()]; |
||
411 | } |
||
412 | |||
413 | $this->getResponseContext($authenticationMode)->markSecondFactorVerified(); |
||
414 | $this->getAuthenticationLogger()->logSecondFactorAuthentication($originalRequestId, $authenticationMode); |
||
415 | |||
416 | $logger->info( |
||
417 | sprintf( |
||
418 | 'Marked Yubikey Second Factor "%s" as verified, forwarding to Saml Proxy to respond', |
||
419 | $selectedSecondFactor |
||
420 | ) |
||
421 | ); |
||
422 | return $this->forward($context->getResponseAction()); |
||
423 | } |
||
424 | |||
425 | // OTP field is rendered empty in the template. |
||
426 | return ['form' => $form->createView(), 'cancelForm' => $cancelForm->createView()]; |
||
427 | } |
||
428 | |||
429 | /** |
||
430 | * @Template |
||
431 | * @param Request $request |
||
432 | * @param string $authenticationMode |
||
433 | * @return array|Response |
||
434 | */ |
||
435 | public function verifySmsSecondFactorAction(Request $request) |
||
436 | { |
||
437 | if (!$request->get('authenticationMode', false)) { |
||
438 | throw new RuntimeException('Unable to determine the authentication mode in the SMS verification action'); |
||
439 | } |
||
440 | $authenticationMode = $request->get('authenticationMode'); |
||
441 | $this->supportsAuthenticationMode($authenticationMode); |
||
442 | $context = $this->getResponseContext($authenticationMode); |
||
443 | $originalRequestId = $context->getInResponseTo(); |
||
444 | |||
445 | /** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
||
446 | $logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
||
447 | |||
448 | $selectedSecondFactor = $this->getSelectedSecondFactor($context, $logger); |
||
449 | |||
450 | $logger->notice('Verifying possession of SMS second factor, preparing to send'); |
||
451 | |||
452 | $command = new SendSmsChallengeCommand(); |
||
453 | $command->secondFactorId = $selectedSecondFactor; |
||
454 | |||
455 | $form = $this->createForm(SendSmsChallengeType::class, $command)->handleRequest($request); |
||
456 | $cancelForm = $this->buildCancelAuthenticationForm($authenticationMode)->handleRequest($request); |
||
457 | |||
458 | $stepupService = $this->getStepupService(); |
||
459 | $phoneNumber = InternationalPhoneNumber::fromStringFormat( |
||
460 | $stepupService->getSecondFactorIdentifier($selectedSecondFactor) |
||
461 | ); |
||
462 | |||
463 | $otpRequestsRemaining = $stepupService->getSmsOtpRequestsRemainingCount($selectedSecondFactor); |
||
464 | $maximumOtpRequests = $stepupService->getSmsMaximumOtpRequestsCount(); |
||
465 | $viewVariables = ['otpRequestsRemaining' => $otpRequestsRemaining, 'maximumOtpRequests' => $maximumOtpRequests]; |
||
466 | |||
467 | if ($form->isSubmitted() && !$form->isValid()) { |
||
468 | return array_merge( |
||
469 | $viewVariables, |
||
470 | [ |
||
471 | 'phoneNumber' => $phoneNumber, |
||
472 | 'form' => $form->createView(), |
||
473 | 'cancelForm' => $cancelForm->createView() |
||
474 | ] |
||
475 | ); |
||
476 | } |
||
477 | |||
478 | $logger->notice('Verifying possession of SMS second factor, sending challenge per SMS'); |
||
479 | |||
480 | if (!$stepupService->sendSmsChallenge($command)) { |
||
481 | $form->addError( |
||
482 | new FormError($this->get('translator')->trans('gateway.form.send_sms_challenge.sms_sending_failed')) |
||
483 | ); |
||
484 | |||
485 | return array_merge( |
||
486 | $viewVariables, |
||
487 | [ |
||
488 | 'phoneNumber' => $phoneNumber, |
||
489 | 'form' => $form->createView(), |
||
490 | 'cancelForm' => $cancelForm->createView() |
||
491 | ] |
||
492 | ); |
||
493 | } |
||
494 | return $this->redirect( |
||
495 | $this->generateUrl( |
||
496 | 'gateway_verify_second_factor_sms_verify_challenge', |
||
497 | ['authenticationMode' => $authenticationMode] |
||
498 | ) |
||
499 | ); |
||
500 | } |
||
501 | |||
502 | /** |
||
503 | * @Template |
||
504 | * @param Request $request |
||
505 | * @param string $authenticationMode |
||
506 | * @return array|Response |
||
507 | */ |
||
508 | public function verifySmsSecondFactorChallengeAction(Request $request) |
||
565 | } |
||
566 | |||
567 | public function cancelAuthenticationAction() |
||
568 | { |
||
569 | return $this->forward('SurfnetStepupGatewayGatewayBundle:Gateway:sendAuthenticationCancelledByUser'); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * @return \Surfnet\StepupGateway\GatewayBundle\Service\StepupAuthenticationService |
||
574 | */ |
||
575 | private function getStepupService() |
||
576 | { |
||
577 | return $this->get('gateway.service.stepup_authentication'); |
||
578 | } |
||
579 | |||
580 | /** |
||
581 | * @return ResponseContext |
||
582 | */ |
||
583 | private function getResponseContext($authenticationMode) |
||
584 | { |
||
585 | switch ($authenticationMode) { |
||
586 | case self::MODE_SFO: |
||
587 | return $this->get($this->get('gateway.proxy.sfo.state_handler')->getResponseContextServiceId()); |
||
588 | break; |
||
589 | case self::MODE_SSO: |
||
590 | return $this->get($this->get('gateway.proxy.sso.state_handler')->getResponseContextServiceId()); |
||
591 | break; |
||
592 | } |
||
593 | } |
||
594 | |||
595 | /** |
||
596 | * @return \Surfnet\StepupGateway\GatewayBundle\Monolog\Logger\AuthenticationLogger |
||
597 | */ |
||
598 | private function getAuthenticationLogger() |
||
599 | { |
||
600 | return $this->get('gateway.authentication_logger'); |
||
601 | } |
||
602 | |||
603 | /** |
||
604 | * @param ResponseContext $context |
||
605 | * @param LoggerInterface $logger |
||
606 | * @return string |
||
607 | */ |
||
608 | private function getSelectedSecondFactor(ResponseContext $context, LoggerInterface $logger) |
||
609 | { |
||
610 | $selectedSecondFactor = $context->getSelectedSecondFactor(); |
||
611 | |||
612 | if (!$selectedSecondFactor) { |
||
613 | $logger->error('Cannot verify possession of an unknown second factor'); |
||
614 | |||
615 | throw new BadRequestHttpException('Cannot verify possession of an unknown second factor.'); |
||
616 | } |
||
617 | |||
618 | return $selectedSecondFactor; |
||
619 | } |
||
620 | |||
621 | private function selectAndRedirectTo(SecondFactor $secondFactor, ResponseContext $context, $authenticationMode) |
||
622 | { |
||
623 | $context->saveSelectedSecondFactor($secondFactor); |
||
624 | |||
625 | $this->getStepupService()->clearSmsVerificationState($secondFactor->secondFactorId); |
||
626 | |||
627 | $secondFactorTypeService = $this->get('surfnet_stepup.service.second_factor_type'); |
||
628 | $secondFactorType = new SecondFactorType($secondFactor->secondFactorType); |
||
629 | |||
630 | $route = 'gateway_verify_second_factor_'; |
||
631 | if ($secondFactorTypeService->isGssf($secondFactorType)) { |
||
632 | $route .= 'gssf'; |
||
633 | } else { |
||
634 | $route .= strtolower($secondFactor->secondFactorType); |
||
635 | } |
||
636 | |||
637 | return $this->redirect($this->generateUrl($route, ['authenticationMode' => $authenticationMode])); |
||
638 | } |
||
639 | |||
640 | /** |
||
641 | * @param string $authenticationMode |
||
642 | * @return FormInterface |
||
643 | */ |
||
644 | private function buildCancelAuthenticationForm($authenticationMode) |
||
655 | ); |
||
656 | } |
||
657 | |||
658 | private function supportsAuthenticationMode($authenticationMode) |
||
659 | { |
||
660 | if (!($authenticationMode === self::MODE_SSO || $authenticationMode === self::MODE_SFO)) { |
||
661 | throw new InvalidArgumentException('Invalid authentication mode requested'); |
||
662 | } |
||
663 | } |
||
664 | } |
||
665 |