-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Allow in memory user to have extra fields #40097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
noniagriconomie
commented
Feb 4, 2021
•
edited
Loading
edited
Q | A |
---|---|
Branch? | 5.x |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Tickets | Fix #40091 |
License | MIT |
Doc PR | symfony/symfony-docs#14928 |
474eb6b
to
365d506
Compare
src/Symfony/Bundle/SecurityBundle/DependencyInjection/MainConfiguration.php
Outdated
Show resolved
Hide resolved
365d506
to
a46493d
Compare
a46493d
to
abf3545
Compare
abf3545
to
b31fff5
Compare
This PR was submitted for the 5.x branch but it was merged into the 4.4 branch instead. Discussion ---------- Update PULL_REQUEST_TEMPLATE.md | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | See #40097 (comment) | License | MIT | Doc PR | Doc introduced in symfony/symfony-docs#14830 ping @OskarStark do you think this can be valuable here? as this file is the entry point of all PRs Commits ------- 41c7796 Update PULL_REQUEST_TEMPLATE.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A functional test would be nice :)
src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php
Outdated
Show resolved
Hide resolved
b31fff5
to
c0f459a
Compare
Does this really fit in the architecture of the new system where this User class is considered for deprecation ? |
given the current situation, i figured the mapping was missing from an implementation pov, hence im 👍🏻 however i do think we should rename it to
|
I personally only see a use-case for the in-memory provider in simple demo applications. Do we really want to advocate using it in real applications? If the answer is no, then I'm in favor of not adding more lines that we need to maintain. (btw, I would not say that the User is up for deprecation, but hopefully the credential related methods are. Any security system needs to have some sort of user/principal) |
https://symfony.com/doc/current/security/user_provider.html#memory-user-provider
we fix some limitation here. Managing YAML is debatable 😁
So it is useful for limited (non-prototype) apps actually? IMHO it's just a persistence layer, and if in-memory fits ... it fits :) |
It's not a "real" persistence layer, as it requires to use Symfony's User. Btw, it's very easy to implement your own in-memory user provider that uses a custom User class with all properties it needs: class MyInMemoryUserProvider implements UserProvider
{
private const USERS = [
'wouter' => [...],
// ...
];
public function loadUserByUsername(string $username)
{
if (!$user = self::USERS[$username] ?? false) {
throw new UsernameNotFoundException();
}
return new AppUser($user['username'], $user['password'], ...);
}
public function refreshUser(UserInterface $user)
{
return $this->loadUserByUsername($user->getUsername());
}
public function supportsClass(string $class)
{
return is_a($class, AppUser::class);
}
} So I'm honestly leaning more and more towards not adding more properties to the |
For context, |
Hello, i am not aware of the deprecation of this class, where can i find more? Also, as the prop already exists, i think it is more « finishing » the implementation than adding a new one |
We don't need to deprecate this class and the corresponding provider, only renaming it (already possible) and make it follow the rework of the UserInterface when it's time to. |
Rebase needed. Don't hesitate to tell us if you need help to finish this PR @noniagriconomie |
ad04e86
to
4c4ee49
Compare
@chalasr rebase done and a test added |
4c4ee49
to
b382bc4
Compare
@@ -25,6 +25,7 @@ public function testConstructor() | |||
$user = $provider->loadUserByUsername('fabien'); | |||
$this->assertEquals('foo', $user->getPassword()); | |||
$this->assertEquals(['ROLE_USER'], $user->getRoles()); | |||
$this->assertEquals(['name' => 'John', 'age' => 77, 'salary' => 1234.56], $user->getExtraFields()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertSame ?
Same for the others in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not know if it is related to this PR to change the method name
and for this new added line I just duplicate the above line to keep things similar
if asked/decided I can handle it inside this PR of course :)
I agree with @wouterj and I don't think we want to add this feature. I understand the use case and I have the same on some small applications. But as already mentioned, there are simple ways to achieve what you want without support in the framework. Even if adding it in core in not a lot of code, I think that this sends the wrong signal. |
@noniagriconomie would you then send the proposed code snippet by Wouter as a docs PR to help others achieve this more easily? Thanks |
For reference: the |
hey, ok understood even if I really thought this was a nice addition |