因此,没有“官方”登录前事件。但值得庆幸的是,由于Symfony2如此可扩展,因此设置起来并不难。诀窍是使用您自己的服务来处理身份验证。
Symfony在使用登录表单时使用此类:
SymfonyComponentSecurityHttpFirewallUsernamePasswordFormAuthenticationListener
如果您覆盖
security.authentication.listener.form.class参数(最初在中定义
SymfonyBundleSecurityBundleResourcesconfigsecurity_listeners.xml),则可以使用扩展的自定义侦听器
UsernamePasswordFormAuthenticationListener。
剩下要做的就是重写
attemptAuthentication()方法以调度自定义事件。
(实际上,您还需要将事件分发程序存储为的类属性
__construct())
此方法应与其它认证方法的工作-
所有你需要做的就是修改相应的监听器(即
BasicAuthenticationListener,
X509AuthenticationListener等)



