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