Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a0c2dd8

Browse filesBrowse files
committed
feature #36656 [Security/Core] Add CustomUserMessageAccountStatusException (VincentLanglet)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Security/Core] Add CustomUserMessageAccountStatusException | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT | Doc PR | Not really needed When implementing the `UserCheckerInterface`, we can throw `AccountStatusException`. Similar to `CustomUserMessageAuthenticationException`, this exception allow to throw an `AccountStatusException` with a custom message. Commits ------- 9233efb Add CustomUserMessageAccountStatusException
2 parents c2cc993 + 9233efb commit a0c2dd8
Copy full SHA for a0c2dd8

File tree

2 files changed

+76
-0
lines changed
Filter options

2 files changed

+76
-0
lines changed

‎src/Symfony/Component/Security/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Added `LogoutEvent` to allow custom logout listeners.
1111
* Deprecated `LogoutSuccessHandlerInterface` and `LogoutHandlerInterface` in favor of listening on the `LogoutEvent`.
1212
* Added experimental new security using `Http\Authenticator\AuthenticatorInterface`, `Http\Authentication\AuthenticatorManager` and `Http\Firewall\AuthenticatorManagerListener`.
13+
* Added `CustomUserMessageAccountStatusException` to be used when extending `UserCheckerInterface`
1314

1415
5.0.0
1516
-----
+75Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Exception;
13+
14+
/**
15+
* An authentication exception caused by the user account status
16+
* where you can control the message shown to the user.
17+
*
18+
* Be sure that the message passed to this exception is something that
19+
* can be shown safely to your user. In other words, avoid catching
20+
* other exceptions and passing their message directly to this class.
21+
*
22+
* @author Vincent Langlet <vincentlanglet@github.com>
23+
*/
24+
class CustomUserMessageAccountStatusException extends AccountStatusException
25+
{
26+
private $messageKey;
27+
28+
private $messageData = [];
29+
30+
public function __construct(string $message = '', array $messageData = [], int $code = 0, \Throwable $previous = null)
31+
{
32+
parent::__construct($message, $code, $previous);
33+
34+
$this->setSafeMessage($message, $messageData);
35+
}
36+
37+
/**
38+
* Set a message that will be shown to the user.
39+
*
40+
* @param string $messageKey The message or message key
41+
* @param array $messageData Data to be passed into the translator
42+
*/
43+
public function setSafeMessage(string $messageKey, array $messageData = [])
44+
{
45+
$this->messageKey = $messageKey;
46+
$this->messageData = $messageData;
47+
}
48+
49+
public function getMessageKey()
50+
{
51+
return $this->messageKey;
52+
}
53+
54+
public function getMessageData()
55+
{
56+
return $this->messageData;
57+
}
58+
59+
/**
60+
* {@inheritdoc}
61+
*/
62+
public function __serialize(): array
63+
{
64+
return [parent::__serialize(), $this->messageKey, $this->messageData];
65+
}
66+
67+
/**
68+
* {@inheritdoc}
69+
*/
70+
public function __unserialize(array $data): void
71+
{
72+
[$parentData, $this->messageKey, $this->messageData] = $data;
73+
parent::__unserialize($parentData);
74+
}
75+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.