|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DMK\MKSamlAuth\EntityDescriptor; |
|
6
|
|
|
|
|
7
|
|
|
use LightSaml\Model\Metadata\EntityDescriptor; |
|
8
|
|
|
use LightSaml\Model\Metadata\IdpSsoDescriptor; |
|
9
|
|
|
use LightSaml\Model\Metadata\SingleSignOnService; |
|
10
|
|
|
use LightSaml\Model\Metadata\SpSsoDescriptor; |
|
11
|
|
|
use LightSaml\Model\XmlDSig\SignatureStringReader; |
|
12
|
|
|
use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; |
|
13
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
14
|
|
|
|
|
15
|
|
|
class SpEntityDescriptorStore implements EntityDescriptorStoreInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var ConnectionPool |
|
19
|
|
|
*/ |
|
20
|
|
|
private $pool; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(ConnectionPool $pool) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->pool = $pool; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function get($entityId) |
|
28
|
|
|
{ |
|
29
|
|
|
$conn = $this->pool->getConnectionForTable('tx_mksamlauth_domain_model_identityprovider'); |
|
30
|
|
|
|
|
31
|
|
|
$qb = $conn->createQueryBuilder(); |
|
32
|
|
|
$qb->select('i.*'); |
|
33
|
|
|
$qb->from('tx_mksamlauth_domain_model_identityprovider', 'i'); |
|
34
|
|
|
$qb->where($qb->expr()->eq('i.name', ':id')); |
|
35
|
|
|
$qb->setParameter(':id', $entityId); |
|
36
|
|
|
|
|
37
|
|
|
$row = $qb->execute()->fetch(); |
|
38
|
|
|
|
|
39
|
|
|
return $row ? $this->map($row) : null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function has($entityId) |
|
43
|
|
|
{ |
|
44
|
|
|
return null !== $this->get($entityId); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function all() |
|
48
|
|
|
{ |
|
49
|
|
|
$conn = $this->pool->getConnectionForTable('tx_mksamlauth_domain_model_identityprovider'); |
|
50
|
|
|
|
|
51
|
|
|
$qb = $conn->createQueryBuilder(); |
|
52
|
|
|
$qb->select('i.*'); |
|
53
|
|
|
$qb->from('tx_mksamlauth_domain_model_identityprovider', 'i'); |
|
54
|
|
|
$qb->groupBy('i.name'); |
|
55
|
|
|
|
|
56
|
|
|
$result = []; |
|
57
|
|
|
|
|
58
|
|
|
foreach ($qb->execute()->fetchAll() as $row) { |
|
59
|
|
|
$result[] = $this->map($row); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $result; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function map(array $row): EntityDescriptor |
|
66
|
|
|
{ |
|
67
|
|
|
$descriptor = new SpSsoDescriptor(); |
|
68
|
|
|
$descriptor->addAssertionConsumerService($row['name']); |
|
69
|
|
|
|
|
70
|
|
|
$entityDescriptor = new EntityDescriptor( |
|
71
|
|
|
$row['idp_entity_id'], |
|
72
|
|
|
[$descriptor] |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$entityDescriptor->setSignature(new SignatureStringReader($row['idp_certificate'])); |
|
76
|
|
|
|
|
77
|
|
|
return $entityDescriptor; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|