|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DMK\MKSamlAuth\Container; |
|
6
|
|
|
|
|
7
|
|
|
use DMK\MKSamlAuth\Repository\IdentityProviderRepository; |
|
8
|
|
|
use DMK\MKSamlAuth\Store\CredentialStore; |
|
9
|
|
|
use LightSaml\Build\Container\OwnContainerInterface; |
|
10
|
|
|
use LightSaml\Builder\EntityDescriptor\SimpleEntityDescriptorBuilder; |
|
11
|
|
|
use LightSaml\Credential\CredentialInterface; |
|
12
|
|
|
use LightSaml\Credential\KeyHelper; |
|
13
|
|
|
use LightSaml\Credential\X509Certificate; |
|
14
|
|
|
use LightSaml\Provider\EntityDescriptor\EntityDescriptorProviderInterface; |
|
15
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
16
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
|
17
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
18
|
|
|
|
|
19
|
|
|
class OwnContainer implements OwnContainerInterface, SingletonInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var SingletonContainer |
|
23
|
|
|
*/ |
|
24
|
|
|
private $container; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var IdentityProviderRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
private $repository; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct(IdentityProviderRepository $repository, SingletonContainer $container) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->container = $container; |
|
33
|
|
|
$this->repository = $repository; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getOwnEntityDescriptorProvider() |
|
37
|
|
|
{ |
|
38
|
|
|
$record = $this->repository->findByHostname(GeneralUtility::getIndpEnv('HTTP_HOST')); |
|
39
|
|
|
|
|
40
|
|
|
if (false === is_array($record)) { |
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$certificate = new X509Certificate(); |
|
45
|
|
|
$certificate->loadPem($record['certificate']); |
|
46
|
|
|
|
|
47
|
|
|
return new SimpleEntityDescriptorBuilder( |
|
48
|
|
|
$record['name'], |
|
49
|
|
|
$record['name'], |
|
50
|
|
|
$record['url'], |
|
51
|
|
|
$certificate |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getOwnCredentials() |
|
56
|
|
|
{ |
|
57
|
|
|
$record = $this->repository->findByHostname(GeneralUtility::getIndpEnv('HTTP_HOST')); |
|
58
|
|
|
|
|
59
|
|
|
if (false === is_array($record)) { |
|
60
|
|
|
return null; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** @var CredentialStore $store */ |
|
64
|
|
|
$store = $this->container->getInstance(CredentialStore::class); |
|
65
|
|
|
|
|
66
|
|
|
return $store->getByEntityId($record['name']); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|