‪TYPO3CMS  11.5
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;
25 
29 class ‪AbstractAuthenticationService implements LoggerAwareInterface
30 {
31  use LoggerAwareTrait;
32 
38  public ‪$pObj;
39 
45  public ‪$mode;
46 
52  public ‪$login = [];
53 
59  public ‪$authInfo = [];
60 
66  public ‪$db_user = [];
67 
73  public ‪$writeAttemptLog = false;
74 
78  public ‪$info = [];
79 
88  public function ‪initAuth(‪$mode, $loginData, ‪$authInfo, ‪$pObj)
89  {
90  $this->pObj = ‪$pObj;
91  // Sub type
92  $this->mode = ‪$mode;
93  $this->login = $loginData;
94  $this->authInfo = ‪$authInfo;
95  $this->‪db_user = $this->‪getServiceOption('db_user', $authInfo['db_user'] ?? [], false);
96  $this->writeAttemptLog = $this->pObj->writeAttemptLog ?? true;
97  }
98 
112  public function ‪writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '')
113  {
114  if ($this->writeAttemptLog) {
115  $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
116  }
117  }
118 
127  public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '')
128  {
129  $dbUser = is_array($dbUserSetup) ? $dbUserSetup : ‪$this->db_user;
130  ‪$user = false;
131  if ($username || $extraWhere) {
132  $query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
133  $query->getRestrictions()->removeAll()
134  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
135  $constraints = array_filter([
136  ‪QueryHelper::stripLogicalOperatorPrefix($dbUser['check_pid_clause']),
137  ‪QueryHelper::stripLogicalOperatorPrefix($dbUser['enable_clause']),
139  ]);
140  if (!empty($username)) {
141  array_unshift(
142  $constraints,
143  $query->expr()->eq(
144  $dbUser['username_column'],
145  $query->createNamedParameter($username, ‪Connection::PARAM_STR)
146  )
147  );
148  }
149  ‪$user = $query->select('*')
150  ->from($dbUser['table'])
151  ->where(...$constraints)
152  ->executeQuery()
153  ->fetchAssociative();
154  }
155  return ‪$user;
156  }
157 
163  public function ‪init(): bool
164  {
165  return true;
166  }
167 
173  public function ‪reset()
174  {
175  // nothing to do
176  }
177 
184  public function ‪getServiceKey()
185  {
186  return $this->info['serviceKey'];
187  }
188 
195  public function ‪getServiceTitle()
196  {
197  return $this->info['title'];
198  }
199 
209  public function ‪getServiceOption($optionName, $defaultValue = '', $includeDefaultConfig = true)
210  {
211  $config = null;
212  $serviceType = $this->info['serviceType'] ?? '';
213  $serviceKey = $this->info['serviceKey'] ?? '';
214  $svOptions = ‪$GLOBALS['TYPO3_CONF_VARS']['SVCONF'][$serviceType] ?? [];
215  if (isset($svOptions[$serviceKey][$optionName])) {
216  $config = $svOptions[$serviceKey][$optionName];
217  } elseif ($includeDefaultConfig && isset($svOptions['default'][$optionName])) {
218  $config = $svOptions['default'][$optionName];
219  }
220  if (!isset($config)) {
221  $config = $defaultValue;
222  }
223  return $config;
224  }
225 
230  public function ‪getLastErrorArray(): array
231  {
232  return [];
233  }
234 }
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceOption
‪mixed getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=true)
Definition: AbstractAuthenticationService.php:202
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\initAuth
‪initAuth($mode, $loginData, $authInfo, $pObj)
Definition: AbstractAuthenticationService.php:81
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$writeAttemptLog
‪bool $writeAttemptLog
Definition: AbstractAuthenticationService.php:67
‪TYPO3\CMS\Core\Authentication
Definition: AbstractAuthenticationService.php:16
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$info
‪array $info
Definition: AbstractAuthenticationService.php:71
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceTitle
‪string getServiceTitle()
Definition: AbstractAuthenticationService.php:188
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\writelog
‪writelog($type, $action, $error, $details_nr, $details, $data, $tablename='', $recuid='', $recpid='')
Definition: AbstractAuthenticationService.php:105
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService
Definition: AbstractAuthenticationService.php:30
‪TYPO3\CMS\Core\Database\Connection\PARAM_STR
‪const PARAM_STR
Definition: Connection.php:54
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$user
‪if($username|| $extraWhere) return $user
Definition: AbstractAuthenticationService.php:124
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$mode
‪string $mode
Definition: AbstractAuthenticationService.php:43
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\db_user
‪array< string, function fetchUserRecord( $username, $extraWhere='', $dbUserSetup='') { $dbUser=is_array( $dbUserSetup) ? $dbUserSetup :$this-> db_user
Definition: AbstractAuthenticationService.php:122
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$db_user
‪array $db_user
Definition: AbstractAuthenticationService.php:61
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$user
‪$user
Definition: AbstractAuthenticationService.php:123
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$pObj
‪AbstractUserAuthentication $pObj
Definition: AbstractAuthenticationService.php:37
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\reset
‪reset()
Definition: AbstractAuthenticationService.php:166
‪TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix
‪static string stripLogicalOperatorPrefix(string $constraint)
Definition: QueryHelper.php:171
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$authInfo
‪array $authInfo
Definition: AbstractAuthenticationService.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getLastErrorArray
‪array getLastErrorArray()
Definition: AbstractAuthenticationService.php:223
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceKey
‪string getServiceKey()
Definition: AbstractAuthenticationService.php:177
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\init
‪init()
Definition: AbstractAuthenticationService.php:156
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$login
‪array $login
Definition: AbstractAuthenticationService.php:49
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:56