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