简体   繁体   English

为什么Symfony不使用表单来处理安全组件登录?

[英]Why Symfony dont use a Form to handle security component login?

From document https://symfony.com/doc/current/security/form_login_setup.html that describe how to setup a login form that work with Symfony Security component, I am surprised to not see the use of Symfony Form component. 从描述如何设置与Symfony Security组件一起使用的登录表单的文档https://symfony.com/doc/current/security/form_login_setup.html中,我很惊讶地没有看到Symfony Form组件的使用。

They render the form in pure HTML, and the form is handled by some magic, by the security component somewhere (and break the concept of Controller that should handle the HTTP request). 他们以纯HTML格式呈现表单,并且表单由某种魔术,安全组件在某处处理(并打破了应该处理HTTP请求的Controller的概念)。

Is there a particular reason to not use a Form type here? 是否有特定的原因不使用Form类型? (and also a controller). (以及控制器)。

Symfony security does not use forms as forms works with submitted data and most of the authentication methods is done using the HTTP Headers which a form does not have access. Symfony安全性不使用表单,因为表单可处理提交的数据,并且大多数身份验证方法是使用表单无法访问的HTTP标头完成的。

Security component has 2 roles: Authentication and authorization. 安全组件具有2个角色:身份验证和授权。 You are mentioning authentication in this question. 您在此问题中提到身份验证。

Authentication it is way more complex than just handling a form in a controller. 身份验证比仅在控制器中处理表单要复杂得多。

Only one of the authentication methods implies a form submit in symfony: UsernamePasswordToken and even that can be submitted as a http basic/digest authentication via a header. 仅一种身份验证方法意味着以symfony形式提交表单:UsernamePasswordToken,甚至可以通过标头将其作为http基本/摘要身份验证提交。

Other ways of login/authentication/authorization is via the remember me token, sessions, oauth tokens, Json Web Tokens, SAML, etc. 其他登录/身份验证/授权方式是通过“记住我”令牌,会话,oauth令牌,Json Web令牌,SAML等。

The more flexible way is to just have a authentication system based in events, although this adds quite complexity to the system that has been addressed with Symfony Guard in Symfony 3. 更为灵活的方法是仅基于事件建立身份验证系统,尽管这给使用Symfony 3中的Symfony Guard解决的系统增加了相当的复杂性。

在此处输入图片说明

https://symfony.com/doc/2.0/book/security.html https://symfony.com/doc/2.0/book/security.html

I finally wrote my own GuardAuthenticator that handle Symfony form (extends Symfony\\Component\\Security\\Guard\\Authenticator\\AbstractFormLoginAuthenticator): 最后,我编写了自己的处理Symfony表单的GuardAuthenticator(扩展了Symfony \\ Component \\ Security \\ Guard \\ Authenticator \\ AbstractFormLoginAuthenticator):

Symfony表单卫士身份验证器

This work like a charm! 这项工作就像一种魅力! and the design team can use form easily. 设计团队可以轻松使用表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM