1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2010 SURFnet B.V. |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting; |
19
|
|
|
|
20
|
|
|
use SAML2\Configuration\PrivateKey; |
21
|
|
|
use Surfnet\SamlBundle\Entity\IdentityProvider; |
22
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Assert; |
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\InvalidRemoteVettingIdentityProviderException; |
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RemoteVetting\Configuration\RemoteVettingConfiguration; |
25
|
|
|
|
26
|
|
|
class IdentityProviderFactory |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var IdentityProvider[] |
30
|
|
|
*/ |
31
|
|
|
private $identityProviders = []; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param RemoteVettingConfiguration $configuration |
35
|
|
|
*/ |
36
|
|
|
public function __construct(RemoteVettingConfiguration $configuration) |
37
|
|
|
{ |
38
|
|
|
foreach ($configuration->getRemoteVettingIdps() as $idp) { |
39
|
|
|
Assert::file($idp->getPrivateKey(), 'privateKey should be a file'); |
40
|
|
|
Assert::file($idp->getCertificateFile(), 'certificateFile should be a file'); |
41
|
|
|
|
42
|
|
|
$idpConfiguration = [ |
43
|
|
|
'name' => $idp->getName(), |
44
|
|
|
'entityId' => $idp->getEntityId(), |
45
|
|
|
'ssoUrl' => $idp->getSsoUrl(), |
46
|
|
|
'certificateFile' => $idp->getCertificateFile(), |
47
|
|
|
'privateKeys' => [new PrivateKey($idp->getPrivateKey(), PrivateKey::NAME_DEFAULT)], |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
// set idp |
51
|
|
|
$this->identityProviders[$idp->getSlug()] = new IdentityProvider($idpConfiguration); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param string $name |
57
|
|
|
* @return IdentityProvider |
58
|
|
|
*/ |
59
|
|
|
public function create($name) |
60
|
|
|
{ |
61
|
|
|
if (array_key_exists($name, $this->identityProviders)) { |
62
|
|
|
return $this->identityProviders[$name]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
throw new InvalidRemoteVettingIdentityProviderException(sprintf("Invalid IdP requested '%s'", $name)); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|