| Conditions | 10 |
| Paths | 9 |
| Total Lines | 74 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 95 | public function determineGsspFallbackNeeded( |
||
| 96 | string $identityNameId, |
||
| 97 | string $authenticationMode, |
||
| 98 | Loa $requestedLoa, |
||
| 99 | WhitelistService $whitelistService, |
||
| 100 | LoggerInterface $logger, |
||
| 101 | string $locale, |
||
| 102 | ): bool { |
||
| 103 | |||
| 104 | // Determine if the GSSP fallback flow should be started based on the following conditions: |
||
| 105 | // - the authentication mode is SFO |
||
| 106 | // - a fallback GSSP is configured |
||
| 107 | // - a LoA1.5 (i.e. self asserted) authentication is requested |
||
| 108 | // - the GSSP user attributes are available in the AuthnRequest |
||
| 109 | // - the GSSP institution in the extension is whitelisted |
||
| 110 | // - this "fallback" option is enabled for the institution that the user belongs to. |
||
| 111 | // - the user has no registered tokens |
||
| 112 | |||
| 113 | if ($authenticationMode !== SecondFactorController::MODE_SFO) { |
||
| 114 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 115 | return false; |
||
| 116 | } |
||
| 117 | |||
| 118 | if (!$this->config->isConfigured()) { |
||
| 119 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 120 | return false; |
||
| 121 | } |
||
| 122 | |||
| 123 | if (!$requestedLoa->levelIsLowerOrEqualTo(Loa::LOA_SELF_VETTED)) { |
||
| 124 | $logger->info('Gssp Fallback configured but not used, requested LoA is higher than self-vetted'); |
||
| 125 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 126 | return false; |
||
| 127 | } |
||
| 128 | |||
| 129 | $subject = $this->stateHandler->getGsspUserAttributeSubject(); |
||
| 130 | $institution = $this->stateHandler->getGsspUserAttributeInstitution(); |
||
| 131 | if (empty($subject) || empty($institution)) { |
||
| 132 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 133 | $logger->info('Gssp Fallback configured but not used, GSSP user attributes are not set in AuthnRequest'); |
||
| 134 | return false; |
||
| 135 | } |
||
| 136 | |||
| 137 | if (!$whitelistService->contains($institution)) { |
||
| 138 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 139 | $logger->info('Gssp Fallback configured but not used, GSSP institution is not whitelisted'); |
||
| 140 | return false; |
||
| 141 | } |
||
| 142 | |||
| 143 | try { |
||
| 144 | $institutionConfiguration = $this->institutionConfigurationRepository->getInstitutionConfiguration($institution); |
||
| 145 | } catch (InstitutionConfigurationNotFoundException) { |
||
| 146 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 147 | $logger->info('Gssp Fallback configured but not used, GSSP institution configuration is not found'); |
||
| 148 | return false; |
||
| 149 | } |
||
| 150 | |||
| 151 | if (!$institutionConfiguration->ssoRegistrationBypass) { |
||
| 152 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 153 | $logger->info('Gssp Fallback configured but not used, GSSP fallback is not enabled for the institution'); |
||
| 154 | return false; |
||
| 155 | } |
||
| 156 | |||
| 157 | if ($this->secondFactorRepository->hasTokens($identityNameId)) { |
||
| 158 | $this->stateHandler->setSecondFactorIsFallback(false); |
||
| 159 | $logger->info('Gssp Fallback configured but not used, the identity has registered tokens'); |
||
| 160 | return false; |
||
| 161 | } |
||
| 162 | |||
| 163 | $logger->info('Gssp Fallback flow started'); |
||
| 164 | |||
| 165 | $this->stateHandler->setSecondFactorIsFallback(true); |
||
| 166 | $this->stateHandler->setPreferredLocale($locale); |
||
| 167 | |||
| 168 | return true; |
||
| 169 | } |
||
| 186 |