1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2017 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\SecondFactorOnlyBundle\Adfs; |
20
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
22
|
|
|
use Surfnet\StepupGateway\SecondFactorOnlyBundle\Adfs\ValueObject\Response as AdfsResponse; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The Adfs helper service is used to transform Adfs response. Wrapping the SFO response in an ADFS friendly response |
26
|
|
|
* format: |
27
|
|
|
* |
28
|
|
|
* AuthMethod: <AuthMethod> |
29
|
|
|
* Context: <Conext> |
30
|
|
|
* RequestId: <RequestId> |
31
|
|
|
* Response: <The "Response" that was received from the SFO endpoint> |
32
|
|
|
* |
33
|
|
|
* @package Surfnet\StepupGateway\SecondFactorOnlyBundle\Service |
34
|
|
|
*/ |
35
|
|
|
final class ResponseHelper |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** @var LoggerInterface */ |
39
|
|
|
private $logger; |
40
|
|
|
|
41
|
|
|
/** @var StateHandler */ |
42
|
|
|
private $stateHandler; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* ResponseHelper constructor. |
46
|
|
|
* @param StateHandler $stateHandler |
47
|
|
|
* @param LoggerInterface $logger |
48
|
|
|
*/ |
49
|
|
|
public function __construct(StateHandler $stateHandler, LoggerInterface $logger) |
50
|
|
|
{ |
51
|
|
|
$this->stateHandler = $stateHandler; |
52
|
|
|
$this->logger = $logger; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $originalRequestId |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public function isAdfsResponse($originalRequestId) |
60
|
|
|
{ |
61
|
|
|
return $this->stateHandler->hasMatchingRequestId($originalRequestId); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return AdfsResponse |
66
|
|
|
*/ |
67
|
|
|
public function retrieveAdfsParameters() |
68
|
|
|
{ |
69
|
|
|
$authMethod = $this->stateHandler->getAuthMethod(); |
70
|
|
|
$context = $this->stateHandler->getContext(); |
71
|
|
|
$requestId = $this->stateHandler->getRequestId(); |
72
|
|
|
$acsUrl = $this->stateHandler->getAssertionConsumerServiceUrl(); |
73
|
|
|
|
74
|
|
|
$this->logger->notice(sprintf('Retrieving ADFS Response parameters for RequestId: "%s"', $requestId)); |
75
|
|
|
return AdfsResponse::fromValues($authMethod, $context, $acsUrl); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|