Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8456f3b

Browse files
Iltar van der Berglinaori
Iltar van der Berg
authored andcommitted
Deprecated the AdvancedUserInterface
1 parent 52e9f83 commit 8456f3b

File tree

12 files changed

+207
-62
lines changed

12 files changed

+207
-62
lines changed

UPGRADE-4.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Security
2929
--------
3030

3131
* The `ContextListener::setLogoutOnUserChange()` method is deprecated and will be removed in 5.0.
32+
* Using the `AdvancedUserInterface` is now deprecated. To use the existing
33+
functionality, create a custom user-checker based on the
34+
`Symfony\Component\Security\Core\User\UserChecker`. This functionality will
35+
be removed in Symfony 5.0.
3236

3337
SecurityBundle
3438
--------------

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Security
2626
--------
2727

2828
* The `ContextListener::setLogoutOnUserChange()` method has been removed.
29+
* The `Symfony\Component\Security\Core\User\AdvancedUserInterface` has been removed.
2930

3031
SecurityBundle
3132
--------------

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ CHANGELOG
66

77
* The `ContextListener::setLogoutOnUserChange()` method is deprecated and will be removed in 5.0.
88
* added `UserValueResolver`.
9+
* Using the AdvancedUserInterface is now deprecated. To use the existing
10+
functionality, create a custom user-checker based on the
11+
`Symfony\Component\Security\Core\User\UserChecker`. This functionality will
12+
be removed in Symfony 5.0.
913

1014
4.0.0
1115
-----

src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ private function hasUserChanged(UserInterface $user)
261261
}
262262

263263
if ($this->user instanceof AdvancedUserInterface && $user instanceof AdvancedUserInterface) {
264+
@trigger_error(sprintf('Checking for the AdvancedUserInterface in %s has been deprecated in 4.1 and will be removed in 5.0. Implement the %s to check if the user has been changed,', __METHOD__, EquatableInterface::class), E_USER_DEPRECATED);
264265
if ($this->user->isAccountNonExpired() !== $user->isAccountNonExpired()) {
265266
return true;
266267
}
@@ -277,6 +278,8 @@ private function hasUserChanged(UserInterface $user)
277278
return true;
278279
}
279280
} elseif ($this->user instanceof AdvancedUserInterface xor $user instanceof AdvancedUserInterface) {
281+
@trigger_error(sprintf('Checking for the AdvancedUserInterface in %s has been deprecated in 4.1 and will be removed in 5.0. Implement the %s to check if the user has been changed,', __METHOD__, EquatableInterface::class), E_USER_DEPRECATED);
282+
280283
return true;
281284
}
282285

src/Symfony/Component/Security/Core/Tests/Authentication/Token/AbstractTokenTest.php

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function getCredentials()
5959
}
6060
}
6161

