Skip to content

[Security] [Doctrine] Added BaseUserProviderInterface #12733

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

Closed

Conversation

mtrojanowski
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #11157
License MIT
Doc PR symfony/symfony-docs#4543

You can now implement BaseUserProviderInterface without the need of implementing supportsClass function.

You can now implement BaseUserProviderInterface without the need of
implementing `supportsClass` function.
@@ -54,7 +54,7 @@ public function loadUserByUsername($username)
if (null !== $this->property) {
$user = $this->repository->findOneBy(array($this->property => $username));
} else {
if (!$this->repository instanceof UserProviderInterface) {
if (!$this->repository instanceof BaseUserProviderInterface) {
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Souldn't the message of exception be changed as well (Classname) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course you're right. Fixed that.

 * Removed unneeded `use` statements.
 * Fixed error message to reference the new interface
 * Changed `refreshUser` to compare to the new interface
@@ -77,7 +77,7 @@ public function refreshUser(UserInterface $user)
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}

if ($this->repository instanceof UserProviderInterface) {
if ($this->repository instanceof BaseUserProviderInterface) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really needed to move the refreshUser() method to the base interface too? Usually you would have users that have an identifier which can be passed to the repository's find() method, wouldn't you?

@weaverryan
Copy link
Member

Hey @mtrojanowski!

So the use-case for this BaseUserProviderInterface is small: it's just to allow this EntityUserProvider to be able to call a custom method on your EntityRepository class in case you have some special logic for loading your users.

So, I'm going to propose an evolution, that I think will be less intrusive (e.g. it won't touch the very central UserProviderInterface in any way, even a BC-way). What if we:

A) Introduce a new interface inside of the Doctrine Bridge - something like UserProviderLoaderInterface (any better name ideas?). This will only have the method loadUserByUsername on it.

B) In EntityUserProvider, we basically have take the existing if statement and modify it to check for the UserProviderInterface (like now) AND the new UserProviderLoaderInterface. If it implements neither, then we throw an exception. If it implements UserProviderInterface, we'll trigger a deprecation warning, since this method of doing this will be deprecated.

What do you think?

P.S. Nice avatar ;)

@stof
Copy link
Member

stof commented Jan 4, 2015

I'm with @weaverryan here. Your BaseUserProviderInterface makes no sense in the context of the Security component. So a separate interface in the bridge to be used by the bridge to allow simpler implementations for Doctrine repositories would be better.

Can you work on this @mtrojanowski ?

@mtrojanowski
Copy link
Contributor Author

@stof, sure. I'll try to propose a new solution according to your ideas.

@fabpot
Copy link
Member

fabpot commented Sep 14, 2015

Closing as there is no activity. @mtrojanowski Feel free to open a new PR implementing @weaverryan suggestions.

@fabpot fabpot closed this Sep 14, 2015
fabpot added a commit that referenced this pull request Oct 16, 2015
…ctrine. (mtrojanowski)

This PR was submitted for the 2.7 branch but it was merged into the 2.8 branch instead (closes #15947).

Discussion
----------

Added UserLoaderInterface for loading users through Doctrine.

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #11157
| License       | MIT
| Doc PR        | symfony/symfony-docs#4543

Based on the @weaverryan and @stof propositions from [this](#12733 (comment)) discussion I created a new interface in the Doctrine Bridge which can be used to more easily implement a repository capable of returning a User.

Commits
-------

a8d3d12 Added UserLoaderInterface for loading users through Doctrine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants