我正在扩展身份验证失败处理程序,并且一切主要工作正常,但是有一个小问题。覆盖身份验证失败处理程序 - Symfony2
这是我services.yml:
http.utils.class:
class: Symfony\Component\Security\Http\HttpUtils
auth.fail:
class: Acme\MyBundle\AuthenticationFailure
arguments:
- @http_kernel
- @http.utils.class
- []
我已将这security.yml使用:
failure_handler: auth.fail
这是我的Acme \ MyBundle \ AuthenticationFailure.php:
namespace Acme\MyBundle;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
use Symfony\Component\HttpFoundation\Response;
class AuthenticationFailure extends DefaultAuthenticationFailureHandler
{
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
//do something
}
}
问题是我在security.yml中设置的选项被忽略。我知道该类的_construct方法的第三个参数是$ options数组,并且我没有传入任何东西作为第三个参数(在services.yml中),所以我猜这是问题,解决方案可能会是只传递中的值我猜我也可以做这样的事情:
arguments:
- @http_kernel
- @http.utils.class
- %security.firewalls.secure_area.form_login%
....我没有测试的问题是,这是硬编码在services.yml它不是理想的,就好像我改变了它会破坏的secure_area的名字一样。当然,这些价值可以更好地提供?