‪TYPO3CMS  9.5
FrontendBackendUserAuthentication.php
Go to the documentation of this file.
1 <?php
2 namespace ‪TYPO3\CMS\Backend;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
28 
35 {
36 
42  public ‪$formfield_uname = '';
43 
49  public ‪$formfield_uident = '';
50 
57  public ‪$formfield_status = '';
58 
64  public ‪$writeStdLog = false;
65 
71  public ‪$writeAttemptLog = false;
72 
79  public ‪$extAdmEnabled = false;
80 
85  public ‪$adminPanel;
86 
91  public ‪$frontendEdit;
92 
97  public ‪$extAdminConfig = [];
98 
104  public function ‪initializeAdminPanel()
105  {
106  trigger_error('FrontendBackendUserAuthentication->initializeAdminPanel() will be removed in TYPO3 v10.0 - initialization is done via middleware.', E_USER_DEPRECATED);
107  }
108 
114  public function ‪initializeFrontendEdit()
115  {
116  trigger_error('FrontendBackendUserAuthentication->initializeFrontendEdit() will be removed in TYPO3 v10.0 - initialization is done via middleware.', E_USER_DEPRECATED);
117  }
118 
125  public function ‪isFrontendEditingActive()
126  {
127  trigger_error('FrontendBackendUserAuthentication->isFrontendEditingActive() will be removed in TYPO3 v10.0 - use underlying TSFE directly.', E_USER_DEPRECATED);
128  return $this->extAdmEnabled && (
129  $this->adminPanel->isAdminModuleEnabled('edit') ||
130  (int)‪$GLOBALS['TSFE']->displayEditIcons === 1 ||
131  (int)‪$GLOBALS['TSFE']->displayFieldEditIcons === 1
132  );
133  }
134 
141  public function ‪displayAdminPanel()
142  {
143  trigger_error('FrontendBackendUserAuthentication->displayAdminPanel() will be removed in TYPO3 v10.0 - use MainController of adminpanel extension.', E_USER_DEPRECATED);
144  return $this->adminPanel->display();
145  }
146 
153  public function ‪isAdminPanelVisible()
154  {
155  trigger_error('FrontendBackendUserAuthentication->isAdminPanelVisible() will be removed in TYPO3 v10.0 - use new adminpanel API instead.', E_USER_DEPRECATED);
156  return $this->extAdmEnabled && !$this->extAdminConfig['hide'] && ‪$GLOBALS['TSFE']->config['config']['admPanel'];
157  }
158 
159  /*****************************************************
160  *
161  * TSFE BE user Access Functions
162  *
163  ****************************************************/
172  {
173  trigger_error('FrontendBackendUserAuthentication->checkBackendAccessSettingsFromInitPhp() will be removed in TYPO3 v10.0. Use a PSR-15 middleware and backendCheckLogin() instead.', E_USER_DEPRECATED);
174  // Check Hardcoded lock on BE
175  if (‪$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
176  return false;
177  }
178  // Check IP
179  if (trim(‪$GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
180  if (!GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), ‪$GLOBALS['TYPO3_CONF_VARS']['BE']['IPmaskList'])) {
181  return false;
182  }
183  }
184  // Check IP mask based on TSconfig
185  if (!$this->‪checkLockToIP()) {
186  return false;
187  }
188  // Check SSL (https)
189  if ((bool)‪$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSL'] && !GeneralUtility::getIndpEnv('TYPO3_SSL')) {
190  return false;
191  }
192  // Finally a check as in BackendUserAuthentication::backendCheckLogin()
193  return $this->‪isUserAllowedToLogin();
194  }
195 
203  public function ‪backendCheckLogin($proceedIfNoUserIsLoggedIn = false)
204  {
205  if (empty($this->user['uid'])) {
206  return false;
207  }
208  // Check Hardcoded lock on BE
209  if (‪$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
210  return false;
211  }
212  // Check IP mask based on TSconfig
213  if (!$this->‪checkLockToIP()) {
214  return false;
215  }
216  return $this->‪isUserAllowedToLogin();
217  }
218 
232  public function ‪extPageReadAccess($pageRec)
233  {
234  trigger_error('FrontendBackendUserAuthentication->extPageReadAccess() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
235  return $this->‪isInWebMount($pageRec['uid']) && $this->‪doesUserHaveAccess($pageRec, ‪Permission::PAGE_SHOW);
236  }
237 
238  /*****************************************************
239  *
240  * TSFE BE user Access Functions
241  *
242  ****************************************************/
254  public function ‪extGetTreeList(‪$id, $depth, $begin = 0, $perms_clause)
255  {
256  trigger_error('FrontendBackendUserAuthentication->extGetTreeList() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
258  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
259  ->getQueryBuilderForTable('pages');
260 
261  $queryBuilder->getRestrictions()
262  ->removeAll()
263  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
264 
265  $depth = (int)$depth;
266  $begin = (int)$begin;
267  ‪$id = (int)‪$id;
268  $theList = '';
269  if (‪$id && $depth > 0) {
270  $result = $queryBuilder
271  ->select('uid', 'title')
272  ->from('pages')
273  ->where(
274  $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter(‪$id, \PDO::PARAM_INT)),
275  $queryBuilder->expr()->eq('sys_language_uid', 0),
277  )
278  ->execute();
279  while ($row = $result->fetch()) {
280  if ($begin <= 0) {
281  $theList .= $row['uid'] . ',';
282  }
283  if ($depth > 1) {
284  $theList .= $this->‪extGetTreeList($row['uid'], $depth - 1, $begin - 1, $perms_clause);
285  }
286  }
287  }
288  return $theList;
289  }
290 
303  public function ‪allowedToEditLanguage($table, array $currentRecord): bool
304  {
305  // If no access right to record languages, return immediately
307  $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
308  if ($table === 'pages') {
309  $languageId = $languageAspect->getId();
310  } elseif ($table === 'tt_content') {
311  $languageId = $languageAspect->getContentId();
312  } elseif (‪$GLOBALS['TCA'][$table]['ctrl']['languageField']) {
313  $languageId = $currentRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']];
314  } else {
315  $languageId = -1;
316  }
317  return $this->‪checkLanguageAccess($languageId);
318  }
319 
329  public function ‪allowedToEdit(string $table, array $dataArray, array $conf, bool $checkEditAccessInternals): bool
330  {
331  // Unless permissions specifically allow it, editing is not allowed.
332  $mayEdit = false;
333  if ($checkEditAccessInternals) {
334  $editAccessInternals = $this->‪recordEditAccessInternals($table, $dataArray, false, false);
335  } else {
336  $editAccessInternals = true;
337  }
338  if ($editAccessInternals) {
339  $restrictEditingToRecordsOfCurrentPid = !empty($conf['onlyCurrentPid'] ?? false);
340  if ($this->‪isAdmin()) {
341  $mayEdit = true;
342  } elseif ($table === 'pages') {
343  if ($this->‪doesUserHaveAccess($dataArray, ‪Permission::PAGE_EDIT)) {
344  $mayEdit = true;
345  }
346  } else {
347  $pageOfEditableRecord = ‪BackendUtility::getRecord('pages', $dataArray['pid']);
348  if ($this->‪doesUserHaveAccess($pageOfEditableRecord, ‪Permission::CONTENT_EDIT) && !$restrictEditingToRecordsOfCurrentPid) {
349  $mayEdit = true;
350  }
351  }
352  // Check the permission of the "pid" that should be accessed, if not disabled.
353  if (!$restrictEditingToRecordsOfCurrentPid || $dataArray['pid'] == ‪$GLOBALS['TSFE']->id) {
354  // Permissions
355  if ($table === 'pages') {
356  $allow = $this->‪getAllowedEditActions($table, $conf, $dataArray['pid']);
357  // Can only display editbox if there are options in the menu
358  if (!empty($allow)) {
359  $mayEdit = true;
360  }
361  } else {
362  $perms = $this->‪calcPerms(‪$GLOBALS['TSFE']->page);
363  $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
364  $allow = array_flip($types);
365  $mayEdit = !empty($allow) && $perms & ‪Permission::CONTENT_EDIT;
366  }
367  }
368  }
369  return $mayEdit;
370  }
371 
380  public function ‪getAllowedEditActions($table, array $conf, $pid): array
381  {
382  $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
383  $allow = array_flip($types);
384  if (!$conf['onlyCurrentPid'] || $pid == ‪$GLOBALS['TSFE']->id) {
385  // Permissions
386  $types = GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
387  $allow = array_flip($types);
388  $perms = $this->‪calcPerms(‪$GLOBALS['TSFE']->page);
389  if ($table === 'pages') {
390  // Rootpage
391  if (count(‪$GLOBALS['TSFE']->config['rootLine']) === 1) {
392  unset($allow['move']);
393  unset($allow['hide']);
394  unset($allow['delete']);
395  }
396  if (!($perms & ‪Permission::PAGE_EDIT) || !$this->‪checkLanguageAccess(0)) {
397  unset($allow['edit']);
398  unset($allow['move']);
399  unset($allow['hide']);
400  }
401  if (!($perms & ‪Permission::PAGE_DELETE)) {
402  unset($allow['delete']);
403  }
404  if (!($perms & ‪Permission::PAGE_NEW)) {
405  unset($allow['new']);
406  }
407  }
408  }
409  return $allow;
410  }
411 
412  /*****************************************************
413  *
414  * Localization handling
415  *
416  ****************************************************/
428  public function ‪extGetLL($key)
429  {
430  trigger_error('FrontendBackendUserAuthentication->extGetLL() will be removed in TYPO3 v10.0.', E_USER_DEPRECATED);
431  if (!is_array(‪$GLOBALS['LOCAL_LANG'])) {
432  $this->‪getLanguageService()->‪includeLLFile('EXT:core/Resources/Private/Language/locallang_tsfe.xlf');
433  if (!is_array(‪$GLOBALS['LOCAL_LANG'])) {
434  ‪$GLOBALS['LOCAL_LANG'] = [];
435  }
436  }
437  return htmlspecialchars($this->‪getLanguageService()->getLL($key));
438  }
439 
443  protected function ‪getLanguageService()
444  {
445  return ‪$GLOBALS['LANG'];
446  }
447 }
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$writeStdLog
‪bool $writeStdLog
Definition: FrontendBackendUserAuthentication.php:60
‪TYPO3\CMS\Core\Localization\LanguageService\includeLLFile
‪mixed includeLLFile($fileRef, $setGlobal=true, $mergeLocalOntoDefault=false)
Definition: LanguageService.php:260
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$adminPanel
‪TYPO3 CMS Adminpanel View AdminPanelView $adminPanel
Definition: FrontendBackendUserAuthentication.php:78
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\recordEditAccessInternals
‪bool recordEditAccessInternals($table, $idOrRow, $newRecord=false, $deletedRecord=false, $checkFullLanguageAccess=false)
Definition: BackendUserAuthentication.php:802
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_NEW
‪const PAGE_NEW
Definition: Permission.php:47
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$frontendEdit
‪TYPO3 CMS Core FrontendEditing FrontendEditingController $frontendEdit
Definition: FrontendBackendUserAuthentication.php:83
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:35
‪TYPO3\CMS\Backend
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\calcPerms
‪int calcPerms($row)
Definition: BackendUserAuthentication.php:592
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\getLanguageService
‪LanguageService getLanguageService()
Definition: FrontendBackendUserAuthentication.php:434
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:294
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$writeAttemptLog
‪bool $writeAttemptLog
Definition: FrontendBackendUserAuthentication.php:66
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_status
‪string $formfield_status
Definition: FrontendBackendUserAuthentication.php:54
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\displayAdminPanel
‪string displayAdminPanel()
Definition: FrontendBackendUserAuthentication.php:132
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\extGetTreeList
‪string extGetTreeList($id, $depth, $begin=0, $perms_clause)
Definition: FrontendBackendUserAuthentication.php:245
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\isFrontendEditingActive
‪bool isFrontendEditingActive()
Definition: FrontendBackendUserAuthentication.php:116
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_uident
‪string $formfield_uident
Definition: FrontendBackendUserAuthentication.php:47
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\allowedToEditLanguage
‪bool allowedToEditLanguage($table, array $currentRecord)
Definition: FrontendBackendUserAuthentication.php:294
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\$id
‪string $id
Definition: AbstractUserAuthentication.php:239
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\initializeFrontendEdit
‪initializeFrontendEdit()
Definition: FrontendBackendUserAuthentication.php:105
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLockToIP
‪bool checkLockToIP()
Definition: BackendUserAuthentication.php:2545
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:30
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isUserAllowedToLogin
‪bool isUserAllowedToLogin()
Definition: BackendUserAuthentication.php:2730
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\doesUserHaveAccess
‪bool doesUserHaveAccess($row, $perms)
Definition: BackendUserAuthentication.php:331
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\extGetLL
‪string extGetLL($key)
Definition: FrontendBackendUserAuthentication.php:419
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:733
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\extPageReadAccess
‪bool extPageReadAccess($pageRec)
Definition: FrontendBackendUserAuthentication.php:223
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_uname
‪string $formfield_uname
Definition: FrontendBackendUserAuthentication.php:41
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\checkBackendAccessSettingsFromInitPhp
‪bool checkBackendAccessSettingsFromInitPhp()
Definition: FrontendBackendUserAuthentication.php:162
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:130
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:52
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:163
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\backendCheckLogin
‪bool backendCheckLogin($proceedIfNoUserIsLoggedIn=false)
Definition: FrontendBackendUserAuthentication.php:194
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:26
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:37
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_DELETE
‪const PAGE_DELETE
Definition: Permission.php:42
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$extAdmEnabled
‪bool $extAdmEnabled
Definition: FrontendBackendUserAuthentication.php:73
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\allowedToEdit
‪bool allowedToEdit(string $table, array $dataArray, array $conf, bool $checkEditAccessInternals)
Definition: FrontendBackendUserAuthentication.php:320
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\getAllowedEditActions
‪array getAllowedEditActions($table, array $conf, $pid)
Definition: FrontendBackendUserAuthentication.php:371
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$extAdminConfig
‪array $extAdminConfig
Definition: FrontendBackendUserAuthentication.php:88
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\initializeAdminPanel
‪initializeAdminPanel()
Definition: FrontendBackendUserAuthentication.php:95
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isInWebMount
‪int null isInWebMount($idOrRow, $readPerms='', $exitOnError=0)
Definition: BackendUserAuthentication.php:353
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\isAdminPanelVisible
‪bool isAdminPanelVisible()
Definition: FrontendBackendUserAuthentication.php:144