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