eZ\Publish\Core\REST\Server\Security\RestAuthenticator::logout PHP Method

logout() public method

public logout ( Request $request )
$request Symfony\Component\HttpFoundation\Request
    public function logout(Request $request)
    {
        $response = new Response();
        // Manually clear the session through session storage.
        // Session::invalidate() is not called on purpose, to avoid unwanted session migration that would imply
        // generation of a new session id.
        // REST logout must indeed clear the session cookie.
        // See \eZ\Publish\Core\REST\Server\Security\RestLogoutHandler
        $this->sessionStorage->clear();
        $token = $this->tokenStorage->getToken();
        foreach ($this->logoutHandlers as $handler) {
            // Explicitly ignore SessionLogoutHandler as we do session invalidation manually here,
            // through the session storage, to avoid unwanted session migration.
            if ($handler instanceof SessionLogoutHandler) {
                continue;
            }
            $handler->logout($request, $response, $token);
        }
        return $response;
    }

Usage Example

 public function testLogout()
 {
     $sessionLogoutHandler = $this->getMock('Symfony\\Component\\Security\\Http\\Logout\\SessionLogoutHandler');
     $sessionLogoutHandler->expects($this->never())->method('logout');
     $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
     $this->tokenStorage->expects($this->once())->method('getToken')->will($this->returnValue($token));
     $request = new Request();
     $logoutHandler1 = $this->getMock('Symfony\\Component\\Security\\Http\\Logout\\LogoutHandlerInterface');
     $logoutHandler1->expects($this->once())->method('logout')->with($request, $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response'), $token);
     $logoutHandler2 = $this->getMock('Symfony\\Component\\Security\\Http\\Logout\\LogoutHandlerInterface');
     $logoutHandler2->expects($this->once())->method('logout')->with($request, $this->isInstanceOf('Symfony\\Component\\HttpFoundation\\Response'), $token);
     $this->authenticator->addLogoutHandler($sessionLogoutHandler);
     $this->authenticator->addLogoutHandler($logoutHandler1);
     $this->authenticator->addLogoutHandler($logoutHandler2);
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $this->authenticator->logout($request));
 }