File size: 2,025 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

namespace Mautic\UserBundle\Security\Authentication\Token;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Guard\Token\GuardTokenInterface;

class PluginToken extends AbstractToken implements GuardTokenInterface
{
    private ?string $providerKey;

    /**
     * @param UserInterface|string|null $user
     * @param array<string>             $roles
     */
    public function __construct(
        ?string $providerKey,
        private ?string $authenticatingService = null,
        $user = null,
        private string $credentials = '',
        array $roles = [],
        private ?Response $response = null
    ) {
        parent::__construct($roles);

        if ('' === $providerKey) {
            throw new \InvalidArgumentException('$providerKey must not be empty.');
        }

        if (null !== $user) {
            $this->setUser($user);
        }
        $this->providerKey           = $providerKey;

        $this->setAuthenticated(count($roles) > 0);
    }

    public function getCredentials(): string
    {
        return $this->credentials;
    }

    public function getProviderKey(): ?string
    {
        return $this->providerKey;
    }

    public function getAuthenticatingService(): ?string
    {
        return $this->authenticatingService;
    }

    public function getResponse(): ?Response
    {
        return $this->response;
    }

    /**
     * @return array<int, mixed>
     */
    public function __serialize(): array
    {
        return array_merge([$this->authenticatingService, $this->credentials, $this->providerKey, parent::__serialize()]);
    }

    /**
     * @param array<int, mixed> $data
     */
    public function __unserialize(array $data): void
    {
        [$this->authenticatingService, $this->credentials, $this->providerKey, $parentArray] = $data;
        parent::__unserialize($parentArray);
    }
}