‪TYPO3CMS  10.4
AbstractAuthenticationService.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 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
24 
28 class ‪AbstractAuthenticationService implements LoggerAwareInterface
29 {
30  use LoggerAwareTrait;
31 
37  public ‪$pObj;
38 
44  public ‪$mode;
45 
51  public ‪$login = [];
52 
58  public ‪$authInfo = [];
59 
65  public ‪$db_user = [];
66 
72  public ‪$db_groups = [];
73 
79  public ‪$writeAttemptLog = false;
80 
84  public ‪$info = [];
85 
94  public function ‪initAuth(‪$mode, $loginData, ‪$authInfo, ‪$pObj)
95  {
96  $this->pObj = ‪$pObj;
97  // Sub type
98  $this->mode = ‪$mode;
99  $this->login = $loginData;
100  $this->authInfo = ‪$authInfo;
101  $this->db_user = $this->‪getServiceOption('db_user', ‪$authInfo['db_user'] ?? [], false);
102  $this->db_groups = $this->‪getServiceOption('db_groups', ‪$authInfo['db_groups'] ?? [], false);
103  $this->writeAttemptLog = $this->pObj->writeAttemptLog ?? true;
104  }
105 
119  public function ‪writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '')
120  {
121  if ($this->writeAttemptLog) {
122  $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
123  }
124  }
125 
134  public function ‪fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '')
135  {
136  $dbUser = is_array($dbUserSetup) ? $dbUserSetup : ‪$this->db_user;
137  $user = false;
138  if ($username || $extraWhere) {
139  $query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
140  $query->getRestrictions()->removeAll()
141  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
142  $constraints = array_filter([
143  ‪QueryHelper::stripLogicalOperatorPrefix($dbUser['check_pid_clause']),
144  ‪QueryHelper::stripLogicalOperatorPrefix($dbUser['enable_clause']),
146  ]);
147  if (!empty($username)) {
148  array_unshift(
149  $constraints,
150  $query->expr()->eq(
151  $dbUser['username_column'],
152  $query->createNamedParameter($username, \PDO::PARAM_STR)
153  )
154  );
155  }
156  $user = $query->select('*')
157  ->from($dbUser['table'])
158  ->where(...$constraints)
159  ->execute()
160  ->fetch();
161  }
162  return $user;
163  }
164 
170  public function ‪init(): bool
171  {
172  return true;
173  }
174 
180  public function ‪reset()
181  {
182  // nothing to do
183  }
184 
191  public function ‪getServiceKey()
192  {
193  return $this->info['serviceKey'];
194  }
195 
202  public function ‪getServiceTitle()
203  {
204  return $this->info['title'];
205  }
206 
216  public function ‪getServiceOption($optionName, $defaultValue = '', $includeDefaultConfig = true)
217  {
218  $config = null;
219  $serviceType = $this->info['serviceType'] ?? '';
220  $serviceKey = $this->info['serviceKey'] ?? '';
221  $svOptions = ‪$GLOBALS['TYPO3_CONF_VARS']['SVCONF'][$serviceType] ?? [];
222  if (isset($svOptions[$serviceKey][$optionName])) {
223  $config = $svOptions[$serviceKey][$optionName];
224  } elseif ($includeDefaultConfig && isset($svOptions['default'][$optionName])) {
225  $config = $svOptions['default'][$optionName];
226  }
227  if (!isset($config)) {
228  $config = $defaultValue;
229  }
230  return $config;
231  }
232 
237  public function ‪getLastErrorArray(): array
238  {
239  return [];
240  }
241 }
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceOption
‪mixed getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=true)
Definition: AbstractAuthenticationService.php:208
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\initAuth
‪initAuth($mode, $loginData, $authInfo, $pObj)
Definition: AbstractAuthenticationService.php:86
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$writeAttemptLog
‪bool $writeAttemptLog
Definition: AbstractAuthenticationService.php:72
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\fetchUserRecord
‪mixed fetchUserRecord($username, $extraWhere='', $dbUserSetup='')
Definition: AbstractAuthenticationService.php:126
‪TYPO3\CMS\Core\Authentication
Definition: AbstractAuthenticationService.php:16
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$info
‪array $info
Definition: AbstractAuthenticationService.php:76
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceTitle
‪string getServiceTitle()
Definition: AbstractAuthenticationService.php:194
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\writelog
‪writelog($type, $action, $error, $details_nr, $details, $data, $tablename='', $recuid='', $recpid='')
Definition: AbstractAuthenticationService.php:111
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService
Definition: AbstractAuthenticationService.php:29
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$db_groups
‪array $db_groups
Definition: AbstractAuthenticationService.php:66
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$mode
‪string $mode
Definition: AbstractAuthenticationService.php:42
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$db_user
‪array $db_user
Definition: AbstractAuthenticationService.php:60
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$pObj
‪AbstractUserAuthentication $pObj
Definition: AbstractAuthenticationService.php:36
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\reset
‪reset()
Definition: AbstractAuthenticationService.php:172
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:165
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$authInfo
‪array $authInfo
Definition: AbstractAuthenticationService.php:54
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getLastErrorArray
‪array getLastErrorArray()
Definition: AbstractAuthenticationService.php:229
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceKey
‪string getServiceKey()
Definition: AbstractAuthenticationService.php:183
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\init
‪init()
Definition: AbstractAuthenticationService.php:162
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$login
‪array $login
Definition: AbstractAuthenticationService.php:48
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51