From d4309720fe7ebaf9c3c1610024800504a90ae504 Mon Sep 17 00:00:00 2001 From: Valantis Koutsoumpos Date: Fri, 4 May 2018 18:02:22 +0200 Subject: [PATCH 1/2] Added documentation about authentication for multiple firewalls under the same firewall context --- testing/http_authentication.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/testing/http_authentication.rst b/testing/http_authentication.rst index 8d5d37970cf..31c4ae3267a 100644 --- a/testing/http_authentication.rst +++ b/testing/http_authentication.rst @@ -124,3 +124,22 @@ needs:: $this->client->getCookieJar()->set($cookie); } } + +If your setup contains multiple firewalls sharing the same firewall context, you need to generate the +*authentication token* by using one of the firewall names as provider key and set the security session +using the firewall context name:: + + private function logIn() + { + $session = $this->client->getContainer()->get('session'); + + $firewallName = 'secure_area'; + $firewallContext = 'firewall_context'; + + $token = new UsernamePasswordToken('admin', null, $firewallName, array('ROLE_ADMIN')); + $session->set('_security_'.$firewallContext, serialize($token)); + $session->save(); + + $cookie = new Cookie($session->getName(), $session->getId()); + $this->client->getCookieJar()->set($cookie); + } From eae4a3c48afc3dedff7162879b556f16ad822afa Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 21 May 2018 17:32:27 +0200 Subject: [PATCH 2/2] Reword --- testing/http_authentication.rst | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/testing/http_authentication.rst b/testing/http_authentication.rst index 31c4ae3267a..8833878c424 100644 --- a/testing/http_authentication.rst +++ b/testing/http_authentication.rst @@ -109,32 +109,14 @@ needs:: $this->assertSame('Admin Dashboard', $crawler->filter('h1')->text()); } - private function logIn() - { - $session = $this->client->getContainer()->get('session'); - - // the firewall context defaults to the firewall name - $firewallContext = 'secured_area'; - - $token = new UsernamePasswordToken('admin', null, $firewallContext, array('ROLE_ADMIN')); - $session->set('_security_'.$firewallContext, serialize($token)); - $session->save(); - - $cookie = new Cookie($session->getName(), $session->getId()); - $this->client->getCookieJar()->set($cookie); - } - } - -If your setup contains multiple firewalls sharing the same firewall context, you need to generate the -*authentication token* by using one of the firewall names as provider key and set the security session -using the firewall context name:: - private function logIn() { $session = $this->client->getContainer()->get('session'); $firewallName = 'secure_area'; - $firewallContext = 'firewall_context'; + // if you don't define multiple connected firewalls, the context defaults to the firewall name + // See https://symfony.com/doc/current/reference/configuration/security.html#firewall-context + $firewallContext = 'secured_area'; $token = new UsernamePasswordToken('admin', null, $firewallName, array('ROLE_ADMIN')); $session->set('_security_'.$firewallContext, serialize($token)); @@ -143,3 +125,4 @@ using the firewall context name:: $cookie = new Cookie($session->getName(), $session->getId()); $this->client->getCookieJar()->set($cookie); } + }