我正在擴展身份驗證失敗處理程序,並且一切主要工作正常,但是有一個小問題。覆蓋身份驗證失敗處理程序 - 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的名字一樣。當然,這些價值可以更好地提供?