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