多个防火墙提升了Symfony 5.4的安全性
<p>我正在尝试将用户的身份验证与管理员的身份验证分开。</p>
<p>所以我创建了2个防火墙和2个不同的访问控制。</p>
<p>我的security.yaml文件如下:</p>
<pre class="brush:php;toolbar:false;">enable_authenticator_manager: true
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
providers:
owner_authentication:
entity:
class: App\Entity\Merchant\Owner
property: emailAddress
user_authentication:
entity:
class: App\Entity\User\User
property: emailAddress
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
user:
lazy: true
pattern: ^/admin/login/
provider: user_authentication
user_checker: App\Security\AuthentificableModelChecker
form_login:
provider: user_authentication
default_target_path: app.dashboard.index
use_referer: true
use_forward: false
login_path: app.authorization.admin_login
check_path: app.authorization.admin_login
username_parameter: login[emailAddress]
password_parameter: login[password]
logout:
path: app.authorization.logout
target: app.authorization.admin_login
main:
lazy: true
pattern: ^/
provider: owner_authentication
user_checker: App\Security\AuthentificableModelChecker
form_login:
provider: owner_authentication
default_target_path: app.dashboard.index
use_referer: true
use_forward: false
login_path: app.authorization.login
check_path: app.authorization.login
username_parameter: login[emailAddress]
password_parameter: login[password]
logout:
path: app.authorization.logout
target: app.authorization.login
access_control:
- { path: ^/admin/login, roles: PUBLIC_ACCESS}
- { path: ^/login, roles: PUBLIC_ACCESS }
- { path: ^/, roles: ROLE_USER }</pre>
<p>主防火墙上的一切都正常工作,但当我使用用户(管理员)防火墙提交按钮时,登录页面会刷新自身,然后什么也不发生。我没有任何错误。</p>
<p>** 如果我在主防火墙上添加用户(管理员)登录,那么/admin/login将正常工作,而另一个则不再工作。</p>
<p>当我调用<code>$authenticationUtils->getLastAuthenticationError()</code>时,我没有收到任何错误。但验证也不起作用。</p>
<p>这是我的控制器的样子:</p>
<pre class="brush:php;toolbar:false;">public function adminLogin(AuthenticationUtils $authenticationUtils): Response
{
if ($this->getUser()) {
return $this->redirectToRoute('app.dashboard.index');
}
$loginForm = $this->createForm(LoginType::class, ['emailAddress' => $authenticationUtils->getLastUsername()]);
return $this->renderForm('app/pages/authorization/admin_login.html.twig', [
'title' => 'Log in',
'login_form' => $loginForm,
'error' => $authenticationUtils->getLastAuthenticationError()?->getMessageKey(),
]);
}</pre>
<p>这是一个人遇到的相同问题:https://grafikart.fr/forum/35234,但我找不到任何解决方案。</p>