多個防火牆提升了Symfony 5.4的安全性
P粉952365143
P粉952365143 2023-08-26 16:14:30
0
1
524
<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>
P粉952365143
P粉952365143

全部回覆(1)
P粉041881924

最後,我找到了答案,我會在這裡發布:https://stackoverflow.com/a/42352112/8003007 我所需要做的是在兩個防火牆中新增一個context: my_context

這是一個難以辨識的選項,因為它在官方和目前的Symfony文件中並沒有出現,只出現在先前的版本中,例如Symfony 3.4。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!