Skip to content

Commit

Permalink
minor #31767 [Security] remove the deprecated AdvancedUserInterface (…
Browse files Browse the repository at this point in the history
…xabbuh)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Security] remove the deprecated AdvancedUserInterface

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

a47cf7e remove the deprecated AdvancedUserInterface
  • Loading branch information
fabpot committed May 31, 2019
2 parents f5d15f6 + a47cf7e commit c5922d2
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 258 deletions.
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\Doctrine\Tests\Security\User;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\SchemaTool;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
Expand Down Expand Up @@ -172,7 +173,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
*/
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
{
$repository = $this->getMockBuilder('\Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$repository = $this->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->getMock();

$provider = new EntityUserProvider(
$this->getManager($this->getObjectManager($repository)),
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Security/CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
5.0.0
-----

* Removed the `AdvancedUserInterface`, use a custom user checker instead.
* Removed `Argon2iPasswordEncoder`, use `SodiumPasswordEncoder` instead
* Removed `BcryptPasswordEncoder`, use `NativePasswordEncoder` instead
* Removed the `has_role()` function from security expressions, use `is_granted()` instead.
Expand Down
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Security\Core\Authentication\Token;

use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;

Expand Down Expand Up @@ -321,29 +320,6 @@ private function hasUserChanged(UserInterface $user)
return true;
}

if ($this->user instanceof AdvancedUserInterface && $user instanceof AdvancedUserInterface) {
@trigger_error(sprintf('Checking for the AdvancedUserInterface in "%s()" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the %s to check if the user has been changed,', __METHOD__, EquatableInterface::class), E_USER_DEPRECATED);
if ($this->user->isAccountNonExpired() !== $user->isAccountNonExpired()) {
return true;
}

if ($this->user->isAccountNonLocked() !== $user->isAccountNonLocked()) {
return true;
}

if ($this->user->isCredentialsNonExpired() !== $user->isCredentialsNonExpired()) {
return true;
}

if ($this->user->isEnabled() !== $user->isEnabled()) {
return true;
}
} elseif ($this->user instanceof AdvancedUserInterface xor $user instanceof AdvancedUserInterface) {
@trigger_error(sprintf('Checking for the AdvancedUserInterface in "%s()" is deprecated since Symfony 4.1 and support for it will be removed in 5.0. Implement the %s to check if the user has been changed,', __METHOD__, EquatableInterface::class), E_USER_DEPRECATED);

return true;
}

return false;
}
}
Expand Up @@ -192,47 +192,6 @@ public function getUserChanges()
];
}

/**
* @group legacy
*
* @dataProvider getUserChangesAdvancedUser
*/
public function testSetUserSetsAuthenticatedToFalseWhenUserChangesAdvancedUser($firstUser, $secondUser)
{
$token = new ConcreteToken();
$token->setAuthenticated(true);
$this->assertTrue($token->isAuthenticated());

$token->setUser($firstUser);
$this->assertTrue($token->isAuthenticated());

$token->setUser($secondUser);
$this->assertFalse($token->isAuthenticated());
}

public function getUserChangesAdvancedUser()
{
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
$advancedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();

return [
['foo', 'bar'],
['foo', new TestUser('bar')],
['foo', $user],
['foo', $advancedUser],
[$user, 'foo'],
[$advancedUser, 'foo'],
[$user, new TestUser('foo')],
[$advancedUser, new TestUser('foo')],
[new TestUser('foo'), new TestUser('bar')],
[new TestUser('foo'), 'bar'],
[new TestUser('foo'), $user],
[new TestUser('foo'), $advancedUser],
[$user, $advancedUser],
[$advancedUser, $user],
];
}

/**
* @dataProvider getUsers
*/
Expand Down
93 changes: 0 additions & 93 deletions src/Symfony/Component/Security/Core/Tests/User/UserCheckerTest.php
Expand Up @@ -30,20 +30,6 @@ public function testCheckPostAuthPass()
$this->assertNull($checker->checkPostAuth(new User('John', 'password')));
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPostAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
*/
public function testCheckPostAuthPassAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isCredentialsNonExpired')->willReturn(true);

