因为symfony没有vmiddleware的概念,但是提供了event的概念,可以做同样的事情:
https://stackoverflow.com/questions/48377175/how-to-add-middleware-for-one-or-two-controllers-in-symfony4
自定义AccessDeniedException异常处理:
https://symfony.com/doc/current/security/access_denied_handler.html
还有就是找到一个middleware的composer包,不过感觉用的人挺少:
https://github.com/kafkiansky/symfony-middleware
自定义authenticator,这个主要是为了定义多个firewall的时候用到,比如后台一套 接口一套:
https://symfony.com/doc/current/security/custom_authenticator.html,使用:https://symfony.com/doc/current/security/entry_point.html#multiple-authenticators-with-separate-entry-points
虽然不能直接在控制器里定义roles,但是可以通过 $this->denyAccessUnlessGranted('ROLE_USER'); 来判断是否有 ROLE_USER 角色,进而判断用户是否登录,也可以通过 #[IsGranted('ROLE_ADMIN')] 来决定:
https://symfony.com/doc/current/security.html#security-securing-controller
