Completed
Push — 8.7 ( b6d8c1...3ac046 )
by Markus
06:49
created

OwnContainer::getOwnEntityDescriptorProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 16
rs 9.9332
cc 2
nc 2
nop 0
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