/
AuthenticationException.php
138 lines (124 loc) · 3.74 KB
/
AuthenticationException.php
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Security\Core\Exception;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
/**
* AuthenticationException is the base class for all authentication exceptions.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Alexander <iam.asm89@gmail.com>
*/
class AuthenticationException extends RuntimeException implements \Serializable
{
private $token;
/**
* Get the token.
*
* @return TokenInterface
*/
public function getToken()
{
return $this->token;
}
public function setToken(TokenInterface $token)
{
$this->token = $token;
}
/**
* {@inheritdoc}
*
* @final since Symfony 4.3, use getState() instead
*
* @internal since Symfony 4.3, use getState() instead
*/
public function serialize()
{
return $this->doSerialize($this->getState(), \func_num_args() ? \func_get_arg(0) : null);
}
/**
* {@inheritdoc}
*
* @final since Symfony 4.3, use setState() instead
*
* @internal since Symfony 4.3, use setState() instead
*/
public function unserialize($serialized)
{
$this->setState(\is_array($serialized) ? $serialized : unserialize($serialized));
}
/**
* Returns all the necessary state of the object for serialization purposes.
*
* There is no need to serialize any entry, they should be returned as-is.
* If you extend this method, keep in mind you MUST guarantee parent data is present in the state.
* Here is an example of how to extend this method:
* <code>
* protected function getState(): array
* {
* return [$this->childAttribute, parent::getState()];
* }
* </code>
*
* @see setState()
*/
protected function getState(): array
{
return [$this->token, $this->code, $this->message, $this->file, $this->line];
}
/**
* Restores the object state from an array given by getState().
*
* There is no need to unserialize any entry in $data, they are already ready-to-use.
* If you extend this method, keep in mind you MUST pass the parent data to its respective class.
* Here is an example of how to extend this method:
* <code>
* protected function setState(array $data)
* {
* [$this->childAttribute, $parentData] = $data;
* parent::setState($parentData);
* }
* </code>
*
* @see getState()
*/
protected function setState(array $data)
{
[$this->token, $this->code, $this->message, $this->file, $this->line] = $data;
}
/**
* @internal
*/
protected function doSerialize($serialized, $isCalledFromOverridingMethod)
{
if (null === $isCalledFromOverridingMethod) {
$trace = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 3);
$isCalledFromOverridingMethod = isset($trace[2]['function'], $trace[2]['object']) && 'serialize' === $trace[2]['function'] && $this === $trace[2]['object'];
}
return $isCalledFromOverridingMethod ? $serialized : serialize($serialized);
}
/**
* Message key to be used by the translation component.
*
* @return string
*/
public function getMessageKey()
{
return 'An authentication exception occurred.';
}
/**
* Message data to be used by the translation component.
*
* @return array
*/
public function getMessageData()
{
return [];
}
}