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 |
||
| 53 | class SamlProxyController extends Controller |
||
| 54 | { |
||
| 55 | /** |
||
| 56 | * Proxy a GSSP authentication request to the remote GSSP SSO endpoint. |
||
| 57 | * |
||
| 58 | * The user is about to be sent to the remote GSSP application for |
||
| 59 | * registration. Verification is not initiated with a SAML AUthnRequest, |
||
| 60 | * see sendSecondFactorVerificationAuthnRequestAction(). |
||
| 61 | * |
||
| 62 | * The service provider in this context is SelfService (when registering |
||
| 63 | * a token) or RA (when vetting a token). |
||
| 64 | * |
||
| 65 | * @param string $provider |
||
| 66 | * @param Request $httpRequest |
||
| 67 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
||
| 68 | */ |
||
| 69 | public function singleSignOnAction($provider, Request $httpRequest) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Start a GSSP single sign-on. |
||
| 91 | * |
||
| 92 | * The user has selected a second factor token and the token happens to be |
||
| 93 | * a GSSP token. The SecondFactorController therefor did an internal |
||
| 94 | * redirect (see SecondFactorController::verifyGssfAction) to this method. |
||
| 95 | * |
||
| 96 | * In this method, an authn request is created. This authn request is sent |
||
| 97 | * directly to the remote GSSP SSO URL, and the response is handled in |
||
| 98 | * consumeAssertionAction(). |
||
| 99 | * |
||
| 100 | * @param $provider |
||
| 101 | * @param $subjectNameId |
||
| 102 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 103 | */ |
||
| 104 | public function sendSecondFactorVerificationAuthnRequestAction($provider, $subjectNameId) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Process an assertion received from the remote GSSP application. |
||
| 120 | * |
||
| 121 | * The GSSP application sent an assertion back to the gateway. When |
||
| 122 | * successful, the user is sent back to: |
||
| 123 | * |
||
| 124 | * 1. in case of registration: back to the originating SP (SelfService or RA) |
||
| 125 | * 2. in case of verification: internal redirect to SecondFactorController |
||
| 126 | * |
||
| 127 | * @param string $provider |
||
| 128 | * @param Request $httpRequest |
||
| 129 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 130 | * @throws Exception |
||
| 131 | */ |
||
| 132 | public function consumeAssertionAction($provider, Request $httpRequest) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param string $provider |
||
| 168 | * @return XMLResponse |
||
| 169 | */ |
||
| 170 | public function metadataAction($provider) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param string $provider |
||
| 182 | * @return \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider |
||
| 183 | */ |
||
| 184 | private function getProvider($provider) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param StateHandler $stateHandler |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | private function getDestination(StateHandler $stateHandler) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param string $view |
||
| 224 | * @param StateHandler $stateHandler |
||
| 225 | * @param SAMLResponse $response |
||
| 226 | * @return Response |
||
| 227 | */ |
||
| 228 | View Code Duplication | public function renderSamlResponse($view, StateHandler $stateHandler, SAMLResponse $response) |
|
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $view |
||
| 244 | * @param array $parameters |
||
| 245 | * @param Response $response |
||
| 246 | * @return Response |
||
| 247 | */ |
||
| 248 | public function render($view, array $parameters = array(), Response $response = null) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @param SAMLResponse $response |
||
| 259 | * @return string |
||
| 260 | */ |
||
| 261 | private function getResponseAsXML(SAMLResponse $response) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Response that indicates that an error occurred in the responder (the gateway). Used to indicate that we could |
||
| 268 | * not process the response we received from the upstream GSSP |
||
| 269 | * |
||
| 270 | * @param Provider $provider |
||
| 271 | * @param string $destination |
||
| 272 | * @return SAMLResponse |
||
| 273 | */ |
||
| 274 | private function createResponseFailureResponse(Provider $provider, $destination) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Response that indicates that the authentication could not be performed correctly. In this context it means |
||
| 284 | * that the upstream GSSP did not responsd with the same NameID as we request to authenticate in the AuthnRequest |
||
| 285 | * |
||
| 286 | * @param Provider $provider |
||
| 287 | * @param string $destination |
||
| 288 | * @return SAMLResponse |
||
| 289 | */ |
||
| 290 | private function createAuthnFailedResponse(Provider $provider, $destination) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Creates a standard response with default status Code (success) |
||
| 303 | * |
||
| 304 | * @param Provider $provider |
||
| 305 | * @param string $destination |
||
| 306 | * @return SAMLResponse |
||
| 307 | */ |
||
| 308 | private function createResponse(Provider $provider, $destination) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @param string $serviceProvider |
||
| 321 | * @return \Surfnet\StepupGateway\GatewayBundle\Entity\ServiceProvider |
||
| 322 | */ |
||
| 323 | private function getServiceProvider($serviceProvider) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @return LoginService |
||
| 334 | */ |
||
| 335 | private function getGsspLoginService() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return SecondFactorVerificationService |
||
| 342 | */ |
||
| 343 | private function getGsspSecondFactorVerificationService() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @return ConsumeAssertionService |
||
| 350 | */ |
||
| 351 | private function getGsspConsumeAssertionService() |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @param Provider $provider |
||
| 358 | * @return ProxyResponseFactory |
||
| 359 | */ |
||
| 360 | private function getProxyResponseFactory(Provider $provider) |
||
| 364 | } |
||
| 365 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.