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
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\StepupGateway\GatewayBundle\Controller; |
20
|
|
|
|
21
|
|
|
use SAML2_Const; |
22
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext; |
23
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
24
|
|
|
|
25
|
|
|
class FailureController extends Controller |
26
|
|
|
{ |
27
|
|
View Code Duplication |
public function sendLoaCannotBeGivenAction() |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
/** @var ResponseContext $responseContext */ |
30
|
|
|
$responseContext = $this->get( |
31
|
|
|
$this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
32
|
|
|
); |
33
|
|
|
$originalRequestId = $responseContext->getInResponseTo(); |
34
|
|
|
|
35
|
|
|
/** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
36
|
|
|
$logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
37
|
|
|
$logger->notice('Loa cannot be given, creating Response with NoAuthnContext status'); |
38
|
|
|
|
39
|
|
|
/** @var \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseBuilder $responseBuilder */ |
40
|
|
|
$responseBuilder = $this->get('gateway.proxy.response_builder'); |
41
|
|
|
|
42
|
|
|
$response = $responseBuilder |
43
|
|
|
->createNewResponse($responseContext) |
44
|
|
|
->setResponseStatus(SAML2_Const::STATUS_RESPONDER, SAML2_Const::STATUS_NO_AUTHN_CONTEXT) |
45
|
|
|
->get(); |
46
|
|
|
|
47
|
|
|
$logger->notice(sprintf( |
48
|
|
|
'Responding to request "%s" with response based on response from the remote IdP with response "%s"', |
49
|
|
|
$responseContext->getInResponseTo(), |
50
|
|
|
$response->getId() |
51
|
|
|
)); |
52
|
|
|
|
53
|
|
|
$responseRendering = $this->get('gateway.service.saml_response'); |
54
|
|
|
return $responseRendering->renderResponse($responseContext, $response); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
public function sendAuthenticationCancelledByUserAction() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
/** @var ResponseContext $responseContext */ |
60
|
|
|
$responseContext = $this->get( |
61
|
|
|
$this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
62
|
|
|
); |
63
|
|
|
$originalRequestId = $responseContext->getInResponseTo(); |
64
|
|
|
|
65
|
|
|
/** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
66
|
|
|
$logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
67
|
|
|
$logger->notice('Authentication was cancelled by the user, creating Response with AuthnFailed status'); |
68
|
|
|
|
69
|
|
|
/** @var \Surfnet\StepupGateway\GatewayBundle\Saml\ResponseBuilder $responseBuilder */ |
70
|
|
|
$responseBuilder = $this->get('gateway.proxy.response_builder'); |
71
|
|
|
|
72
|
|
|
$response = $responseBuilder |
73
|
|
|
->createNewResponse($responseContext) |
74
|
|
|
->setResponseStatus( |
75
|
|
|
SAML2_Const::STATUS_RESPONDER, |
76
|
|
|
SAML2_Const::STATUS_AUTHN_FAILED, |
77
|
|
|
'Authentication cancelled by user' |
78
|
|
|
) |
79
|
|
|
->get(); |
80
|
|
|
|
81
|
|
|
$logger->notice(sprintf( |
82
|
|
|
'Responding to request "%s" with response based on response from the remote IdP with response "%s"', |
83
|
|
|
$responseContext->getInResponseTo(), |
84
|
|
|
$response->getId() |
85
|
|
|
)); |
86
|
|
|
|
87
|
|
|
$responseRendering = $this->get('gateway.service.saml_response'); |
88
|
|
|
return $responseRendering->renderResponse($responseContext, $response); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.