You've to add a LoginSuccessHandler which implements the AuthenticationSuccessHandler Interface,
You can then set your redirect logic within the onAuthenticationSuccess()
method as follow,
namespace XXX\YourBundler\Handler;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
class LoginSuccessHandler implements AuthenticationSuccessHandlerInterface
{
protected $router;
protected $security;
public function __construct(Router $router, SecurityContext $security)
{
$this->router = $router;
$this->security = $security;
}
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
if ($this->security->isGranted('ROLE_XXXX_1'))
{
$response = new RedirectResponse($this->router->generate('route_1'));
}
elseif ($this->security->isGranted('ROLE_XXXX_2'))
{
$response = new RedirectResponse($this->router->generate('route_2'));
}
// ...
}
}
You handler must also be registered as a service,
parameters:
security.authentication.success_handler.class: XXX\YourBundler\Handler\AuthenticationSuccessHandler
services:
security.authentication.customized_success_handler:
class: %security.authentication.success_handler.class%
public: false
arguments: [@router, @security.context]
You've then to add the following line to your firewall security configuration,
success_handler: security.authentication.customized_success_handler