1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2020 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\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Configuration; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Assert; |
22
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\InvalidRemoteVettingIdentityProviderException; |
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Dto\RemoteVettingIdenityProviderDto; |
24
|
|
|
|
25
|
|
|
class RemoteVettingConfiguration |
26
|
|
|
{ |
27
|
|
|
private $publicKey; |
28
|
|
|
|
29
|
|
|
private $location; |
30
|
|
|
|
31
|
|
|
private $idps = []; |
32
|
|
|
|
33
|
|
|
private $attributeMapping = []; |
34
|
|
|
|
35
|
|
|
public function __construct(string $privateKey, array $configurationSettings, array $remoteVettingIdpConfig) |
36
|
|
|
{ |
37
|
|
|
Assert::string($privateKey, 'privateKey should be a string'); |
38
|
|
|
Assert::file($privateKey, 'privateKey should be a file'); |
39
|
|
|
|
40
|
|
|
Assert::string($configurationSettings['encryption_public_key'], 'identity_encryption_configuration.encryption_public_key should be a string'); |
41
|
|
|
Assert::string($configurationSettings['storage_location'], 'identity_encryption_configuration.storage_location should be a string'); |
42
|
|
|
|
43
|
|
|
$this->publicKey = $configurationSettings['encryption_public_key']; |
44
|
|
|
$this->location = $configurationSettings['storage_location']; |
45
|
|
|
|
46
|
|
|
foreach ($remoteVettingIdpConfig as $idpConfig) { |
47
|
|
|
$idpConfig['privateKey'] = $privateKey; |
48
|
|
|
|
49
|
|
|
$idp = RemoteVettingIdenityProviderDto::create($idpConfig); |
50
|
|
|
$this->idps[$idp->getSlug()] = $idp; |
51
|
|
|
|
52
|
|
|
Assert::keyExists($idpConfig, 'attributeMapping', sprintf('attributeMapping should be set: %s', $idp->getSlug())); |
53
|
|
|
Assert::isArray($idpConfig['attributeMapping'], 'attributeMapping should be an array'); |
54
|
|
|
Assert::allString($idpConfig['attributeMapping'], 'attributeMapping should consist of strings'); |
55
|
|
|
|
56
|
|
|
$this->attributeMapping[$idp->getSlug()] = $idpConfig['attributeMapping']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getLocation() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
return $this->location; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getPublicKey() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
return $this->publicKey; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return RemoteVettingIdenityProviderDto[] |
72
|
|
|
*/ |
73
|
|
|
public function getRemoteVettingIdps(): array |
74
|
|
|
{ |
75
|
|
|
return $this->idps; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getRemoteVettingIdp(string $name): RemoteVettingIdenityProviderDto |
79
|
|
|
{ |
80
|
|
|
if (array_key_exists($name, $this->idps)) { |
81
|
|
|
return $this->idps[$name]; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
throw new InvalidRemoteVettingIdentityProviderException(sprintf("Invalid IdP requested '%s'", $name)); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param string |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getAttributeMapping($name) |
92
|
|
|
{ |
93
|
|
|
if (array_key_exists($name, $this->attributeMapping)) { |
94
|
|
|
return $this->attributeMapping[$name]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
throw new InvalidRemoteVettingIdentityProviderException(sprintf("Invalid IdP requested '%s'", $name)); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.