‪TYPO3CMS  11.5
FrontendBackendUserAuthentication.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 
16 namespace ‪TYPO3\CMS\Backend;
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 
31 {
37  public ‪$formfield_uname = '';
38 
44  public ‪$formfield_uident = '';
45 
52  public ‪$formfield_status = '';
53 
59  public ‪$writeStdLog = false;
60 
66  public ‪$writeAttemptLog = false;
67 
75  public function ‪backendCheckLogin($proceedIfNoUserIsLoggedIn = null)
76  {
77  if (empty($this->user['uid'])) {
78  return false;
79  }
80  // Check Hardcoded lock on BE
81  if (‪$GLOBALS['TYPO3_CONF_VARS']['BE']['adminOnly'] < 0) {
82  return false;
83  }
84  return $this->‪isUserAllowedToLogin();
85  }
86 
98  public function ‪allowedToEditLanguage($table, array $currentRecord): bool
99  {
100  // If no access right to record languages, return immediately
102  $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
103  if ($table === 'pages') {
104  $languageId = $languageAspect->getId();
105  } elseif ($table === 'tt_content') {
106  $languageId = $languageAspect->getContentId();
107  } elseif (‪$GLOBALS['TCA'][$table]['ctrl']['languageField'] ?? false) {
108  $languageId = $currentRecord[‪$GLOBALS['TCA'][$table]['ctrl']['languageField']];
109  } else {
110  $languageId = -1;
111  }
112  return $this->‪checkLanguageAccess($languageId);
113  }
114 
124  public function ‪allowedToEdit(string $table, array $dataArray, array $conf, bool $checkEditAccessInternals): bool
125  {
126  // Unless permissions specifically allow it, editing is not allowed.
127  $mayEdit = false;
128  if ($checkEditAccessInternals) {
129  $editAccessInternals = $this->‪recordEditAccessInternals($table, $dataArray, false, false);
130  } else {
131  $editAccessInternals = true;
132  }
133  if ($editAccessInternals) {
134  $restrictEditingToRecordsOfCurrentPid = !empty($conf['onlyCurrentPid'] ?? false);
135  if ($this->‪isAdmin()) {
136  $mayEdit = true;
137  } elseif ($table === 'pages') {
138  if ($this->‪doesUserHaveAccess($dataArray, ‪Permission::PAGE_EDIT)) {
139  $mayEdit = true;
140  }
141  } else {
142  $pageOfEditableRecord = BackendUtility::getRecord('pages', $dataArray['pid']);
143  if (is_array($pageOfEditableRecord) && $this->‪doesUserHaveAccess($pageOfEditableRecord, ‪Permission::CONTENT_EDIT) && !$restrictEditingToRecordsOfCurrentPid) {
144  $mayEdit = true;
145  }
146  }
147  // Check the permission of the "pid" that should be accessed, if not disabled.
148  if (!$restrictEditingToRecordsOfCurrentPid || $dataArray['pid'] == ‪$GLOBALS['TSFE']->id) {
149  // Permissions
150  if ($table === 'pages') {
151  $allow = $this->‪getAllowedEditActions($table, $conf, $dataArray['pid']);
152  // Can only display editbox if there are options in the menu
153  if (!empty($allow)) {
154  $mayEdit = true;
155  }
156  } else {
157  $perms = new ‪Permission($this->‪calcPerms(‪$GLOBALS['TSFE']->page));
158  $types = ‪GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
159  $allow = array_flip($types);
160  $mayEdit = !empty($allow) && $perms->editContentPermissionIsGranted();
161  }
162  }
163  }
164  return $mayEdit;
165  }
166 
175  public function ‪getAllowedEditActions($table, array $conf, $pid): array
176  {
177  $types = ‪GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
178  $allow = array_flip($types);
179  if (!($conf['onlyCurrentPid'] ?? false) || $pid == ‪$GLOBALS['TSFE']->id) {
180  // Permissions
181  $types = ‪GeneralUtility::trimExplode(',', strtolower($conf['allow']), true);
182  $allow = array_flip($types);
183  $perms = new ‪Permission($this->‪calcPerms(‪$GLOBALS['TSFE']->page));
184  if ($table === 'pages') {
185  // Rootpage
186  if (count(‪$GLOBALS['TSFE']->config['rootLine']) === 1) {
187  unset($allow['move']);
188  unset($allow['hide']);
189  unset($allow['delete']);
190  }
191  if (!$perms->editPagePermissionIsGranted() || !$this->checkLanguageAccess(0)) {
192  unset($allow['edit']);
193  unset($allow['move']);
194  unset($allow['hide']);
195  }
196  if (!$perms->deletePagePermissionIsGranted()) {
197  unset($allow['delete']);
198  }
199  if (!$perms->createPagePermissionIsGranted()) {
200  unset($allow['new']);
201  }
202  }
203  }
204  return $allow;
205  }
206 
212  protected function ‪hasEditAccessToLiveWorkspace(): bool
213  {
214  return true;
215  }
216 }
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$writeStdLog
‪bool $writeStdLog
Definition: FrontendBackendUserAuthentication.php:55
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\recordEditAccessInternals
‪bool recordEditAccessInternals($table, $idOrRow, $newRecord=false, $deletedRecord=false, $checkFullLanguageAccess=false)
Definition: BackendUserAuthentication.php:740
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication
Definition: FrontendBackendUserAuthentication.php:31
‪TYPO3\CMS\Backend
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\calcPerms
‪int calcPerms($row)
Definition: BackendUserAuthentication.php:529
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isAdmin
‪bool isAdmin()
Definition: BackendUserAuthentication.php:245
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$writeAttemptLog
‪bool $writeAttemptLog
Definition: FrontendBackendUserAuthentication.php:61
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_status
‪string $formfield_status
Definition: FrontendBackendUserAuthentication.php:49
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_uident
‪string $formfield_uident
Definition: FrontendBackendUserAuthentication.php:42
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\allowedToEditLanguage
‪bool allowedToEditLanguage($table, array $currentRecord)
Definition: FrontendBackendUserAuthentication.php:93
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\hasEditAccessToLiveWorkspace
‪hasEditAccessToLiveWorkspace()
Definition: FrontendBackendUserAuthentication.php:207
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\backendCheckLogin
‪bool backendCheckLogin($proceedIfNoUserIsLoggedIn=null)
Definition: FrontendBackendUserAuthentication.php:70
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\isUserAllowedToLogin
‪bool isUserAllowedToLogin()
Definition: BackendUserAuthentication.php:2235
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\doesUserHaveAccess
‪bool doesUserHaveAccess($row, $perms)
Definition: BackendUserAuthentication.php:283
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\checkLanguageAccess
‪bool checkLanguageAccess($langValue)
Definition: BackendUserAuthentication.php:670
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\$formfield_uname
‪string $formfield_uname
Definition: FrontendBackendUserAuthentication.php:36
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Core\Type\Bitmask\Permission\CONTENT_EDIT
‪const CONTENT_EDIT
Definition: Permission.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_EDIT
‪const PAGE_EDIT
Definition: Permission.php:40
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\allowedToEdit
‪bool allowedToEdit(string $table, array $dataArray, array $conf, bool $checkEditAccessInternals)
Definition: FrontendBackendUserAuthentication.php:119
‪TYPO3\CMS\Backend\FrontendBackendUserAuthentication\getAllowedEditActions
‪array getAllowedEditActions($table, array $conf, $pid)
Definition: FrontendBackendUserAuthentication.php:170
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50