* * 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\HttpKernel\Attribute\WithHttpStatus; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; /** * AuthenticationException is the base class for all authentication exceptions. * * @author Fabien Potencier * @author Alexander */ #[WithHttpStatus(401)] class AuthenticationException extends RuntimeException { private ?TokenInterface $token = null; public function getToken(): ?TokenInterface { return $this->token; } public function setToken(TokenInterface $token): void { $this->token = $token; } /** * 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: * * public function __serialize(): array * { * return [$this->childAttribute, parent::__serialize()]; * } * * * @see __unserialize() */ public function __serialize(): array { return [$this->token, $this->code, $this->message, $this->file, $this->line]; } /** * Restores the object state from an array given by __serialize(). * * 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: * * public function __unserialize(array $data): void * { * [$this->childAttribute, $parentData] = $data; * parent::__unserialize($parentData); * } * * * @see __serialize() */ public function __unserialize(array $data): void { [$this->token, $this->code, $this->message, $this->file, $this->line] = $data; } /** * Message key to be used by the translation component. */ public function getMessageKey(): string { return 'An authentication exception occurred.'; } /** * Message data to be used by the translation component. */ public function getMessageData(): array { return []; } }