diff --git a/ApplicationConfig/Providers/SessionInfo.php b/ApplicationConfig/Providers/SessionInfo.php index b4d2e21ed..51668ae69 100644 --- a/ApplicationConfig/Providers/SessionInfo.php +++ b/ApplicationConfig/Providers/SessionInfo.php @@ -29,9 +29,9 @@ class SessionInfo implements Provider public function __construct( SessionInterface $session, - CsrfTokenManagerInterface $csrfTokenManager, $csrfTokenIntention, - RouterInterface $router + RouterInterface $router, + CsrfTokenManagerInterface $csrfTokenManager = null ) { $this->session = $session; $this->csrfTokenManager = $csrfTokenManager; @@ -46,11 +46,14 @@ public function getConfig() $sessionInfo['isStarted'] = true; $sessionInfo['name'] = $this->session->getName(); $sessionInfo['identifier'] = $this->session->getId(); - $sessionInfo['csrfToken'] = $this->csrfTokenManager->getToken($this->csrfTokenIntention)->getValue(); $sessionInfo['href'] = $this->generateUrl( 'ezpublish_rest_deleteSession', ['sessionId' => $this->session->getId()] ); + + if ($this->csrfTokenManager instanceof CsrfTokenManagerInterface) { + $sessionInfo['csrfToken'] = $this->csrfTokenManager->getToken($this->csrfTokenIntention)->getValue(); + } } return $sessionInfo; diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 2db8eb3f6..064dd0912 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -60,9 +60,9 @@ services: class: %ezsystems.platformui.application_config.provider.session_info.class% arguments: - @session - - @security.csrf.token_manager - %ezpublish_rest.csrf_token_intention% - @router + - @?security.csrf.token_manager tags: - {name: ezsystems.platformui.application_config_provider, key: 'sessionInfo'} diff --git a/Tests/ApplicationConfig/Providers/SessionInfoTest.php b/Tests/ApplicationConfig/Providers/SessionInfoTest.php index c50e00884..8cf1c0f02 100644 --- a/Tests/ApplicationConfig/Providers/SessionInfoTest.php +++ b/Tests/ApplicationConfig/Providers/SessionInfoTest.php @@ -32,6 +32,26 @@ public function testGetConfig() ); } + public function testGetConfigWithoutTokenManager() + { + $provider = new SessionInfo( + $this->createSession(), + null, + 'intention', + $this->getRouterMock('/api/ezp/v2/user/sessions/the_session_id') + ); + + self::assertEquals( + [ + 'isStarted' => true, + 'name' => 'the_session_name', + 'identifier' => 'the_session_id', + 'href' => '/api/ezp/v2/user/sessions/the_session_id', + ], + $provider->getConfig() + ); + } + /** * @return \Symfony\Component\HttpFoundation\Session\SessionInterface|\PHPUnit_Framework_MockObject_MockObject */