Heim  >  Fragen und Antworten  >  Hauptteil

Mehrere Firewalls verbessern die Sicherheit in Symfony 5.4

<p>Ich versuche, die Authentifizierung des Benutzers von der Authentifizierung des Administrators zu trennen. </p> <p>Also habe ich zwei Firewalls und zwei verschiedene Zugriffskontrollen erstellt. </p> <p>Meine security.yaml-Datei lautet wie folgt:</p> <pre class="brush:php;toolbar:false;">enable_authenticator_manager: true passwort_hasher: SymfonyComponentSecurityCoreUserPasswordAuthenticatedUserInterface: 'auto' Anbieter: owner_authentication: juristische Person: Klasse: AppEntityMerchantOwner Eigenschaft: emailAddress Benutzerauthentifizierung: juristische Person: Klasse:AppEntityUserUser Eigenschaft: emailAddress Firewalls: Entwickler: Muster: ^/(_(profiler|wdt)|css|images|js)/ Sicherheit: falsch Benutzer: faul: stimmt Muster: ^/admin/login/ Anbieter: user_authentication user_checker: AppSecurityAuthentificableModelChecker form_login: Anbieter: 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] Passwortparameter: Login[Passwort] Ausloggen: Pfad: app.authorization.logout Ziel: app.authorization.admin_login hauptsächlich: faul: stimmt Muster: ^/ Anbieter:owner_authentication user_checker: AppSecurityAuthentificableModelChecker form_login: Anbieter:owner_authentication default_target_path: app.dashboard.index use_referer: wahr use_forward: false login_path: app.authorization.login check_path: app.authorization.login username_parameter: login[emailAddress] Passwortparameter: Login[Passwort] Ausloggen: Pfad: app.authorization.logout Ziel: app.authorization.login Zugangskontrolle: - { Pfad: ^/admin/login, Rollen: PUBLIC_ACCESS} - { Pfad: ^/login, Rollen: PUBLIC_ACCESS } - { Pfad: ^/, Rollen: ROLE_USER }</pre> <p>Auf der Haupt-Firewall funktioniert alles einwandfrei, aber wenn ich die Submit-Schaltfläche der Benutzer-Firewall (Administrator) verwende, aktualisiert sich die Anmeldeseite von selbst und dann passiert nichts. Ich bekomme keine Fehler. </p> <p>** Wenn ich einen Benutzer-Login (Administrator) zur Haupt-Firewall hinzufüge, funktioniert /admin/login einwandfrei und der andere nicht mehr. </p> <p>Wenn ich <code>$authenticationUtils->getLastAuthenticationError()</code> aufrufe, erhalte ich keine Fehlermeldungen. Aber auch die Validierung funktioniert nicht.</p> <p>So sieht mein Controller aus:</p> <pre class="brush:php;toolbar:false;">public function adminLogin(AuthenticationUtils $authenticationUtils): Antwort { 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' => 'Anmelden', 'login_form' => $loginForm, 'error' => $authenticationUtils->getLastAuthenticationError()?->getMessageKey(), ]); }</pre> <p>Das ist das gleiche Problem, das jemand hatte: https://grafikart.fr/forum/35234, aber ich konnte keine Lösung finden. </p>
P粉952365143P粉952365143390 Tage vor531

Antworte allen(1)Ich werde antworten

  • P粉041881924

    P粉0418819242023-08-27 10:46:01

    最后,我找到了答案,我会在这里发布:https://stackoverflow.com/a/42352112/8003007 我所需要做的是在两个防火墙中添加一个context: my_context

    这是一个难以识别的选项,因为它在官方和当前的Symfony文档中并没有出现,只出现在之前的版本中,比如Symfony 3.4。

    Antwort
    0
  • StornierenAntwort