Conditions | 13 |
Paths | 28 |
Total Lines | 116 |
Code Lines | 68 |
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 |
||
140 | public function mayRaCommandBeExecutedOnBehalfOf( |
||
141 | Command $command, |
||
142 | IdentityId $actorId = null, |
||
143 | Institution $actorInstitution = null, |
||
144 | ): bool { |
||
145 | $commandName = $command::class; |
||
146 | $identityId = $actorId instanceof IdentityId ? $actorId->getIdentityId() : null; |
||
147 | |||
148 | $this->logger->notice('Running the mayRaCommandBeExecutedOnBehalfOf sequence'); |
||
149 | // Assert RA(A) specific authorizations |
||
150 | if ($command instanceof RaExecutable) { |
||
151 | $this->logger->notice('Asserting a RA command'); |
||
152 | |||
153 | // No additional FGA authorization is required for this shared (SS/RA) command |
||
154 | if ($command instanceof ExpressLocalePreferenceCommand) { |
||
155 | $this->logAllowRa( |
||
156 | 'RA(A) is always allowed to perform the ExpressLocalePreferenceCommand', |
||
157 | $commandName, |
||
158 | $identityId, |
||
159 | ); |
||
160 | return true; |
||
161 | } |
||
162 | |||
163 | // The actor metadata should be set |
||
164 | if (is_null($actorId) || is_null($actorInstitution)) { |
||
165 | $this->logDenyRA( |
||
166 | 'ActorId and/or actorInstitution is missing in mayRaCommandBeExecutedOnBehalfOf', |
||
167 | $commandName, |
||
168 | $identityId, |
||
169 | ); |
||
170 | return false; |
||
171 | } |
||
172 | |||
173 | // If the actor is SRAA all actions are allowed |
||
174 | if ($this->isSraa($actorId)) { |
||
175 | $this->logAllowRa( |
||
176 | 'SRAA is always allowed to execute RA commands', |
||
177 | $commandName, |
||
178 | $identityId, |
||
179 | ); |
||
180 | return true; |
||
181 | } |
||
182 | |||
183 | $raInstitution = $command->getRaInstitution(); |
||
184 | if (is_null($raInstitution)) { |
||
185 | $raInstitution = $actorInstitution->getInstitution(); |
||
186 | } |
||
187 | |||
188 | $this->logger->notice(sprintf('RA institution = %s', $raInstitution)); |
||
189 | |||
190 | $roleRequirement = RegistrationAuthorityRole::raa(); |
||
191 | |||
192 | // the VetSecondFactorCommand is used to vet a second factor for a user |
||
193 | // the RevokeRegistrantsSecondFactorCommand is used to revoke a user's secondfactor |
||
194 | // the RevokeRegistrantsRecoveryTokenCommand is used to revoke a user's recovery token |
||
195 | // All three are only sent by the RA where the minimal role requirement is RA |
||
196 | // all the other actions require RAA rights |
||
197 | if ($command instanceof VetSecondFactorCommand || |
||
198 | $command instanceof RevokeRegistrantsSecondFactorCommand || |
||
199 | $command instanceof RevokeRegistrantsRecoveryTokenCommand |
||
200 | ) { |
||
201 | $this->logger->notice( |
||
202 | 'VetSecondFactorCommand and RevokeRegistrantsSecondFactorCommand require a RA role', |
||
203 | ); |
||
204 | $roleRequirement = RegistrationAuthorityRole::ra(); |
||
205 | // Use the institution of the identity (the user vetting or having his token revoked). |
||
206 | $identity = $this->identityService->find($command->identityId); |
||
207 | if (!$identity instanceof Identity) { |
||
208 | $this->logDenyRA( |
||
209 | 'Unable to find the identity of the user that is being vetted, or revoked', |
||
210 | $commandName, |
||
211 | $identityId, |
||
212 | ); |
||
213 | return false; |
||
214 | } |
||
215 | $this->logger->notice( |
||
216 | sprintf( |
||
217 | 'Changed RA institution (before %s) to identity institution: %s', |
||
218 | $raInstitution, |
||
219 | $identity->institution->getInstitution(), |
||
220 | ), |
||
221 | ); |
||
222 | $raInstitution = $identity->institution->getInstitution(); |
||
223 | } |
||
224 | |||
225 | $authorizationContext = $this->authorizationContextService->buildInstitutionAuthorizationContext( |
||
226 | $actorId, |
||
227 | $roleRequirement, |
||
228 | ); |
||
229 | |||
230 | $this->logger->notice( |
||
231 | sprintf( |
||
232 | 'Identity is authorized RA(A) role in institutions: %s', |
||
233 | implode(',', $authorizationContext->getInstitutions()->serialize()), |
||
234 | ), |
||
235 | ); |
||
236 | |||
237 | if (!$authorizationContext->getInstitutions()->contains(new Institution($raInstitution))) { |
||
238 | $this->logDenyRA( |
||
239 | sprintf( |
||
240 | 'Identity is not RA(A) for the specified RA institution, "%s". Allowed institutions: "%s"', |
||
241 | $raInstitution, |
||
242 | implode(',', $authorizationContext->getInstitutions()->serialize()), |
||
243 | ), |
||
244 | $commandName, |
||
245 | $identityId, |
||
246 | ); |
||
247 | return false; |
||
248 | } |
||
249 | } |
||
250 | $this->logAllowRa( |
||
251 | 'Allowed', |
||
252 | $commandName, |
||
253 | $identityId, |
||
254 | ); |
||
255 | return true; |
||
256 | } |
||
334 |