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) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param string $provider |
||
| 175 | * @return XMLResponse |
||
| 176 | */ |
||
| 177 | public function metadataAction($provider) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $provider |
||
| 189 | * @return \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider |
||
| 190 | */ |
||
| 191 | private function getProvider($provider) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param StateHandler $stateHandler |
||
| 207 | * @return string |
||
| 208 | */ |
||
| 209 | private function getDestination(StateHandler $stateHandler) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @param string $view |
||
| 233 | * @param StateHandler $stateHandler |
||
| 234 | * @param SAMLResponse $response |
||
| 235 | * @return Response |
||
| 236 | */ |
||
| 237 | public function renderSamlResponse($view, StateHandler $stateHandler, SAMLResponse $response) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @param SAMLResponse $response |
||
| 258 | * @return string |
||
| 259 | */ |
||
| 260 | private function getResponseAsXML(SAMLResponse $response) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Response that indicates that an error occurred in the responder (the gateway). Used to indicate that we could |
||
| 267 | * not process the response we received from the upstream GSSP |
||
| 268 | * |
||
| 269 | * @param Provider $provider |
||
| 270 | * @param string $destination |
||
| 271 | * @return SAMLResponse |
||
| 272 | */ |
||
| 273 | View Code Duplication | private function createResponseFailureResponse(Provider $provider, $destination, $message) |
|
| 284 | |||
| 285 | /** |
||
| 286 | * Response that indicates that the authentication could not be performed correctly. In this context it means |
||
| 287 | * that the upstream GSSP did not responsd with the same NameID as we request to authenticate in the AuthnRequest |
||
| 288 | * |
||
| 289 | * @param Provider $provider |
||
| 290 | * @param string $destination |
||
| 291 | * @return SAMLResponse |
||
| 292 | */ |
||
| 293 | View Code Duplication | private function createAuthnFailedResponse(Provider $provider, $destination) |
|
| 305 | |||
| 306 | /** |
||
| 307 | * Creates a standard response with default status Code (success) |
||
| 308 | * |
||
| 309 | * @param Provider $provider |
||
| 310 | * @param string $destination |
||
| 311 | * @return SAMLResponse |
||
| 312 | */ |
||
| 313 | private function createResponse(Provider $provider, $destination) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @param string $serviceProvider |
||
| 328 | * @return \Surfnet\StepupGateway\GatewayBundle\Entity\ServiceProvider |
||
| 329 | */ |
||
| 330 | private function getServiceProvider($serviceProvider) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @return LoginService |
||
| 341 | */ |
||
| 342 | private function getGsspLoginService() |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return SecondFactorVerificationService |
||
| 349 | */ |
||
| 350 | private function getGsspSecondFactorVerificationService() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return ConsumeAssertionService |
||
| 357 | */ |
||
| 358 | private function getGsspConsumeAssertionService() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param Provider $provider |
||
| 365 | * @return ProxyResponseFactory |
||
| 366 | */ |
||
| 367 | private function getProxyResponseFactory(Provider $provider) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext |
||
| 374 | */ |
||
| 375 | View Code Duplication | public function getResponseContext() |
|
| 387 | } |
||
| 388 |
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 theSoncalls the wrong method in the parent class.