Skip to content

Commit

Permalink
[Security] Removed get/setExtraInformation, added `get/set(Token|Us…
Browse files Browse the repository at this point in the history
…er)`
  • Loading branch information
asm89 committed Jan 7, 2013
1 parent 837ae15 commit 39da27a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/Symfony/Component/Security/CHANGELOG.md
Expand Up @@ -35,5 +35,6 @@ CHANGELOG
* [BC BREAK] moved the default logout success handling to a separate class. The
order of arguments in the constructor of `LogoutListener` has changed.
* [BC BREAK] The constructor of `AuthenticationException` and all child
classes now matches the constructor of `\Exception`. Extra information
should be passed via the `setExtraInformation` setter.
classes now matches the constructor of `\Exception`. The extra information
getters and setters are removed. There are now dedicated getters/setters for
token (`AuthenticationException') and user (`AccountStatusException`).
Expand Up @@ -77,7 +77,7 @@ public function authenticate(TokenInterface $token)
break;
}
} catch (AccountStatusException $e) {
$e->setExtraInformation($token);
$e->setToken($token);

throw $e;
} catch (AuthenticationException $e) {
Expand Down Expand Up @@ -105,7 +105,7 @@ public function authenticate(TokenInterface $token)
$this->eventDispatcher->dispatch(AuthenticationEvents::AUTHENTICATION_FAILURE, new AuthenticationFailureEvent($token, $lastException));
}

$lastException->setExtraInformation($token);
$lastException->setToken($token);

throw $lastException;
}
Expand Down
Expand Up @@ -91,7 +91,7 @@ protected function retrieveUser($username, UsernamePasswordToken $token)
throw $notFound;
} catch (\Exception $repositoryProblem) {
$ex = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
$ex->setExtraInformation($token);
$ex->setToken($token);
throw $ex;
}
}
Expand Down
Expand Up @@ -11,12 +11,36 @@

namespace Symfony\Component\Security\Core\Exception;

use Symfony\Component\Security\Core\User\UserInterface;

/**
* AccountStatusException is the base class for authentication exceptions
* caused by the user account status.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Alexander <iam.asm89@gmail.com>
*/
abstract class AccountStatusException extends AuthenticationException
{
private $user;

/**
* Get the user.
*
* @return UserInterface
*/
public function getUser()
{
return $this->user;
}

/**
* Set the user.
*
* @param UserInterface $user
*/
public function setUser(UserInterface $user)
{
$this->user = $user;
}
}
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Security\Core\Exception;

use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
* AuthenticationException is the base class for all authentication exceptions.
*
Expand All @@ -19,16 +21,26 @@
*/
class AuthenticationException extends \RuntimeException implements \Serializable
{
private $extraInformation;
private $token;

public function getExtraInformation()
/**
* Get the token.
*
* @return TokenInterface
*/
public function getToken()
{
return $this->extraInformation;
return $this->token;
}

public function setExtraInformation($extraInformation)
/**
* Set the token.
*
* @param TokenInterface $token
*/
public function setToken(TokenInterface $token)
{
$this->extraInformation = $extraInformation;
$this->token = $token;
}

public function serialize()
Expand Down
8 changes: 4 additions & 4 deletions src/Symfony/Component/Security/Core/User/UserChecker.php
Expand Up @@ -34,7 +34,7 @@ public function checkPreAuth(UserInterface $user)

if (!$user->isCredentialsNonExpired()) {
$ex = new CredentialsExpiredException('User credentials have expired.');
$ex->setExtraInformation($user);
$ex->setUser($user);
throw $ex;
}
}
Expand All @@ -50,19 +50,19 @@ public function checkPostAuth(UserInterface $user)

if (!$user->isAccountNonLocked()) {
$ex = new LockedException('User account is locked.');
$ex->setExtraInformation($user);
$ex->setUser($user);
throw $ex;
}

if (!$user->isEnabled()) {
throw new DisabledException('User account is disabled.');
$ex->setExtraInformation($user);
$ex->setUser($user);
throw $ex;
}

if (!$user->isAccountNonExpired()) {
$ex = new AccountExpiredException('User account has expired.');
$ex->setExtraInformation($user);
$ex->setUser($user);
throw $ex;
}
}
Expand Down
Expand Up @@ -107,7 +107,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)

try {
$insufficientAuthenticationException = new InsufficientAuthenticationException('Full authentication is required to access this resource.', 0, $exception);
$insufficientAuthenticationException->setExtraInformation($token);
$insufficientAuthenticationException->setToken($token);
$response = $this->startAuthentication($request, $insufficientAuthenticationException);
} catch (\Exception $e) {
$event->setException($e);
Expand Down
Expand Up @@ -37,7 +37,7 @@ public function testAuthenticateWhenNoProviderSupportsToken()
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
$this->fail();
} catch (ProviderNotFoundException $e) {
$this->assertSame($token, $e->getExtraInformation());
$this->assertSame($token, $e->getToken());
}
}

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

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

Expand Down

0 comments on commit 39da27a

Please sign in to comment.