| Conditions | 6 |
| Paths | 9 |
| Total Lines | 63 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 78 | $identity = $this->getUser()->getIdentity(); |
||
| 79 | |||
| 80 | $vettedSecondFactors = $this->secondFactorService->findVettedByIdentity($identity->id); |
||
| 81 | if (!$vettedSecondFactors || $vettedSecondFactors->getTotalItems() === 0) { |
||
| 82 | $this->logger->error( |
||
| 83 | sprintf( |
||
| 84 | 'Identity "%s" tried to test a second factor, but does not own a suitable vetted token.', |
||
| 85 | $identity->id |
||
| 86 | ) |
||
| 87 | ); |
||
| 88 | |||
| 89 | throw new NotFoundHttpException(); |
||
| 90 | } |
||
| 91 | |||
| 92 | |||
| 93 | // By requesting LoA 1.5 any relevant token can be tested (LoA 2 and 3) |
||
| 94 | $authenticationRequest = $this->testAuthenticationRequestFactory->createSecondFactorTestRequest( |
||
| 95 | $identity->nameId, |
||
| 96 | $this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED) |
||
| 97 | ); |
||
| 98 | |||
| 99 | $this->requestStack->getSession()->set('second_factor_test_request_id', $authenticationRequest->getRequestId()); |
||
| 100 | |||
| 101 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId()); |
||
| 102 | $samlLogger->notice('Sending authentication request to the second factor test IDP'); |
||
| 103 | |||
| 104 | return $this->redirectBinding->createResponseFor($authenticationRequest); |
||
| 105 | } |
||
| 106 | |||
| 107 | #[Route( |
||
| 108 | path: '/authentication/consume-assertion', |
||
| 109 | name: 'selfservice_serviceprovider_consume_assertion', |
||
| 110 | methods: ['POST'], |
||
| 111 | )] |
||
| 112 | public function consumeAssertion(Request $httpRequest): Response |
||
| 113 | { |
||
| 114 | $session = $this->requestStack->getSession(); |
||
| 115 | if ($session->has(SelfVetController::SELF_VET_SESSION_ID)) { |
||
| 116 | // The test authentication IdP is also used for self vetting, a different session id is |
||
| 117 | // used to mark a self vet command |
||
| 118 | /** @var SelfVetRequestId $selfVetRequestId */ |
||
| 119 | $selfVetRequestId = $session->get(SelfVetController::SELF_VET_SESSION_ID); |
||
| 120 | $secondFactorId = $selfVetRequestId->vettingSecondFactorId(); |
||
| 121 | return $this->forward( |
||
| 122 | 'SurfnetStepupSelfServiceSelfServiceBundle:SelfVet:consumeSelfVetAssertion', |
||
| 123 | ['secondFactorId' => $secondFactorId] |
||
| 124 | ); |
||
| 125 | } |
||
| 126 | if ($session->has(RecoveryTokenState::RECOVERY_TOKEN_STEP_UP_REQUEST_ID_IDENTIFIER)) { |
||
| 127 | // The test authentication IdP is also used for self-asserted recovery token |
||
| 128 | // verification a different session id is used to mark the authentication. |
||
| 129 | return $this->forward('SurfnetStepupSelfServiceSelfServiceBundle:RecoveryToken:stepUpConsumeAssertion'); |
||
| 130 | } |
||
| 131 | if (!$session->has('second_factor_test_request_id')) { |
||
| 132 | $this->logger->error( |
||
| 133 | 'Received an authentication response for testing a second factor, but no second factor test response was expected' |
||
| 134 | ); |
||
| 135 | |||
| 136 | throw new AccessDeniedHttpException('Did not expect an authentication response'); |
||
| 137 | } |
||
| 138 | $this->logger->notice('Received an authentication response for testing a second factor'); |
||
| 139 | $initiatedRequestId = $session->get('second_factor_test_request_id'); |
||
| 140 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($initiatedRequestId); |
||
| 141 | $session->remove('second_factor_test_request_id'); |
||
| 177 |