Skip to content

Commit 39da27a

Browse files
committed
[Security] Removed get/setExtraInformation, added get/set(Token|User)
1 parent 837ae15 commit 39da27a

File tree

8 files changed

+55
-18
lines changed

8 files changed

+55
-18
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ CHANGELOG
3535
* [BC BREAK] moved the default logout success handling to a separate class. The
3636
order of arguments in the constructor of `LogoutListener` has changed.
3737
* [BC BREAK] The constructor of `AuthenticationException` and all child
38-
classes now matches the constructor of `\Exception`. Extra information
39-
should be passed via the `setExtraInformation` setter.
38+
classes now matches the constructor of `\Exception`. The extra information
39+
getters and setters are removed. There are now dedicated getters/setters for
40+
token (`AuthenticationException') and user (`AccountStatusException`).

src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function authenticate(TokenInterface $token)
7777
break;
7878
}
7979
} catch (AccountStatusException $e) {
80-
$e->setExtraInformation($token);
80+
$e->setToken($token);
8181

8282
throw $e;
8383
} catch (AuthenticationException $e) {
@@ -105,7 +105,7 @@ public function authenticate(TokenInterface $token)
105105
$this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException));
106106
}
107107

108-
$lastException->setExtraInformation($token);
108+
$lastException->setToken($token);
109109

110110
throw $lastException;
111111
}

src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function retrieveUser($username, UsernamePasswordToken $token)
9191
throw $notFound;
9292
} catch (\Exception $repositoryProblem) {
9393
$ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
94-
$ex->setExtraInformation($token);
94+
$ex->setToken($token);
9595
throw $ex;
9696
}
9797
}

src/Symfony/Component/Security/Core/Exception/AccountStatusException.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,36 @@
1111

1212
namespace Symfony\Component\Security\Core\Exception;
1313

14+
use Symfony\Component\Security\Core\User\UserInterface;
15+
1416
/**
1517
* AccountStatusException is the base class for authentication exceptions
1618
* caused by the user account status.
1719
*
1820
* @author Fabien Potencier <fabien@symfony.com>
21+
* @author Alexander <iam.asm89@gmail.com>
1922
*/
2023
abstract class AccountStatusException extends AuthenticationException
2124
{
25+
private $user;
26+
27+
/**
28+
* Get the user.
29+
*
30+
* @return UserInterface
31+
*/
32+
public function getUser()
33+
{
34+
return $this->user;
35+
}
36+
37+
/**
38+
* Set the user.
39+
*
40+
* @param UserInterface $user
41+
*/
42+
public function setUser(UserInterface $user)
43+
{
44+
$this->user = $user;
45+
}
2246
}

src/Symfony/Component/Security/Core/Exception/AuthenticationException.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Security\Core\Exception;
1313

14+
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
1416
/**
1517
* AuthenticationException is the base class for all authentication exceptions.
1618
*
@@ -19,16 +21,26 @@
1921
*/
2022
class AuthenticationException extends \RuntimeException implements \Serializable
2123
{
22-
private $extraInformation;
24+
private $token;
2325

24-
public function getExtraInformation()
26+
/**
27+
* Get the token.
28+
*
29+
* @return TokenInterface
30+
*/
31+
public function getToken()
2532
{
26-
return $this->extraInformation;
33+
return $this->token;
2734
}
2835

29-
public function setExtraInformation($extraInformation)
36+
/**
37+
* Set the token.
38+
*
39+
* @param TokenInterface $token
40+
*/
41+
public function setToken(TokenInterface $token)
3042
{
31-
$this->extraInformation = $extraInformation;
43+
$this->token = $token;
3244
}
3345

3446
public function serialize()

src/Symfony/Component/Security/Core/User/UserChecker.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function checkPreAuth(UserInterface $user)
3434

3535
if (!$user->isCredentialsNonExpired()) {
3636
$ex = new CredentialsExpiredException('User credentials have expired.');
37-
$ex->setExtraInformation($user);
37+
$ex->setUser($user);
3838
throw $ex;
3939
}
4040
}
@@ -50,19 +50,19 @@ public function checkPostAuth(UserInterface $user)
5050

5151
if (!$user->isAccountNonLocked()) {
5252
$ex = new LockedException('User account is locked.');
53-
$ex->setExtraInformation($user);
53+
$ex->setUser($user);
5454
throw $ex;
5555
}
5656

5757
if (!$user->isEnabled()) {
5858
throw new DisabledException('User account is disabled.');
59-
$ex->setExtraInformation($user);
59+
$ex->setUser($user);
6060
throw $ex;
6161
}
6262

6363
if (!$user->isAccountNonExpired()) {
6464
$ex = new AccountExpiredException('User account has expired.');
65-
$ex->setExtraInformation($user);
65+
$ex->setUser($user);
6666
throw $ex;
6767
}
6868
}

src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
107107

108108
try {
109109
$insufficientAuthenticationException = new InsufficientAuthenticationException('Full authentication is required to access this resource.', 0, $exception);
110-
$insufficientAuthenticationException->setExtraInformation($token);
110+
$insufficientAuthenticationException->setToken($token);
111111
$response = $this->startAuthentication($request, $insufficientAuthenticationException);
112112
} catch (\Exception $e) {
113113
$event->setException($e);

src/Symfony/Component/Security/Tests/Core/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function testAuthenticateWhenNoProviderSupportsToken()
3737
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
3838
$this->fail();
3939
} catch (ProviderNotFoundException $e) {
40-
$this->assertSame($token, $e->getExtraInformation());
40+
$this->assertSame($token, $e->getToken());
4141
}
4242
}
4343

@@ -51,7 +51,7 @@ public function testAuthenticateWhenProviderReturnsAccountStatusException()
5151
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
5252
$this->fail();
5353
} catch (AccountStatusException $e) {
54-
$this->assertSame($token, $e->getExtraInformation());
54+
$this->assertSame($token, $e->getToken());
5555
}
5656
}
5757

@@ -65,7 +65,7 @@ public function testAuthenticateWhenProviderReturnsAuthenticationException()
6565
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
6666
$this->fail();
6767
} catch (AuthenticationException $e) {
68-
$this->assertSame($token, $e->getExtraInformation());
68+
$this->assertSame($token, $e->getToken());
6969
}
7070
}
7171

0 commit comments

Comments
 (0)