Symfony2实体用户提供程序覆盖自定义身份验证提供程序

Dan*_* B. 7 php authentication rest restful-authentication symfony

我的Symfony2自定义身份验证提供程序现在似乎正在运行.

用户提供商

我几乎使用了FOSUserBundle,但我甚至没有为我的用户提供电子邮件地址,而且我不需要增加的功能或复杂功能.

所以我只是使用实体提供程序.

我将我的编码器设置为纯文本,因为API客户端库为我处理这个问题,但是,另一个障碍:似乎用户现在正在针对这些用户记录进行身份验证.

在我实现实体用户提供程序之前,我的登录表单给了我有效的响应:正确的凭据没有产生错误,错误的凭据导致我的自定义"不正确的用户/通过错误".

现在,即使我提供了我知道正确的凭据,我得到的只是错误消息"Bad credentials" ,好像我正在实现UserAuthenticationProvider,但据我所知,我不是.我的自定义提供程序直接实现AuthenticationProviderInterface.

所以目前我认为我错误地实现了实体用户提供程序,这样它就会以某种方式覆盖我的自定义身份验证提供程序.同时配置实体用户提供程序和自定义身份验证提供程序的正确方法是什么?

security.yml的相关部分

encoders:
    WordRot\PlayBundle\Entity\User: plaintext

providers:
    wordnik_users:
        entity: { class: WordRotPlayBundle:User, property: username }

firewalls:
    wordnik_secured:
        pattern: ^/play
        logout: ~
        anonymous: ~
        # The next line specifies the custom authentication provider:
        wordnik: true 
        form_login:
            provider: wordnik_users
            login_path:  /login
            check_path:  /play_check
            # on success
            always_use_default_target_path: true
            default_target_path: /play
Run Code Online (Sandbox Code Playgroud)

编辑

这可能证明是有用的.这是主分支的差异......

  • 定义身份验证提供程序(WordnikProvider)仍然执行时(a473d354)
  • 主分支(ddcfeae2)上的最新提交,其中不再执行auth提供程序.

编辑2

我发现有更多的断点:

  1. 在登录表单POST上,使用UsernamePasswordToken调用WordnikProvider#supports,从而返回false.
  2. 在登录表单上POST,WordnikListener构造但是从不调用其他方法(attemptAuthentication,requiresAuthentication).然而WordnikFactory#createListener,从来没有被称为!听众的构建令人惊讶.
  3. 但是在login_checkGET上,WordnikListener#requiresAuthenticationIS被称为.

Cer*_*rad 1

所以我们对此进行了长时间的讨论。基本问题是 form_login 服务干扰了 wodnik 服务。删除了 form_login,一切开始变得更好。

https://chat.stackoverflow.com/rooms/25251/discussion- Between-montgomery-jean-and-cerad