|
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\StepupMiddleware\GatewayBundle\Entity; |
|
20
|
|
|
|
|
21
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
22
|
|
|
use Ramsey\Uuid\Uuid; |
|
23
|
|
|
use Surfnet\StepupMiddleware\GatewayBundle\Exception\RuntimeException; |
|
24
|
|
|
use function is_string; |
|
25
|
|
|
|
|
26
|
|
|
#[ORM\Table] |
|
27
|
|
|
#[ORM\UniqueConstraint(name: 'unq_saml_entity_entity_id_type', columns: ['entity_id', 'type'])] |
|
28
|
|
|
#[ORM\Entity(repositoryClass: SamlEntityRepository::class)] |
|
29
|
|
|
class SamlEntity |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Constants denoting the type of SamlEntity. Also used in the gateway to make that distinction |
|
33
|
|
|
*/ |
|
34
|
|
|
public const TYPE_IDP = 'idp'; |
|
35
|
|
|
public const TYPE_SP = 'sp'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
#[ORM\Id] |
|
41
|
|
|
#[ORM\Column(length: 36)] |
|
42
|
|
|
public string $id; |
|
43
|
|
|
|
|
44
|
|
|
private function __construct( |
|
45
|
|
|
#[ORM\Column] |
|
46
|
|
|
public string $entityId, |
|
47
|
|
|
#[ORM\Column] |
|
48
|
|
|
public string $type, |
|
49
|
|
|
#[ORM\Column(type: 'text')] |
|
50
|
|
|
public string $configuration, |
|
51
|
|
|
) { |
|
52
|
|
|
$this->id = (string)Uuid::uuid4(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static function createServiceProvider(string $entityId, array $configuration): self |
|
56
|
|
|
{ |
|
57
|
|
|
$encodedConfiguration = json_encode($configuration); |
|
58
|
|
|
if (!is_string($encodedConfiguration)) { |
|
|
|
|
|
|
59
|
|
|
throw new RuntimeException('Unable to json_encode the configuration array in SamlEntity::createServiceProvider'); |
|
60
|
|
|
} |
|
61
|
|
|
return new self($entityId, self::TYPE_SP, $encodedConfiguration); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function createIdentityProvider(string $entityId, array $configuration): self |
|
65
|
|
|
{ |
|
66
|
|
|
$encodedConfiguration = json_encode($configuration); |
|
67
|
|
|
if (!is_string($encodedConfiguration)) { |
|
|
|
|
|
|
68
|
|
|
throw new RuntimeException('Unable to json_encode the configuration array in SamlEntity::createServiceProvider'); |
|
69
|
|
|
} |
|
70
|
|
|
return new self($entityId, self::TYPE_IDP, $encodedConfiguration); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|