0

I'm working on a multi-tenancy application and I need to accomplish some rules to check when the user can be authenticated (I'm not talking about roles, trying make login should return "Invalid username or password").

My question is: where is the best place to put these additional checks?

j0k
  • 22,600
  • 28
  • 79
  • 90
Marcos Passos
  • 400
  • 1
  • 3
  • 15

3 Answers3

1

I think your best bet would be to read the User related classes in FosUserBundle. I have made many chnages by adding custom methods in UserManager.php

FOS call many chained methods you can go through these files and chnage according to your needs

Also look out for

UserListerner.php User.php

Mirage
  • 30,868
  • 62
  • 166
  • 261
1

That depends on type of checks you intent to perform, but in general the best way is to use a custom security Voter.

There is an example in official documentation showing how to implement IP blacklist: http://symfony.com/doc/current/cookbook/security/voters.html

tomas.pecserke
  • 3,260
  • 25
  • 26
0

The question is old, but still very relevant, I think. The answer helped me in the right path (FOSUserBundle 2.0 with Symfony 3.3) - if someone is still looking, here are more details https://symfony.com/doc/master/bundles/FOSUserBundle/user_manager.html

This part was key for me:

You can replace the default implementation of the user manager by defining a service implementing FOS\UserBundle\Model\UserManagerInterface and setting its id in the configuration. The id of the default implementation is fos_user.user_manager.default

fos_user: # ... service: user_manager: custom_user_manager_id

Your custom implementation can extend FOS\UserBundle\Model\UserManager to reuse the common logic.

And in my case, I just copied the whole of FOS\UserBundle\Doctrine\UserManager (which extends FOS\UserBundle\Model\UserManager) into my AppBundle\Services as my starting point.

I also had to copy the injections from here: vendor/friendsofsymfony/user-bundle/Resources/config/doctrine.xml

Oliver Adria
  • 1,123
  • 11
  • 23