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 | |||
79 | $identity = $this->getUser()->getIdentity(); |
||
80 | |||
81 | $vettedSecondFactors = $this->secondFactorService->findVettedByIdentity($identity->id); |
||
82 | if (!$vettedSecondFactors || $vettedSecondFactors->getTotalItems() === 0) { |
||
83 | $this->logger->error( |
||
84 | sprintf( |
||
85 | 'Identity "%s" tried to test a second factor, but does not own a suitable vetted token.', |
||
86 | $identity->id, |
||
87 | ), |
||
88 | ); |
||
89 | |||
90 | throw new NotFoundHttpException(); |
||
91 | } |
||
92 | |||
93 | |||
94 | // By requesting LoA 1.5 any relevant token can be tested (LoA 2 and 3) |
||
95 | $authenticationRequest = $this->testAuthenticationRequestFactory->createSecondFactorTestRequest( |
||
96 | $identity->nameId, |
||
97 | $this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED), |
||
98 | ); |
||
99 | |||
100 | $this->requestStack->getSession()->set('second_factor_test_request_id', $authenticationRequest->getRequestId()); |
||
101 | |||
102 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId()); |
||
103 | $samlLogger->notice('Sending authentication request to the second factor test IDP'); |
||
104 | |||
105 | return $this->redirectBinding->createResponseFor($authenticationRequest); |
||
106 | } |
||
107 | |||
108 | #[Route( |
||
109 | path: '/authentication/consume-assertion', |
||
110 | name: 'selfservice_serviceprovider_consume_assertion', |
||
111 | methods: ['POST'], |
||
112 | )] |
||
113 | public function consumeAssertion(Request $httpRequest): Response |
||
114 | { |
||
115 | $session = $this->requestStack->getSession(); |
||
116 | if ($session->has(SelfVetController::SELF_VET_SESSION_ID)) { |
||
117 | // The test authentication IdP is also used for self vetting, a different session id is |
||
118 | // used to mark a self vet command |
||
119 | /** @var SelfVetRequestId $selfVetRequestId */ |
||
120 | $selfVetRequestId = $session->get(SelfVetController::SELF_VET_SESSION_ID); |
||
121 | $secondFactorId = $selfVetRequestId->vettingSecondFactorId(); |
||
122 | return $this->forward( |
||
123 | 'Surfnet\StepupSelfService\SelfServiceBundle\Controller\SelfVetController::consumeSelfVetAssertion', |
||
124 | ['secondFactorId' => $secondFactorId], |
||
125 | ); |
||
126 | } |
||
127 | if ($session->has(RecoveryTokenState::RECOVERY_TOKEN_STEP_UP_REQUEST_ID_IDENTIFIER)) { |
||
128 | // The test authentication IdP is also used for self-asserted recovery token |
||
129 | // verification a different session id is used to mark the authentication. |
||
130 | return $this->forward('Surfnet\StepupSelfService\SelfServiceBundle\Controller\RecoveryTokenController::stepUpConsumeAssertion'); |
||
131 | } |
||
132 | if (!$session->has('second_factor_test_request_id')) { |
||
133 | $this->logger->error( |
||
134 | 'Received an authentication response for testing a second factor, but no second factor test response was expected', |
||
135 | ); |
||
136 | |||
137 | throw new AccessDeniedHttpException('Did not expect an authentication response'); |
||
138 | } |
||
139 | $this->logger->notice('Received an authentication response for testing a second factor'); |
||
140 | $initiatedRequestId = $session->get('second_factor_test_request_id'); |
||
141 | $samlLogger = $this->samlAuthenticationLogger->forAuthentication($initiatedRequestId); |
||
178 |