Passed
Pull Request — develop (#295)
by Peter
04:30
created

getGsspSecondFactorVerificationService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupGateway\SamlStepupProviderBundle\Controller;
20
21
use DateTime;
22
use Exception;
23
use SAML2\Constants;
24
use SAML2\Response as SAMLResponse;
25
use SAML2\XML\saml\Issuer;
26
use Surfnet\SamlBundle\Http\XMLResponse;
27
use Surfnet\StepupGateway\GatewayBundle\Controller\GatewayController;
28
use Surfnet\StepupGateway\GatewayBundle\Exception\ResponseFailureException;
29
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext;
30
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\InvalidSubjectException;
31
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\NotConnectedServiceProviderException;
32
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\RuntimeException;
33
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\SecondfactorVerificationRequiredException;
34
use Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider;
35
use Surfnet\StepupGateway\SamlStepupProviderBundle\Saml\ProxyResponseFactory;
36
use Surfnet\StepupGateway\SamlStepupProviderBundle\Saml\StateHandler;
37
use Surfnet\StepupGateway\SamlStepupProviderBundle\Service\Gateway\ConsumeAssertionService;
38
use Surfnet\StepupGateway\SamlStepupProviderBundle\Service\Gateway\LoginService;
39
use Surfnet\StepupGateway\SamlStepupProviderBundle\Service\Gateway\SecondFactorVerificationService;
40
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs\ResponseHelper;
41
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
42
use Symfony\Component\HttpFoundation\Request;
43
use Symfony\Component\HttpFoundation\Response;
44
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
45
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
46
47
/**
48
 * Handling of GSSP registration and verification.
49
 *
50
 * See docs/GatewayState.md for a high-level diagram on how this controller
51
 * interacts with outside actors and other parts of Stepup.
52
 *
53
 * Should be refactored, {@see https://www.pivotaltracker.com/story/show/90169776}
54
 *
55
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
56
 * @SuppressWarnings(PHPMD.NPathComplexity)
57
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
58
class SamlProxyController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

58
class SamlProxyController extends /** @scrutinizer ignore-deprecated */ Controller
Loading history...
59
{
60
    /**
61
     * Proxy a GSSP authentication request to the remote GSSP SSO endpoint.
62
     *
63
     * The user is about to be sent to the remote GSSP application for
64
     * registration. Verification is not initiated with a SAML AUthnRequest,
65
     * see sendSecondFactorVerificationAuthnRequestAction().
66
     *
67
     * The service provider in this context is SelfService (when registering
68
     * a token) or RA (when vetting a token).
69
     *
70
     * @param string $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
71
     * @param Request $httpRequest
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
72
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
73
     */
74
    public function singleSignOnAction($provider, Request $httpRequest)
75
    {
76
        $provider = $this->getProvider($provider);
77
78
        /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
79
        $redirectBinding = $this->get('surfnet_saml.http.redirect_binding');
80
        $gsspLoginService = $this->getGsspLoginService();
81
82
        $logger = $this->get('logger');
83
        $logger->notice('Received AuthnRequest, started processing');
84
85
        try {
86
            $proxyRequest = $gsspLoginService->singleSignOn($provider, $httpRequest);
87
        } catch (NotConnectedServiceProviderException $e) {
88
            throw new AccessDeniedHttpException();
89
        }
90
91
        return $redirectBinding->createResponseFor($proxyRequest);
92
    }
93
94
    /**
95
     * Start a GSSP single sign-on.
96
     *
97
     * The user has selected a second factor token and the token happens to be
98
     * a GSSP token. The SecondFactorController therefor did an internal
99
     * redirect (see SecondFactorController::verifyGssfAction) to this method.
100
     *
101
     * In this method, an authn request is created. This authn request is sent
102
     * directly to the remote GSSP SSO URL, and the response is handled in
103
     * consumeAssertionAction().
104
     *
105
     * @param string $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
106
     * @param string $subjectNameId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
107
     * @param string $responseContextServiceId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
108
     * @return \Symfony\Component\HttpFoundation\RedirectResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
109
     */
110
    public function sendSecondFactorVerificationAuthnRequestAction($provider, $subjectNameId, $responseContextServiceId)
111
    {
112
        $provider = $this->getProvider($provider);
113
114
        $gsspSecondFactorVerificationService = $this->getGsspSecondFactorVerificationService();
115
116
        $authnRequest = $gsspSecondFactorVerificationService->sendSecondFactorVerificationAuthnRequest(
117
            $provider,
118
            $subjectNameId,
119
            $responseContextServiceId
120
        );
121
122
        /** @var \Surfnet\SamlBundle\Http\RedirectBinding $redirectBinding */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
123
        $redirectBinding = $this->get('surfnet_saml.http.redirect_binding');
124
125
        return $redirectBinding->createResponseFor($authnRequest);
126
    }
127
128
    /**
129
     * Process an assertion received from the remote GSSP application.
130
     *
131
     * The GSSP application sent an assertion back to the gateway. When
132
     * successful, the user is sent back to:
133
     *
134
     *  1. in case of registration: back to the originating SP (SelfService or RA)
135
     *  2. in case of verification: internal redirect to SecondFactorController
136
     *
137
     * @param string $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
138
     * @param Request $httpRequest
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
139
     * @return \Symfony\Component\HttpFoundation\Response
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
140
     * @throws Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
141
     */
142
    public function consumeAssertionAction($provider, Request $httpRequest)
143
    {
144
        $provider = $this->getProvider($provider);
145
146
        $consumeAssertionService = $this->getGsspConsumeAssertionService();
147
        $proxyResponseFactory = $this->getProxyResponseFactory($provider);
148
149
        try {
150
            $response = $consumeAssertionService->consumeAssertion($provider, $httpRequest, $proxyResponseFactory);
151
        } catch (ResponseFailureException $e) {
152
            $response = $this->createResponseFailureResponse(
153
                $provider,
154
                $this->getDestination($provider->getStateHandler()),
155
                $this->getIssuer($provider->getStateHandler()),
156
                $e->getMessage()
157
            );
158
            return $this->renderSamlResponse('consume_assertion', $provider->getStateHandler(), $response);
159
        } catch (InvalidSubjectException $e) {
160
            return $this->renderSamlResponse(
161
                'recoverable_error',
162
                $provider->getStateHandler(),
163
                $this->createAuthnFailedResponse(
164
                    $provider,
165
                    $this->getDestination($provider->getStateHandler())
166
                )
167
            );
168
        } catch (SecondfactorVerificationRequiredException $e) {
169
            // The provider state handler has no access to the session object, hence we use the proxy state handler
170
            $stateHandler = $this->get('gateway.proxy.sso.state_handler');
171
            return $this->forward(
172
                'SurfnetStepupGatewayGatewayBundle:SecondFactor:gssfVerified',
173
                [
174
                    // The authentication mode is loaded from session, based on the request id
175
                    'authenticationMode' => $stateHandler->getAuthenticationModeForRequestId(
176
                        $consumeAssertionService->getReceivedRequestId()
177
                    ),
178
                ]
179
            );
180
        } catch (Exception $e) {
181
            throw $e;
182
        }
183
184
        return $this->renderSamlResponse('consume_assertion', $provider->getStateHandler(), $response);
185
    }
186
187
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
188
     * @param string $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
189
     * @return XMLResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
190
     */
191
    public function metadataAction($provider)
192
    {
193
        $provider = $this->getProvider($provider);
194
195
        /** @var \Surfnet\SamlBundle\Metadata\MetadataFactory $factory */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
196
        $factory = $this->get('gssp.provider.' . $provider->getName() . '.metadata.factory');
197
198
        return new XMLResponse($factory->generate());
199
    }
200
201
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
202
     * @param string $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
203
     * @return \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\Provider
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
204
     */
205
    private function getProvider($provider)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getProvider" must be prefixed with an underscore
Loading history...
206
    {
207
        /** @var \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\ProviderRepository $providerRepository */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
208
        $providerRepository = $this->get('gssp.provider_repository');
209
210
        if (!$providerRepository->has($provider)) {
211
            throw new NotFoundHttpException(
212
                sprintf('Requested GSSP "%s" does not exist or is not registered', $provider)
213
            );
214
        }
215
216
        return $providerRepository->get($provider);
217
    }
218
219
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
220
     * @param StateHandler $stateHandler
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
221
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
222
     */
223
    private function getDestination(StateHandler $stateHandler)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getDestination" must be prefixed with an underscore
Loading history...
224
    {
225
        if ($stateHandler->secondFactorVerificationRequested()) {
226
            // This can either be a SFO or 'regular' SSO authentication. Both use a ResponseContext service of their own
227
            $responseContextServiceId = $stateHandler->getResponseContextServiceId();
228
            // GSSP verification action, return to SP from GatewayController state!
229
            $destination = $this->get($responseContextServiceId)->getDestination();
0 ignored issues
show
Bug introduced by
It seems like $responseContextServiceId can also be of type null; however, parameter $id of Symfony\Bundle\Framework...oller\Controller::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

229
            $destination = $this->get(/** @scrutinizer ignore-type */ $responseContextServiceId)->getDestination();
Loading history...
230
        } else {
231
            // GSSP registration action, return to SP remembered in ssoAction().
232
            $serviceProvider = $this->getServiceProvider(
233
                $stateHandler->getRequestServiceProvider()
234
            );
235
236
            $destination = $serviceProvider->determineAcsLocation(
237
                $stateHandler->getRequestAssertionConsumerServiceUrl(),
238
                $this->get('logger')
239
            );
240
        }
241
242
        return $destination;
243
    }
244
245
    private function getIssuer(StateHandler $stateHandler): Issuer
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getIssuer()
Loading history...
Coding Style introduced by
Private method name "SamlProxyController::getIssuer" must be prefixed with an underscore
Loading history...
246
    {
247
        // This can either be a SFO or 'regular' SSO authentication. Both use a ResponseContext service of their own
248
        $responseContextServiceId = $stateHandler->getResponseContextServiceId();
249
        if (!$responseContextServiceId) {
250
            throw new RuntimeException(
251
                sprintf(
252
                    'Unable to find the ResponseContext service-id for this authentication or registration, ' .
253
                    'service-id provided was: "%s"',
254
                    $responseContextServiceId
255
                )
256
            );
257
        }
258
        // GSSP verification action, return to SP from GatewayController state!
259
        /** @var ResponseContext $responseService */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
260
        $responseService = $this->get($responseContextServiceId);
261
        return $responseService->getIssuer();
262
    }
263
264
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
265
     * @param string $view
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 7 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
266
     * @param StateHandler $stateHandler
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
267
     * @param SAMLResponse $response
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
268
     * @return Response
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
269
     */
270
    public function renderSamlResponse($view, StateHandler $stateHandler, SAMLResponse $response)
271
    {
272
        /** @var ResponseHelper $responseHelper */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
273
        $responseHelper = $this->get('second_factor_only.adfs.response_helper');
274
        $logger = $this->get('logger');
275
276
        $logger->notice(sprintf('Rendering SAML Response with view "%s"', $view));
277
278
        $parameters = [
279
            'acu' => $response->getDestination(),
280
            'response' => $this->getResponseAsXML($response),
281
            'relayState' => $stateHandler->getRelayState(),
282
        ];
283
        $responseContext = $this->getResponseContext('gateway.proxy.sfo.state_handler');
284
285
        // Test if we should add ADFS response parameters
286
        $inResponseTo = $responseContext->getInResponseTo();
287
        $isAdfsResponse = $responseHelper->isAdfsResponse($inResponseTo);
288
        $logger->notice(sprintf('Responding to "%s" an ADFS response? %s', $inResponseTo, $isAdfsResponse ? 'yes' : 'no'));
289
        if ($isAdfsResponse) {
290
            $adfsParameters = $responseHelper->retrieveAdfsParameters();
291
            $logMessage = 'Responding with additional ADFS parameters, in response to request: "%s", with view: "%s"';
292
            if ($response->isSuccess()) {
293
                $logMessage = 'Responding with an AuthnFailed SamlResponse with ADFS parameters, in response to AR: "%s", with view: "%s"';
294
            }
295
            $logger->notice(sprintf($logMessage, $inResponseTo, $view));
296
            $parameters['adfs'] = $adfsParameters;
297
            $parameters['acu'] = $responseContext->getDestinationForAdfs();
298
        }
299
300
        $response = parent::render(
301
            'SurfnetStepupGatewaySamlStepupProviderBundle:saml_proxy:' . $view . '.html.twig',
302
            $parameters
303
        );
304
305
        // clear the state so we can call again :)
306
        $stateHandler->clear();
307
308
        return $response;
309
    }
310
311
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
312
     * @param SAMLResponse $response
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
313
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
314
     */
315
    private function getResponseAsXML(SAMLResponse $response)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getResponseAsXML" must be prefixed with an underscore
Loading history...
316
    {
317
        return base64_encode($response->toUnsignedXML()->ownerDocument->saveXML());
0 ignored issues
show
Bug introduced by
The method saveXML() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

317
        return base64_encode($response->toUnsignedXML()->ownerDocument->/** @scrutinizer ignore-call */ saveXML());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
318
    }
319
320
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $provider should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $destination should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $issuer should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $message should have a doc-comment as per coding-style.
Loading history...
321
     * Response that indicates that an error occurred in the responder
322
     * (the gateway). Used to indicate that we could not process the
323
     * response we received from the upstream GSSP
324
     *
325
     * The correct Destination (where did the SAMLResponse originate from.
326
     * And the Issuer (who issued the response) are explicitly set on the response
327
     * allowing for correctly setting them.
328
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
329
    private function createResponseFailureResponse(
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::createResponseFailureResponse" must be prefixed with an underscore
Loading history...
330
        Provider $provider,
331
        string $destination,
332
        Issuer $issuer,
333
        string $message
334
    ): SAMLResponse {
335
        $response = $this->createResponse($provider, $destination);
336
        // Overwrite the issuer with the correct issuer for the saml failed response
337
        $response->setIssuer($issuer);
338
        $response->setStatus([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
339
            'Code' => Constants::STATUS_RESPONDER,
340
            'SubCode' => Constants::STATUS_AUTHN_FAILED,
341
            'Message' => $message
342
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
343
344
        return $response;
345
    }
346
347
    /**
348
     * Response that indicates that the authentication could not be performed correctly. In this context it means
349
     * that the upstream GSSP did not responsd with the same NameID as we request to authenticate in the AuthnRequest
350
     *
351
     * @param Provider $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
352
     * @param string $destination
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
353
     * @return SAMLResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
354
     */
355
    private function createAuthnFailedResponse(Provider $provider, $destination)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::createAuthnFailedResponse" must be prefixed with an underscore
Loading history...
356
    {
357
        $response = $this->createResponse($provider, $destination);
358
        $response->setStatus(
359
            [
360
                'Code' => Constants::STATUS_RESPONDER,
361
                'SubCode' => Constants::STATUS_AUTHN_FAILED,
362
            ]
363
        );
364
365
        return $response;
366
    }
367
368
    /**
369
     * Creates a standard response with default status Code (success)
370
     *
371
     * @param Provider $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
372
     * @param string $destination
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
373
     * @return SAMLResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
374
     */
375
    private function createResponse(Provider $provider, $destination)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::createResponse" must be prefixed with an underscore
Loading history...
376
    {
377
        $context = $this->getResponseContext();
378
        $response = new SAMLResponse();
379
        $response->setDestination($destination);
380
        $response->setIssuer($context->getIssuer());
381
        $response->setIssueInstant((new DateTime('now'))->getTimestamp());
382
        $response->setInResponseTo($provider->getStateHandler()->getRequestId());
383
384
        return $response;
385
    }
386
387
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
388
     * @param string $serviceProvider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
389
     * @return \Surfnet\StepupGateway\GatewayBundle\Entity\ServiceProvider
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
390
     */
391
    private function getServiceProvider($serviceProvider)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getServiceProvider" must be prefixed with an underscore
Loading history...
392
    {
393
        /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
394
         * @var \Surfnet\StepupGateway\SamlStepupProviderBundle\Provider\ConnectedServiceProviders $connectedServiceProviders
395
         */
396
        $connectedServiceProviders = $this->get('gssp.connected_service_providers');
397
        return $connectedServiceProviders->getConfigurationOf($serviceProvider);
398
    }
399
400
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
401
     * @return LoginService
402
     */
403
    private function getGsspLoginService()
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getGsspLoginService" must be prefixed with an underscore
Loading history...
404
    {
405
        return $this->get('gssp.service.gssp.login');
406
    }
407
408
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
409
     * @return SecondFactorVerificationService
410
     */
411
    private function getGsspSecondFactorVerificationService()
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getGsspSecondFactorVerificationService" must be prefixed with an underscore
Loading history...
412
    {
413
        return $this->get('gssp.service.gssp.second_factor_verification');
414
    }
415
416
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
417
     * @return ConsumeAssertionService
418
     */
419
    private function getGsspConsumeAssertionService()
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getGsspConsumeAssertionService" must be prefixed with an underscore
Loading history...
420
    {
421
        return $this->get('gssp.service.gssp.consume_assertion');
422
    }
423
424
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
425
     * @param Provider $provider
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
426
     * @return ProxyResponseFactory
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
427
     */
428
    private function getProxyResponseFactory(Provider $provider)
0 ignored issues
show
Coding Style introduced by
Private method name "SamlProxyController::getProxyResponseFactory" must be prefixed with an underscore
Loading history...
429
    {
430
        return $this->get('gssp.provider.' . $provider->getName() . '.response_proxy');
431
    }
432
433
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $mode should have a doc-comment as per coding-style.
Loading history...
434
     * @return \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext
435
     */
436
    public function getResponseContext($mode = 'gateway.proxy.sso.state_handler')
437
    {
438
        $stateHandler = $this->get($mode);
439
440
        $responseContextServiceId = $stateHandler->getResponseContextServiceId();
441
442
        if (!$responseContextServiceId) {
443
            return $this->get(GatewayController::RESPONSE_CONTEXT_SERVICE_ID);
444
        }
445
446
        return $this->get($responseContextServiceId);
447
    }
448
}
449