我看到你正试图通过登录路径到您的身份验证失败处理程序...
...你应该注射@router
,适应__construct
方法并生成 url路线名称 ( 不是图案)由您的防火墙在身份验证失败处理程序中使用。然后将用户重定向到那里...
login_path: your_login_route_name # <- not a pattern like /login
这样更改防火墙的名称不会破坏您的应用程序!
如果您甚至不想在更改路由名称时破坏应用程序,您也可以进行配置:
配置.yml
parameters:
login.route_name: my_login_route_name
路由.yml
%login.route_name%:
pattern: /login
安全.yml
security:
firewalls:
your_firewall_name:
failure_handler: auth.fail
login_path: %login.route_name%
服务.yml
auth.fail:
arguments:
- # ...
- @router
- %login.route_name%
Acme\MyBundle\AuthenticationFailure
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
// ...
protected $router;
protected $loginRoute;
public function __construct(
/** ... other arguments **/,
RouterInterface $router,
$loginRoute
)
{
// ..
$this->router = $router;
$this->loginRoute = $loginRoute;
}
public function onAuthenticationFailure(
Request $request,
AuthenticationException $exception
)
{
// ...
return new RedirectResponse( $this->router->generate($this->loginRoute) );
}
关于您的建议的提示
(...使用类似的东西%security.firewalls.secure_area.form_login%
)
您无法直接访问安全配置(这些不是参数 - 您不能使用%security.firewall.whatever%
! ) ...
默认的$options
传递给__construct
必须是一个数组...
...所以你可能需要将传递的参数包围起来[]
如果这些参数不是数组。
arguments:
- [ %parameter1% , %parameter2% ]