Symfony AuthenticatorInterface::supports()方法的用途是什么?

Symfony AuthenticatorInterface::supports()方法的用途是什么?,symfony,symfony-security,symfony-flex,symfony4,Symfony,Symfony Security,Symfony Flex,Symfony4,在Symfony 4中,AuthenticatorInterface::supports()方法具有以下注释: interface AuthenticatorInterface extends AuthenticationEntryPointInterface { /** * Does the authenticator support the given Request? * * If this returns false, the authenticat

在Symfony 4中,AuthenticatorInterface::supports()方法具有以下注释:

interface AuthenticatorInterface extends AuthenticationEntryPointInterface
{
    /**
     * Does the authenticator support the given Request?
     *
     * If this returns false, the authenticator will be skipped.
     *
     * @param Request $request
     *
     * @return bool
     */
    public function supports(Request $request);
我觉得措辞令人困惑。当我尝试实现这一点时,我的第一反应是,如果请求包含
用户名
密码
字段,则返回true,但是我记得,我收到的所有请求都得到了验证,即使我没有使用登录表单

supports()
方法是覆盖
security.firewalls.myFirewall.pattern
参数的一种方法吗?它是处理多个身份验证程序之间的流的东西吗


我应该如何使用这个界面?

我同意这个功能还没有很好的文档记录。我唯一能找到的是:

支持(请求$Request)

这将在每次请求和 您的工作是决定是否应该为此使用验证器 请求(返回true)或是否应跳过请求(返回false)

例如:您可以使用
请求
检查它是否是XMLHttpRequest(AJAX),因此您可以使用专用的
AjaxAuthenticator


类似的功能(
VoterInterface::support()
)记录在。

此接口取代了在Symfony 3.4中不推荐使用并从Symfony 3.4中删除的
GuardAuthenticationInterface

这一区别在于前者的
GuardAuthenticationInterface
只定义了一个
getCredentials
方法,该方法返回
NULL
或任何形式的凭据。在某些情况下,有许多方法可以获取验证器的凭据,
getCredentials
方法以任何方式进行处理,直到返回某个内容,或者结束时不返回任何内容(这几乎相当于空返回)

当您使用多个验证器时,您不希望等待每个验证器都不返回任何内容来传递给下一个验证器。因此,如果必须调用authenticator
getCredentials
方法,则出现此
支持的
方法将返回是或否。请注意,在新的
AuthenticationInterface
中,
getCredentials
方法总是应该返回一些内容


这里是

在阅读了更多的源代码之后,这也是我的猜测。它看起来像是在特定防火墙中有多个身份验证器时使用的。在进一步挖掘文档后,我发现:这听起来像是只有当用户提交登录表单时,我们才应该返回true。你应该用你的评论内容写一个响应。在写我的之前我没有看到他们,但是你有一个很好的解释!