Shib.php 1.42 KB
Newer Older
1
2
3
4
<?php

namespace UnicaenAuth\Authentication\Storage;

5
use UnicaenAuth\Authentication\SessionIdentity;
6
use UnicaenAuth\Entity\Shibboleth\ShibUser;
7
use UnicaenAuth\Service\Traits\ShibServiceAwareTrait;
8
9
10
11
12
13

/**
 * Shibboleth authentication storage.
 *
 * @author Unicaen
 */
14
class Shib extends AbstractStorage
15
{
16
    use ShibServiceAwareTrait;
17

18
19
    const TYPE = \UnicaenAuth\Authentication\Adapter\Shib::TYPE;

20
    /**
21
     * @var string
22
     */
23
    protected $type = self::TYPE;
24
25
26
27
28
29

    /**
     * @var ShibUser
     */
    protected $resolvedIdentity;

30
31
32
    /**
     * @return bool
     */
33
    protected function isEnabled(): bool
34
35
36
37
38
39
    {
        $config = $this->moduleOptions->getShib();

        return isset($config['enabled']) && (bool) $config['enabled'];
    }

40
41
42
    /**
     * @return null|ShibUser
     */
43
    protected function findIdentity(): ?ShibUser
44
    {
45
46
47
        /** @var SessionIdentity $sessionIdentity */
        $sessionIdentity = $this->storage->read();
        $username = $sessionIdentity->getUsername();
48

49
50
51
52
53
//        // L'identité en session doit ressembler à un EPPN.
//        $looksLikeEppn = strpos($username, '@') !== false;
//        if (! $looksLikeEppn) {
//            return null;
//        }
54

55
        return $this->shibService->getAuthenticatedUser();
56
    }
57
58
59
60
61
62
63
64
65
66

    /**
     * @inheritDoc
     */
    public function clear(ChainEvent $e)
    {
        parent::clear($e);

        $this->shibService->deactivateUsurpation();
    }
67
}