$this->assertNull($checker->checkPostAuth($account));
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
*/
Expand All @@ -53,37 +39,6 @@ public function testCheckPostAuthCredentialsExpired()
$checker->checkPostAuth(new User('John', 'password', [], true, true, false, true));
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPostAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
*/
public function testCheckPostAuthCredentialsExpiredAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isCredentialsNonExpired')->willReturn(false);

$checker->checkPostAuth($account);
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPreAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
*/
public function testCheckPreAuthPassAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isAccountNonLocked')->willReturn(true);
$account->expects($this->once())->method('isEnabled')->willReturn(true);
$account->expects($this->once())->method('isAccountNonExpired')->willReturn(true);

$this->assertNull($checker->checkPreAuth($account));
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
*/
Expand All @@ -93,21 +48,6 @@ public function testCheckPreAuthAccountLocked()
$checker->checkPreAuth(new User('John', 'password', [], true, true, false, false));
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPreAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
*/
public function testCheckPreAuthAccountLockedAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isAccountNonLocked')->willReturn(false);

$checker->checkPreAuth($account);
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
*/
Expand All @@ -117,22 +57,6 @@ public function testCheckPreAuthDisabled()
$checker->checkPreAuth(new User('John', 'password', [], false, true, false, true));
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPreAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
*/
public function testCheckPreAuthDisabledAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isAccountNonLocked')->willReturn(true);
$account->expects($this->once())->method('isEnabled')->willReturn(false);

$checker->checkPreAuth($account);
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
*/
Expand All @@ -141,21 +65,4 @@ public function testCheckPreAuthAccountExpired()
$checker = new UserChecker();
$checker->checkPreAuth(new User('John', 'password', [], true, false, true, true));
}

/**
* @group legacy
* @expectedDeprecation Calling "Symfony\Component\Security\Core\User\UserChecker::checkPreAuth()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
*/
public function testCheckPreAuthAccountExpiredAdvancedUser()
{
$checker = new UserChecker();

$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
$account->expects($this->once())->method('isAccountNonLocked')->willReturn(true);
$account->expects($this->once())->method('isEnabled')->willReturn(true);
$account->expects($this->once())->method('isAccountNonExpired')->willReturn(false);

$checker->checkPreAuth($account);
}
}
88 changes: 0 additions & 88 deletions src/Symfony/Component/Security/Core/User/AdvancedUserInterface.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Symfony/Component/Security/Core/User/User.php
Expand Up @@ -18,7 +18,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
final class User implements UserInterface, EquatableInterface, AdvancedUserInterface
final class User implements UserInterface, EquatableInterface
{
private $username;
private $password;
Expand Down
12 changes: 2 additions & 10 deletions src/Symfony/Component/Security/Core/User/UserChecker.php
Expand Up @@ -28,14 +28,10 @@ class UserChecker implements UserCheckerInterface
*/
public function checkPreAuth(UserInterface $user)
{
if (!$user instanceof AdvancedUserInterface && !$user instanceof User) {
if (!$user instanceof User) {
return;
}

if ($user instanceof AdvancedUserInterface && !$user instanceof User) {
@trigger_error(sprintf('Calling "%s()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.', __METHOD__), E_USER_DEPRECATED);
}

if (!$user->isAccountNonLocked()) {
$ex = new LockedException('User account is locked.');
$ex->setUser($user);
Expand All @@ -60,14 +56,10 @@ public function checkPreAuth(UserInterface $user)
*/
public function checkPostAuth(UserInterface $user)
{
if (!$user instanceof AdvancedUserInterface && !$user instanceof User) {
if (!$user instanceof User) {
return;
}

if ($user instanceof AdvancedUserInterface && !$user instanceof User) {
@trigger_error(sprintf('Calling "%s()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.', __METHOD__), E_USER_DEPRECATED);
}

if (!$user->isCredentialsNonExpired()) {
$ex = new CredentialsExpiredException('User credentials have expired.');
$ex->setUser($user);
Expand Down

0 comments on commit c5922d2

Please sign in to comment.