62-
/** @noinspection PhpUndefinedClassInspection */
6362
class AbstractTokenTest extends TestCase
6463
{
6564
public function testGetUsername()
@@ -185,10 +184,8 @@ public function testSetUser($user)
185184
public function getUsers()
186185
{
187186
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
188-
$advancedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
189187

190188
return array(
191-
array($advancedUser),
192189
array($user),
193190
array(new TestUser('foo')),
194191
array('foo'),
@@ -212,53 +209,59 @@ public function testSetUserSetsAuthenticatedToFalseWhenUserChanges($firstUser, $
212209
}
213210

214211
public function getUserChanges()
212+
{
213+
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
214+
215+
return array(
216+
array('foo', 'bar'),
217+
array('foo', new TestUser('bar')),
218+
array('foo', $user),
219+
array($user, 'foo'),
220+
array($user, new TestUser('foo')),
221+
array(new TestUser('foo'), new TestUser('bar')),
222+
array(new TestUser('foo'), 'bar'),
223+
array(new TestUser('foo'), $user),
224+
);
225+
}
226+
227+
/**
228+
* @group legacy
229+
*
230+
* @dataProvider getUserChangesAdvancedUser
231+
*/
232+
public function testSetUserSetsAuthenticatedToFalseWhenUserChangesdvancedUser($firstUser, $secondUser)
233+
{
234+
$token = $this->getToken();
235+
$token->setAuthenticated(true);
236+
$this->assertTrue($token->isAuthenticated());
237+
238+
$token->setUser($firstUser);
239+
$this->assertTrue($token->isAuthenticated());
240+
241+
$token->setUser($secondUser);
242+
$this->assertFalse($token->isAuthenticated());
243+
}
244+
245+
public function getUserChangesAdvancedUser()
215246
{
216247
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
217248
$advancedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
218249

219250
return array(
220-
array(
221-
'foo', 'bar',
222-
),
223-
array(
224-
'foo', new TestUser('bar'),
225-
),
226-
array(
227-
'foo', $user,
228-
),
229-
array(
230-
'foo', $advancedUser,
231-
),
232-
array(
233-
$user, 'foo',
234-
),
235-
array(
236-
$advancedUser, 'foo',
237-
),
238-
array(
239-
$user, new TestUser('foo'),
240-
),
241-
array(
242-
$advancedUser, new TestUser('foo'),
243-
),
244-
array(
245-
new TestUser('foo'), new TestUser('bar'),
246-
),
247-
array(
248-
new TestUser('foo'), 'bar',
249-
),
250-
array(
251-
new TestUser('foo'), $user,
252-
),
253-
array(
254-
new TestUser('foo'), $advancedUser,
255-
),
256-
array(
257-
$user, $advancedUser,
258-
),
259-
array(
260-
$advancedUser, $user,
261-
),
251+
array('foo', 'bar'),
252+
array('foo', new TestUser('bar')),
253+
array('foo', $user),
254+
array('foo', $advancedUser),
255+
array($user, 'foo'),
256+
array($advancedUser, 'foo'),
257+
array($user, new TestUser('foo')),
258+
array($advancedUser, new TestUser('foo')),
259+
array(new TestUser('foo'), new TestUser('bar')),
260+
array(new TestUser('foo'), 'bar'),
261+
array(new TestUser('foo'), $user),
262+
array(new TestUser('foo'), $advancedUser),
263+
array($user, $advancedUser),
264+
array($advancedUser, $user),
262265
);
263266
}
264267

src/Symfony/Component/Security/Core/Tests/User/UserCheckerTest.php

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Tests\User;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Security\Core\User\User;
1516
use Symfony\Component\Security\Core\User\UserChecker;
1617

1718
class UserCheckerTest extends TestCase
@@ -24,6 +25,16 @@ public function testCheckPostAuthNotAdvancedUserInterface()
2425
}
2526

2627
public function testCheckPostAuthPass()
28+
{
29+
$checker = new UserChecker();
30+
$this->assertNull($checker->checkPostAuth(new User('John', 'password')));
31+
}
32+
33+
/**
34+
* @group legacy
35+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPostAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
36+
*/
37+
public function testCheckPostAuthPassAdvancedUser()
2738
{
2839
$checker = new UserChecker();
2940

@@ -39,21 +50,29 @@ public function testCheckPostAuthPass()
3950
public function testCheckPostAuthCredentialsExpired()
4051
{
4152
$checker = new UserChecker();
42-
43-
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
44-
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
45-
46-
$checker->checkPostAuth($account);
53+
$checker->checkPostAuth(new User('John', 'password', array(), true, true, false, true));
4754
}
4855

49-
public function testCheckPreAuthNotAdvancedUserInterface()
56+
/**
57+
* @group legacy
58+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPostAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
59+
* @expectedException \Symfony\Component\Security\Core\Exception\CredentialsExpiredException
60+
*/
61+
public function testCheckPostAuthCredentialsExpiredAdvancedUser()
5062
{
5163
$checker = new UserChecker();
5264

53-
$this->assertNull($checker->checkPreAuth($this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock()));
65+
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\AdvancedUserInterface')->getMock();
66+
$account->expects($this->once())->method('isCredentialsNonExpired')->will($this->returnValue(false));
67+
68+
$checker->checkPostAuth($account);
5469
}
5570

56-
public function testCheckPreAuthPass()
71+
/**
72+
* @group legacy
73+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
74+
*/
75+
public function testCheckPreAuthPassAdvancedUser()
5776
{
5877
$checker = new UserChecker();
5978

@@ -69,6 +88,17 @@ public function testCheckPreAuthPass()
6988
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
7089
*/
7190
public function testCheckPreAuthAccountLocked()
91+
{
92+
$checker = new UserChecker();
93+
$checker->checkPreAuth(new User('John', 'password', array(), true, true, false, false));
94+
}
95+
96+
/**
97+
* @group legacy
98+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
99+
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
100+
*/
101+
public function testCheckPreAuthAccountLockedAdvancedUser()
72102
{
73103
$checker = new UserChecker();
74104

@@ -82,6 +112,17 @@ public function testCheckPreAuthAccountLocked()
82112
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
83113
*/
84114
public function testCheckPreAuthDisabled()
115+
{
116+
$checker = new UserChecker();
117+
$checker->checkPreAuth(new User('John', 'password', array(), false, true, false, true));
118+
}
119+
120+
/**
121+
* @group legacy
122+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
123+
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
124+
*/
125+
public function testCheckPreAuthDisabledAdvancedUser()
85126
{
86127
$checker = new UserChecker();
87128

@@ -96,6 +137,17 @@ public function testCheckPreAuthDisabled()
96137
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
97138
*/
98139
public function testCheckPreAuthAccountExpired()
140+
{
141+
$checker = new UserChecker();
142+
$checker->checkPreAuth(new User('John', 'password', array(), true, false, true, true));
143+
}
144+
145+
/**
146+
* @group legacy
147+
* @expectedDeprecation Calling Symfony\Component\Security\Core\User\UserChecker::checkPreAuth with an AdvancedUserInterface is deprecated as of 4.1 and will be removed in 5.0. Create a custom user checker if you wish to keep this functionality.
148+
* @expectedException \Symfony\Component\Security\Core\Exception\AccountExpiredException
149+
*/
150+
public function testCheckPreAuthAccountExpiredAdvancedUser()
99151
{
100152
$checker = new UserChecker();
101153

src/Symfony/Component/Security/Core/Tests/User/UserTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Component\Security\Core\Tests\User;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Security\Core\User\EquatableInterface;
1516
use Symfony\Component\Security\Core\User\User;
17+
use Symfony\Component\Security\Core\User\UserInterface;
1618

1719
class UserTest extends TestCase
1820
{
@@ -99,4 +101,37 @@ public function testToString()
99101
$user = new User('fabien', 'superpass');
100102
$this->assertEquals('fabien', (string) $user);
101103
}
104+
105+
/**
106+
* @dataProvider isEqualToData
107+
*
108+
* @param bool $expectation
109+
* @param EquatableInterface|UserInterface $a
110+
* @param EquatableInterface|UserInterface $b
111+
*/
112+
public function testIsEqualTo($expectation, $a, $b)
113+
{
114+
$this->assertSame($expectation, $a->isEqualTo($b));
115+
$this->assertSame($expectation, $b->isEqualTo($a));
116+
}
117+
118+
public static function isEqualToData()
119+
{
120+
return array(
121+
array(true, new User('username', 'password'), new User('username', 'password')),
122+
array(true, new User('username', 'password', array('ROLE')), new User('username', 'password')),
123+
array(true, new User('username', 'password', array('ROLE')), new User('username', 'password', array('NO ROLE'))),
124+
array(false, new User('diff', 'diff'), new User('username', 'password')),
125+
array(false, new User('diff', 'diff', array(), false), new User('username', 'password')),
126+
array(false, new User('diff', 'diff', array(), false, false), new User('username', 'password')),
127+
array(false, new User('diff', 'diff', array(), false, false, false), new User('username', 'password')),
128+
array(false, new User('diff', 'diff', array(), false, false, false, false), new User('username', 'password')),
129+
);
130+
}
131+
132+
public function testIsEqualToWithDifferentUser()
133+
{
134+
$user = new User('username', 'password');
135+
$this->assertFalse($user->isEqualTo($this->getMockBuilder(UserInterface::class)->getMock()));
136+
}
102137
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*
3333
* @see UserInterface
3434
* @see AccountStatusException
35+
* @deprecated since version 4.1, will be removed in 5.0.
3536
*
3637
* @author Fabien Potencier <[email protected]>
3738
*/

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ interface EquatableInterface
2626
* However, you do not need to compare every attribute, but only those that
2727
* are relevant for assessing whether re-authentication is required.
2828
*
29-
* Also implementation should consider that $user instance may implement
30-
* the extended user interface `AdvancedUserInterface`.
31-
*
3229
* @return bool
3330
*/
3431
public function isEqualTo(UserInterface $user);

0 commit comments

Comments
 (0)