1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2017 SURFnet B.V. |
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\Pdp; |
20
|
|
|
|
21
|
|
|
use GuzzleHttp\ClientInterface; |
22
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Pdp\Dto\Request; |
23
|
|
|
use Surfnet\StepupGateway\GatewayBundle\Pdp\Dto\Response; |
24
|
|
|
use Webmozart\Assert\Assert; |
25
|
|
|
|
26
|
|
|
final class PdpClient implements PdpClientInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var ClientInterface |
30
|
|
|
*/ |
31
|
|
|
private $httpClient; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
private $policyDecisionPointUrl; |
37
|
|
|
|
38
|
|
|
public function __construct( |
39
|
|
|
ClientInterface $httpClient, |
40
|
|
|
$policyDecisionPointUrl |
41
|
|
|
) { |
42
|
|
|
Assert::string($policyDecisionPointUrl, 'Path to PolicyDecisionPoint must be a string'); |
43
|
|
|
|
44
|
|
|
$this->httpClient = $httpClient; |
45
|
|
|
$this->policyDecisionPointUrl = $policyDecisionPointUrl; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param Request $request |
50
|
|
|
* @return PolicyDecisionInterface |
51
|
|
|
*/ |
52
|
|
|
public function requestDecisionFor(Request $request) |
53
|
|
|
{ |
54
|
|
|
$response = $this->httpClient->request( |
55
|
|
|
'POST', |
56
|
|
|
$this->policyDecisionPointUrl, |
57
|
|
|
[ |
58
|
|
|
'json' => $request, |
59
|
|
|
'headers' => [ |
60
|
|
|
'Accept' => 'application/json', |
61
|
|
|
], |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
return PolicyDecision::fromResponse( |
66
|
|
|
Response::fromData( |
67
|
|
|
json_decode($response->getBody(), true) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|