Skip to content

Easing the use of your own EntityRepository as a user provider #11157

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
weaverryan opened this issue Jun 18, 2014 · 8 comments
Closed

Easing the use of your own EntityRepository as a user provider #11157

weaverryan opened this issue Jun 18, 2014 · 8 comments
Labels
Doctrine DX DX = Developer eXperience (anything that improves the experience of using Symfony)

Comments

@weaverryan
Copy link
Member

(this issue is part of the "DX" ("Developer eXperience") initiative introduced by Symfony project)

Suppose I want to use the entity provider, but I want to make it use my repository, so that I can load my User object via some other method (e.g. by username OR email). We talk about this here: http://symfony.com/doc/current/cookbook/security/entity_provider.html#authenticating-someone-with-a-custom-entity-provider

I do this because I want to override loadUserByUsername, but this forces me to also copy in logic for refreshUser and supportsClass, even though I certainly don't care about these. In fact, EntityUserProvider checks for UserProviderInterface only to call loadUserByUsername or refreshUser (but supportsClass is never called).

Could we add a new interface here with only the loadUserByUsername method - e.g. EntityUserProvider? Or perhaps, have a UserProviderEntityRepository base class that extends EntityProvider but contains the logic for these 3 methods? The end goal: allow me to control how my User is loaded, but don't force me to do anything else.

@stof
Copy link
Member

stof commented Jun 18, 2014

the base class would be a bad idea, because we would have to ship a base class for each of the Doctrine projects (as each of them has its own base repository class).
But having a simplified interface could be a great idea indeed

@robinsorg88
Copy link

Hola, disculpen si me equivoco comentando aquí, pero lo hago porque tiene que ver con la entidad Usuario.. Apenas estoy empezando en symfony2, siguiendo los tutoriales en español, especificamente: http://gitnacho.github.io/symfony-docs-es/book/security.html#security-book-access-control-explanation . el cual me sirvió mucho para hacer el CRUD, entendí como crear rutas, controladores y nuevas páginas, e incluso como subir archivos, pero llegué al punto de seguridad y LOGUEO y de allí no pasé, ya que plantea dos tablas (Entidades: roles y usuarios) y en la aplicación de prueba con la que estaba aprendiendo el framework sólo manejaba una tabla para los usuarios, no comprendí como modificar esto para poder hacer el logueo y hasta allí quedé...
Como mencioné soy nuevo en el uso del framework y lo único que se me ocurre es que symfony permita ir y consultar una sola tabla (entidad) y un código para el logueo más sencillo...

Saludos.

@mvrhov
Copy link

mvrhov commented Jul 24, 2014

@robinsorg88. Se habla espanol? In English please.

@robinsorg88
Copy link

Hi, sorry if I'm wrong here commenting, but I do it because it has to do with the User entity .. I'm just beginning in Symfony2, following the tutorials in Spanish, specifically: http://gitnacho.github.io/symfony-docs-es/book/security.html#security-book-access-control-explanation . which helped me to do CRUD, understood as creating routes, controllers and new pages, and even how to upload files, but I got to the security checkpoint and logging and there did not pass as it raises two tables (entities: roles and users) and application of test that was learning the framework only managed a table for users, not understood how this change to make the logging and there was ...
As I mentioned I am new to using the framework and the only thing I can think is that symfony let go and consult a single table (entity) and a code for the simplest logging ...

Greetings.

@weaverryan
Copy link
Member Author

@robinsorg88 Hola! I don't think your question is related to this issue. Si tiene alguna pregunta de usar Symfony, puede usar el mailing list: https://groups.google.com/forum/#!forum/Symfony2. Y hay un grupo para espanol tambien! :) https://groups.google.com/forum/#!forum/symfony-es

Saludos!

@mtrojanowski
Copy link
Contributor

I'll try to propose a solution for this.

@mtrojanowski
Copy link
Contributor

So my idea for this is to introduce a BasicUserProviderInterface which only need the implementation of refreshUser and loadUserByUsername. To keep the BC UserProviderInterface extends the basic interface.

@mtrojanowski
Copy link
Contributor

Also as I didn't know if this solution will actually be used I didn't change the comments explaining the use of this interface. If this is accepted I think that the comment in BaseUserProviderInterface should be changed - but I'm not yet sure what's the best way to explain this - the base interface can't be used in as a provider in a ChainUserProvider as we need the supportsClass function there. It should rather be used with the repository classes as Ryan suggested.

fabpot added a commit that referenced this issue 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
Labels
Doctrine DX DX = Developer eXperience (anything that improves the experience of using Symfony)
Projects
None yet
Development

No branches or pull requests

5 participants