Answer the question
In order to leave comments, you need to log in
How to authorize Symfony2 + FOSUserBundle?
Hello. I would like to know if it is possible to override the FOSUserBundle authorization, you need to authorize not by two fields (login / password) but by three (not email), for further application of ACL, I re-read a bunch of documentation and forums, I didn’t find anything suitable, maybe someone has already encountered such a task or will tell you in which direction to dig? Due to the complexity of the Symfony 2 core, it's hard to figure this out on your own.
Answer the question
In order to leave comments, you need to log in
Yes, you can, in short, then symfony.com/doc/current/cookbook/bundles/inheritan...
I solved this problem by inheriting my bundle from FOSUserBundle:
class MyUserBundle extends Symfony\Component\HttpKernel\Bundle\Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
namespace MyUserBundle\Controller;
use FOS\UserBundle\Controller\SecurityController as ParentSecurityController;
use Symfony\Component\HttpFoundation\RedirectResponse;
class SecurityController extends ParentSecurityController
{
public function loginAction()
{
if (!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_ANONYMOUSLY'))
{
return new RedirectResponse('/');
}
return parent::loginAction();
}
Then already:
namespace MyUserBundle\Controller;
use FOS\UserBundle\Controller\SecurityController as ParentSecurityController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class SecurityController extends ParentSecurityController
{
public function loginAction(Request $request)
{
if (!$this->container->get('security.context')->isGranted('IS_AUTHENTICATED_ANONYMOUSLY'))
{
return new RedirectResponse('/');
}
return parent::loginAction($request);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question