I am getting myself into symfony and actually I am stucked on authorization.
I would like to forward a user to a specific route, depending on its role. Oh, am using FOS Bundle.
services.yaml:
LogoutListener:
class: App\Listeners\LogoutListener
arguments:
userManager: "@fos_user.user_manager"
security.yaml:
firewalls:
main:
....
logout:
handlers: [logoutlistener]
ListenerClass:
namespace App\Listeners;
use FOS\UserBundle\Model\UserManager;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
class LogoutListener implements LogoutHandlerInterface {
protected $userManager;
/**
* LogoutListener constructor.
* @param UserManagerInterface $userManager
*/
public function __construct(UserManagerInterface $userManager){
$this->userManager = $userManager;
}
public function logout(Request $request, Response $response, TokenInterface $token) {
die('user logged out');
}
}
It always gives me:
InvalidArgumentException
Invalid service "LogoutListener": method "App\Listeners\LogoutListener::__construct()" has no argument type-hinted as "userManager". Check your service definition.
Any hint for me? regards deAndro
Config has changed a bit with Symfony 4. This should do the trick:
services.yaml
security.yaml
ListenerClass