Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
54 | class SamlProxyController extends Controller |
||
55 | { |
||
56 | /** |
||
57 | * Proxy a GSSP authentication request to the remote GSSP SSO endpoint. |
||
58 | * |
||
59 | * The user is about to be sent to the remote GSSP application for |
||
60 | * registration. Verification is not initiated with a SAML AUthnRequest, |
||
61 | * see sendSecondFactorVerificationAuthnRequestAction(). |
||
62 | * |
||
63 | * The service provider in this context is SelfService (when registering |
||
64 | * a token) or RA (when vetting a token). |
||
65 | * |
||
66 | * @param string $provider |
||
67 | * @param Request $httpRequest |
||
68 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
||
69 | */ |
||
70 | public function singleSignOnAction($provider, Request $httpRequest) |
||
89 | |||
90 | /** |
||
91 | * Start a GSSP single sign-on. |
||
92 | * |
||
93 | * The user has selected a second factor token and the token happens to be |
||
94 | * a GSSP token. The SecondFactorController therefor did an internal |
||
95 | * redirect (see SecondFactorController::verifyGssfAction) to this method. |
||
96 | * |
||
97 | * In this method, an authn request is created. This authn request is sent |
||
98 | * directly to the remote GSSP SSO URL, and the response is handled in |
||
99 | * consumeAssertionAction(). |
||
100 | * |
||
101 | * @param string $provider |
||
102 | * @param string $subjectNameId |
||
103 | * @param string $responseContextServiceId |
||
104 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
105 | */ |
||
106 | public function sendSecondFactorVerificationAuthnRequestAction($provider, $subjectNameId, $responseContextServiceId) |
||
123 | |||
124 | /** |
||
125 | * Process an assertion received from the remote GSSP application. |
||
126 | * |
||
127 | * The GSSP application sent an assertion back to the gateway. When |
||
128 | * successful, the user is sent back to: |
||
129 | * |
||
130 | * 1. in case of registration: back to the originating SP (SelfService or RA) |
||
131 | * 2. in case of verification: internal redirect to SecondFactorController |
||
132 | * |
||
133 | * @param string $provider |
||
134 | * @param Request $httpRequest |
||
135 | * @return \Symfony\Component\HttpFoundation\Response |
||
136 | * @throws Exception |
||
137 | */ |
||
138 | public function consumeAssertionAction($provider, Request $httpRequest) |
||
181 | |||
182 | /** |
||
183 | * @param string $provider |
||
184 | * @return XMLResponse |
||
185 | */ |
||
186 | public function metadataAction($provider) |
||
195 | |||
196 | /** |
||
197 | * @param string $provider |
||
198 | * @return \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider |
||
199 | */ |
||
200 | private function getProvider($provider) |
||
213 | |||
214 | /** |
||
215 | * @param StateHandler $stateHandler |
||
216 | * @return string |
||
217 | */ |
||
218 | private function getDestination(StateHandler $stateHandler) |
||
239 | |||
240 | /** |
||
241 | * @param string $view |
||
242 | * @param StateHandler $stateHandler |
||
243 | * @param SAMLResponse $response |
||
244 | * @return Response |
||
245 | */ |
||
246 | public function renderSamlResponse($view, StateHandler $stateHandler, SAMLResponse $response) |
||
264 | |||
265 | /** |
||
266 | * @param SAMLResponse $response |
||
267 | * @return string |
||
268 | */ |
||
269 | private function getResponseAsXML(SAMLResponse $response) |
||
273 | |||
274 | /** |
||
275 | * Response that indicates that an error occurred in the responder (the gateway). Used to indicate that we could |
||
276 | * not process the response we received from the upstream GSSP |
||
277 | * |
||
278 | * @param Provider $provider |
||
279 | * @param string $destination |
||
280 | * @return SAMLResponse |
||
281 | */ |
||
282 | View Code Duplication | private function createResponseFailureResponse(Provider $provider, $destination, $message) |
|
293 | |||
294 | /** |
||
295 | * Response that indicates that the authentication could not be performed correctly. In this context it means |
||
296 | * that the upstream GSSP did not responsd with the same NameID as we request to authenticate in the AuthnRequest |
||
297 | * |
||
298 | * @param Provider $provider |
||
299 | * @param string $destination |
||
300 | * @return SAMLResponse |
||
301 | */ |
||
302 | View Code Duplication | private function createAuthnFailedResponse(Provider $provider, $destination) |
|
314 | |||
315 | /** |
||
316 | * Creates a standard response with default status Code (success) |
||
317 | * |
||
318 | * @param Provider $provider |
||
319 | * @param string $destination |
||
320 | * @return SAMLResponse |
||
321 | */ |
||
322 | private function createResponse(Provider $provider, $destination) |
||
334 | |||
335 | /** |
||
336 | * @param string $serviceProvider |
||
337 | * @return \Surfnet\StepupGateway\GatewayBundle\Entity\ServiceProvider |
||
338 | */ |
||
339 | private function getServiceProvider($serviceProvider) |
||
347 | |||
348 | /** |
||
349 | * @return LoginService |
||
350 | */ |
||
351 | private function getGsspLoginService() |
||
355 | |||
356 | /** |
||
357 | * @return SecondFactorVerificationService |
||
358 | */ |
||
359 | private function getGsspSecondFactorVerificationService() |
||
363 | |||
364 | /** |
||
365 | * @return ConsumeAssertionService |
||
366 | */ |
||
367 | private function getGsspConsumeAssertionService() |
||
371 | |||
372 | /** |
||
373 | * @param Provider $provider |
||
374 | * @return ProxyResponseFactory |
||
375 | */ |
||
376 | private function getProxyResponseFactory(Provider $provider) |
||
380 | |||
381 | /** |
||
382 | * @return \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext |
||
383 | */ |
||
384 | View Code Duplication | public function getResponseContext() |
|
396 | } |
||
397 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.