And*_*ord 5 authentication symfony fosuserbundle
我试图了解Symfony 2.8使用FOSUserBundle. 设置没有问题,一切正常,我只是想了解它是如何工作的。
登录表单将用户名+密码发送到定义在以下路径中的fos_user_security_check路由( ) :/login_checkFOSUserBunde\Resources\config\routing\security.xml
<route id="fos_user_security_check" path="/login_check" methods="POST">
<default key="_controller">FOSUserBundle:Security:check</default>
</route>
Run Code Online (Sandbox Code Playgroud)
所以FOSUserBundle:Security:checkaction负责处理请求。然而,实现看起来像这样:
public function checkAction() {
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
}
Run Code Online (Sandbox Code Playgroud)
所以我查看了防火墙配置/app/config/security.yml:
security:
...
firewalls:
...
main:
...
form_login:
provider: fos_userbundle
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
Run Code Online (Sandbox Code Playgroud)
这里check_path也指fos_user_security_check... 那么,认证实际上是在哪里处理的呢?
身份验证不在 FOSUserBundle 内部处理,它只是提供一些基本参数以及如何从数据库检索用户的提供程序 ( fos_userbundle)。
您需要了解Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener有关身份验证失败和成功时会发生什么情况的一些基础知识。您可以查看那里的Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener方法attemptAuthentication(),然后按照那里调用的身份验证管理器服务authenticate()。
您最终将到达Symfony\Component\Security\Core\Encoder\UserPasswordEncoder该isPasswordValid()函数,该函数检查您拥有的任何编码器(可能Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder),最终调用 PHP 的password_verify函数。
您以这种方式看到控制器操作的原因是您永远不应该login_check直接调用。因此,如果您到达那里,则说明某些内容配置错误,这就是引发异常的原因。请参阅文档中的check_path变量以及此 Stackoverflow 答案以获取有关此内容的更多信息。
| 归档时间: |
|
| 查看次数: |
2420 次 |
| 最近记录: |