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 $provider |
||
102 | * @param $subjectNameId |
||
103 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
104 | */ |
||
105 | public function sendSecondFactorVerificationAuthnRequestAction($provider, $subjectNameId) |
||
118 | |||
119 | /** |
||
120 | * Process an assertion received from the remote GSSP application. |
||
121 | * |
||
122 | * The GSSP application sent an assertion back to the gateway. When |
||
123 | * successful, the user is sent back to: |
||
124 | * |
||
125 | * 1. in case of registration: back to the originating SP (SelfService or RA) |
||
126 | * 2. in case of verification: internal redirect to SecondFactorController |
||
127 | * |
||
128 | * @param string $provider |
||
129 | * @param Request $httpRequest |
||
130 | * @return \Symfony\Component\HttpFoundation\Response |
||
131 | * @throws Exception |
||
132 | */ |
||
133 | public function consumeAssertionAction($provider, Request $httpRequest) |
||
167 | |||
168 | /** |
||
169 | * @param string $provider |
||
170 | * @return XMLResponse |
||
171 | */ |
||
172 | public function metadataAction($provider) |
||
181 | |||
182 | /** |
||
183 | * @param string $provider |
||
184 | * @return \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider |
||
185 | */ |
||
186 | private function getProvider($provider) |
||
199 | |||
200 | /** |
||
201 | * @param StateHandler $stateHandler |
||
202 | * @return string |
||
203 | */ |
||
204 | private function getDestination(StateHandler $stateHandler) |
||
223 | |||
224 | /** |
||
225 | * @param string $view |
||
226 | * @param StateHandler $stateHandler |
||
227 | * @param SAMLResponse $response |
||
228 | * @return Response |
||
229 | */ |
||
230 | public function renderSamlResponse($view, StateHandler $stateHandler, SAMLResponse $response) |
||
248 | |||
249 | /** |
||
250 | * @param SAMLResponse $response |
||
251 | * @return string |
||
252 | */ |
||
253 | private function getResponseAsXML(SAMLResponse $response) |
||
257 | |||
258 | /** |
||
259 | * Response that indicates that an error occurred in the responder (the gateway). Used to indicate that we could |
||
260 | * not process the response we received from the upstream GSSP |
||
261 | * |
||
262 | * @param Provider $provider |
||
263 | * @param string $destination |
||
264 | * @return SAMLResponse |
||
265 | */ |
||
266 | View Code Duplication | private function createResponseFailureResponse(Provider $provider, $destination, $message) |
|
277 | |||
278 | /** |
||
279 | * Response that indicates that the authentication could not be performed correctly. In this context it means |
||
280 | * that the upstream GSSP did not responsd with the same NameID as we request to authenticate in the AuthnRequest |
||
281 | * |
||
282 | * @param Provider $provider |
||
283 | * @param string $destination |
||
284 | * @return SAMLResponse |
||
285 | */ |
||
286 | View Code Duplication | private function createAuthnFailedResponse(Provider $provider, $destination) |
|
296 | |||
297 | /** |
||
298 | * Creates a standard response with default status Code (success) |
||
299 | * |
||
300 | * @param Provider $provider |
||
301 | * @param string $destination |
||
302 | * @return SAMLResponse |
||
303 | */ |
||
304 | private function createResponse(Provider $provider, $destination) |
||
316 | |||
317 | /** |
||
318 | * @param string $serviceProvider |
||
319 | * @return \Surfnet\StepupGateway\GatewayBundle\Entity\ServiceProvider |
||
320 | */ |
||
321 | private function getServiceProvider($serviceProvider) |
||
329 | |||
330 | /** |
||
331 | * @return LoginService |
||
332 | */ |
||
333 | private function getGsspLoginService() |
||
337 | |||
338 | /** |
||
339 | * @return SecondFactorVerificationService |
||
340 | */ |
||
341 | private function getGsspSecondFactorVerificationService() |
||
345 | |||
346 | /** |
||
347 | * @return ConsumeAssertionService |
||
348 | */ |
||
349 | private function getGsspConsumeAssertionService() |
||
353 | |||
354 | /** |
||
355 | * @param Provider $provider |
||
356 | * @return ProxyResponseFactory |
||
357 | */ |
||
358 | private function getProxyResponseFactory(Provider $provider) |
||
362 | |||
363 | /** |
||
364 | * @return \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext |
||
365 | */ |
||
366 | View Code Duplication | public function getResponseContext() |
|
378 | } |
||
379 |
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.