Skip to content

Commit 9e6f9b6

Browse files
committed
feat!: permit use of the lib under Symfony 5
BREAKING CHANGE: the User class no longer implements Symfony's AdvancedUserInterface which was removed in Symfony 5. Instead of using the methods of the removed interface, integrators should implement User and Account checks in UserCheckers. The LegacyAdvancedUserInterface is available as a last resort.
1 parent 83da5d0 commit 9e6f9b6

5 files changed

Lines changed: 90 additions & 14 deletions

File tree

UPGRADE-2.0.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
UPGRADE FROM 1.9 to 2.0
2+
=======================
3+
4+
- The User class no longer implements Symfony's `AdvancedUserInterface` which
5+
it has been removed from Symfony 5. Use of the methods of this interface
6+
should be replaced by performing User and Account checks in UserCheckers.
7+
8+
A temporary replacement for the removed interface is
9+
`UserBase\Client\Model\LegacyAdvancedUserInterface`, but use this only as a
10+
last resort and as a temporary fix.

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
],
1919
"require": {
2020
"php": ">=5.3.0",
21-
"linkorb/userbase-role-contracts": "^1.0",
22-
"symfony/security": "~2.6 || ~3.0 || ^4.0|| ^5.0",
21+
"linkorb/envoi": "^1.1",
22+
"linkorb/userbase-role-contracts": "^2.0",
2323
"psr/cache": "~1.0",
24-
"symfony/cache": "~3.0|| ^4.0 || ^5.0 ",
25-
"linkorb/envoi": "^1.1"
24+
"symfony/cache": "~3.0 || ^4.0 || ^5.0",
25+
"symfony/security-core": "~2.6 || ~3.0 || ^4.0 || ^5.0"
2626
},
2727
"require-dev": {
28-
"symfony/dotenv": "~3.0 || ^4.0"
28+
"symfony/dotenv": "~3.0 || ^4.0 || ^5.0"
2929
},
3030
"autoload": {
3131
"psr-4": {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace UserBase\Client\Model;
4+
5+
/**
6+
* For backwards compatability only - use UserCheckers instead.
7+
*
8+
* This iface replaces Symfony\Component\Security\Core\User\AdvancedUserInterface
9+
* which was removed from Symfony 5 because the User class is not the right place
10+
* to implement account/user checks that influence whether or not a user is
11+
* allowed to authenticate. For more info about why it was removed see:
12+
* https://github.com/symfony/symfony/issues/23292
13+
*
14+
* For info about UserCheckers see:
15+
* https://symfony.com/doc/current/security/user_checkers.html
16+
*/
17+
interface LegacyAdvancedUserInterface extends UserInterface
18+
{
19+
/**
20+
* Check whether the user's account has expired.
21+
*
22+
* @return bool true if the user's account is non expired, false otherwise
23+
*/
24+
public function isAccountNonExpired();
25+
26+
/**
27+
* Check whether the user is locked.
28+
*
29+
* @return bool true if the user is not locked, false otherwise
30+
*/
31+
public function isAccountNonLocked();
32+
33+
/**
34+
* Check whether the user's credentials have expired.
35+
*
36+
* @return bool true if the user's credentials are non expired, false otherwise
37+
*/
38+
public function isCredentialsNonExpired();
39+
40+
/**
41+
* Check whether the user is enabled.
42+
*
43+
* @return bool true if the user is enabled, false otherwise
44+
*/
45+
public function isEnabled();
46+
}

src/Model/User.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,34 @@
44

55
use LinkORB\Contracts\UserbaseRole\RoleInterface;
66
use RuntimeException;
7-
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
7+
use Symfony\Component\Security\Core\User\UserInterface as BaseUserInterface;
88

99
final class User implements
1010
AccountContainerInterface,
11-
AdvancedUserInterface,
11+
BaseUserInterface,
12+
LegacyAdvancedUserInterface,
1213
PolicyContainerInterface,
1314
RoleInterface,
1415
UserInterface
1516
{
16-
private $password;
17+
/**
18+
* @deprecated
19+
*/
1720
private $enabled;
21+
/**
22+
* @deprecated
23+
*/
1824
private $accountNonExpired;
25+
/**
26+
* @deprecated
27+
*/
1928
private $credentialsNonExpired;
29+
/**
30+
* @deprecated
31+
*/
2032
private $accountNonLocked;
33+
34+
private $password;
2135
private $roles;
2236

2337
private $createdAt;
@@ -134,21 +148,24 @@ public function getDisplayName()
134148
}
135149

136150
/**
137-
* {@inheritdoc}
151+
* @deprecated
138152
*/
139153
public function isAccountNonExpired()
140154
{
141155
return $this->accountNonExpired;
142156
}
143157

144158
/**
145-
* {@inheritdoc}
159+
* @deprecated
146160
*/
147161
public function isAccountNonLocked()
148162
{
149163
return $this->accountNonLocked;
150164
}
151165

166+
/**
167+
* @deprecated
168+
*/
152169
public function setAccountNonLocked($accountNonLocked)
153170
{
154171
$this->accountNonLocked = $accountNonLocked;
@@ -157,21 +174,24 @@ public function setAccountNonLocked($accountNonLocked)
157174
}
158175

159176
/**
160-
* {@inheritdoc}
177+
* @deprecated
161178
*/
162179
public function isCredentialsNonExpired()
163180
{
164181
return $this->credentialsNonExpired;
165182
}
166183

167184
/**
168-
* {@inheritdoc}
185+
* @deprecated
169186
*/
170187
public function isEnabled()
171188
{
172189
return $this->enabled;
173190
}
174191

192+
/**
193+
* @deprecated
194+
*/
175195
public function setEnabled($enabled)
176196
{
177197
$this->enabled = $enabled;

src/UserProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use LinkORB\Contracts\UserbaseRole\RoleManagerInterface;
66
use LinkORB\Contracts\UserbaseRole\RoleProviderInterface;
77
use RuntimeException;
8-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
98
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
109
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1110
use Symfony\Component\Security\Core\User\UserInterface;
1211
use Symfony\Component\Security\Core\User\UserProviderInterface;
12+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1313
use UserBase\Client\Event\UserLoadedEvent;
1414
use UserBase\Client\Model\User;
1515

@@ -38,7 +38,7 @@ public function loadUserByUsername($username)
3838
$user = $this->client->getUserByUsername($username);
3939
if ($this->dispatcher) {
4040
$event = new UserLoadedEvent($user);
41-
$this->dispatcher->dispatch('userbase.user_loaded', $event);
41+
$this->dispatcher->dispatch($event, 'userbase.user_loaded');
4242
}
4343
} catch (RuntimeException $e) {
4444
throw new UsernameNotFoundException(

0 commit comments

Comments
 (0)