‪TYPO3CMS  ‪main
BackendFormProtection.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
75 {
82  protected ‪$backendUser;
83 
90  protected ‪$registry;
91 
98  {
99  $this->backendUser = ‪$backendUser;
100  $this->registry = ‪$registry;
101  $this->validationFailedCallback = ‪$validationFailedCallback;
102  if (!$this->‪isAuthorizedBackendSession()) {
103  throw new ‪Exception('A back-end form protection may only be instantiated if there is an active back-end session.', 1285067843);
104  }
105  }
106 
112  protected function ‪retrieveSessionToken()
113  {
114  $this->sessionToken = $this->backendUser->getSessionData('formProtectionSessionToken');
115  if (empty($this->sessionToken)) {
116  $this->sessionToken = $this->‪generateSessionToken();
117  $this->‪persistSessionToken();
118  }
119  return ‪$this->sessionToken;
120  }
121 
128  public function ‪persistSessionToken()
129  {
130  $this->backendUser->setAndSaveSessionData('formProtectionSessionToken', $this->sessionToken);
131  }
132 
141  public function ‪setSessionTokenFromRegistry()
142  {
143  $this->sessionToken = $this->registry->get('core', 'formProtectionSessionToken:' . $this->backendUser->user['uid']);
144  if (empty($this->sessionToken)) {
145  throw new \UnexpectedValueException('Failed to restore the session token from the registry.', 1301827270);
146  }
147  return ‪$this->sessionToken;
148  }
149 
156  public function ‪storeSessionTokenInRegistry()
157  {
158  $this->registry->set('core', 'formProtectionSessionToken:' . $this->backendUser->user['uid'], $this->getSessionToken());
159  }
160 
166  public function ‪removeSessionTokenFromRegistry()
167  {
168  $this->registry->remove('core', 'formProtectionSessionToken:' . $this->backendUser->user['uid']);
169  }
170 
176  protected function ‪isAuthorizedBackendSession()
177  {
178  return !empty($this->backendUser->user['uid']);
179  }
180 }
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\removeSessionTokenFromRegistry
‪removeSessionTokenFromRegistry()
Definition: BackendFormProtection.php:164
‪TYPO3\CMS\Core\FormProtection\AbstractFormProtection\$sessionToken
‪string null $sessionToken
Definition: AbstractFormProtection.php:41
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection
Definition: BackendFormProtection.php:75
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\isAuthorizedBackendSession
‪bool isAuthorizedBackendSession()
Definition: BackendFormProtection.php:174
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\__construct
‪__construct(BackendUserAuthentication $backendUser, Registry $registry, \Closure $validationFailedCallback=null)
Definition: BackendFormProtection.php:95
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\setSessionTokenFromRegistry
‪string setSessionTokenFromRegistry()
Definition: BackendFormProtection.php:139
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\persistSessionToken
‪persistSessionToken()
Definition: BackendFormProtection.php:126
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\$backendUser
‪BackendUserAuthentication $backendUser
Definition: BackendFormProtection.php:81
‪TYPO3\CMS\Core\FormProtection
Definition: AbstractFormProtection.php:16
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\retrieveSessionToken
‪string retrieveSessionToken()
Definition: BackendFormProtection.php:110
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Error\Exception
Definition: Exception.php:21
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\storeSessionTokenInRegistry
‪storeSessionTokenInRegistry()
Definition: BackendFormProtection.php:154
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection\$registry
‪Registry $registry
Definition: BackendFormProtection.php:88
‪TYPO3\CMS\Core\FormProtection\AbstractFormProtection
Definition: AbstractFormProtection.php:31
‪TYPO3\CMS\Core\FormProtection\AbstractFormProtection\$validationFailedCallback
‪Closure null $validationFailedCallback
Definition: AbstractFormProtection.php:35
‪TYPO3\CMS\Core\FormProtection\AbstractFormProtection\generateSessionToken
‪string generateSessionToken()
Definition: AbstractFormProtection.php:115