|
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 RuntimeException; |
|
22
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactor; |
|
23
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Saml\ResponseContext; |
|
24
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Service\SecondFactorService; |
|
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
26
|
|
|
|
|
27
|
|
|
class GssfController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
public function verifyGssfAction() |
|
30
|
|
|
{ |
|
31
|
|
|
/** @var ResponseContext $responseContext */ |
|
32
|
|
|
$context = $this->get( |
|
33
|
|
|
$this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
|
34
|
|
|
); |
|
35
|
|
|
$originalRequestId = $context->getInResponseTo(); |
|
36
|
|
|
|
|
37
|
|
|
/** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
|
38
|
|
|
$logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
|
39
|
|
|
$logger->info('Received request to verify GSSF'); |
|
40
|
|
|
|
|
41
|
|
|
$selectedSecondFactor = $this->get('gateway.service.require_selected_factor') |
|
42
|
|
|
->requireSelectedSecondFactor($logger); |
|
43
|
|
|
|
|
44
|
|
|
$logger->info(sprintf( |
|
45
|
|
|
'Selected GSSF "%s" for verfication, forwarding to Saml handling', |
|
46
|
|
|
$selectedSecondFactor |
|
47
|
|
|
)); |
|
48
|
|
|
|
|
49
|
|
|
$secondFactorService = $this->get('gateway.service.second_factor_service'); |
|
50
|
|
|
$secondFactor = $secondFactorService->findByUuid($selectedSecondFactor); |
|
51
|
|
|
if (!$secondFactor) { |
|
52
|
|
|
$logger->critical(sprintf( |
|
53
|
|
|
'Requested verification of GSSF "%s", however that Second Factor no longer exists', |
|
54
|
|
|
$selectedSecondFactor |
|
55
|
|
|
)); |
|
56
|
|
|
|
|
57
|
|
|
throw new RuntimeException('Verification of selected second factor that no longer exists'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $this->forward( |
|
61
|
|
|
'SurfnetStepupGatewaySamlStepupProviderBundle:SamlProxy:sendSecondFactorVerificationAuthnRequest', |
|
62
|
|
|
[ |
|
63
|
|
|
'provider' => $secondFactor->secondFactorType, |
|
64
|
|
|
'subjectNameId' => $secondFactor->secondFactorIdentifier |
|
65
|
|
|
] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function gssfVerifiedAction() |
|
70
|
|
|
{ |
|
71
|
|
|
/** @var ResponseContext $responseContext */ |
|
72
|
|
|
$context = $this->get( |
|
73
|
|
|
$this->get('gateway.proxy.state_handler')->getResponseContextServiceId() |
|
74
|
|
|
); |
|
75
|
|
|
$originalRequestId = $context->getInResponseTo(); |
|
76
|
|
|
|
|
77
|
|
|
/** @var \Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger $logger */ |
|
78
|
|
|
$logger = $this->get('surfnet_saml.logger')->forAuthentication($originalRequestId); |
|
79
|
|
|
$logger->info('Attempting to mark GSSF as verified'); |
|
80
|
|
|
|
|
81
|
|
|
$selectedSecondFactor = $this->get('gateway.service.require_selected_factor') |
|
82
|
|
|
->requireSelectedSecondFactor($logger); |
|
83
|
|
|
|
|
84
|
|
|
/** @var SecondFactor $secondFactor */ |
|
85
|
|
|
$secondFactor = $this->get('gateway.service.second_factor_service')->findByUuid($selectedSecondFactor); |
|
86
|
|
|
if (!$secondFactor) { |
|
87
|
|
|
$logger->critical(sprintf( |
|
88
|
|
|
'Verification of GSSF "%s" succeeded, however that Second Factor no longer exists', |
|
89
|
|
|
$selectedSecondFactor |
|
90
|
|
|
)); |
|
91
|
|
|
|
|
92
|
|
|
throw new RuntimeException('Verification of selected second factor that no longer exists'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$context->markSecondFactorVerified(); |
|
96
|
|
|
$this->get('gateway.authentication_logger')->logSecondFactorAuthentication($originalRequestId); |
|
97
|
|
|
|
|
98
|
|
|
$logger->info(sprintf( |
|
99
|
|
|
'Marked GSSF "%s" as verified, forwarding to Gateway controller to respond', |
|
100
|
|
|
$selectedSecondFactor |
|
101
|
|
|
)); |
|
102
|
|
|
|
|
103
|
|
|
return $this->forward($context->getResponseAction()); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|