‪TYPO3CMS  ‪main
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 ‪$writeAttemptLog = false;
73 
77  public ‪$info = [];
78 
88  {
89  $this->pObj = ‪$pObj;
90  // Sub type
91  $this->mode = ‪$mode;
92  $this->login = ‪$loginData;
93  $this->authInfo = ‪$authInfo;
94  $this->‪db_user = $this->‪getServiceOption('db_user', $authInfo['db_user'] ?? [], false);
95  $this->writeAttemptLog = $this->pObj->writeAttemptLog ?? true;
96  }
97 
111  public function ‪writelog($type, $action, $error, $details_nr, ‪$details, $data, $tablename = '', $recuid = '', $recpid = '')
112  {
113  if ($this->writeAttemptLog) {
114  $this->pObj->writelog($type, $action, $error, $details_nr, ‪$details, $data, $tablename, $recuid, $recpid);
115  }
116  }
117 
126  public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '')
127  {
128  $dbUser = is_array($dbUserSetup) ? $dbUserSetup : ‪$this->db_user;
129  ‪$user = false;
130  if ($username || $extraWhere) {
131  $query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
132  $query->getRestrictions()->removeAll()
133  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
134  $constraints = array_filter([
135  ‪QueryHelper::stripLogicalOperatorPrefix($dbUser['enable_clause']),
137  ]);
138  if (!empty($username)) {
139  array_unshift(
140  $constraints,
141  $query->expr()->eq(
142  $dbUser['username_column'],
143  $query->createNamedParameter($username)
144  )
145  );
146  }
147  ‪$user = $query->select('*')
148  ->from($dbUser['table'])
149  ->where(...$constraints)
150  ->executeQuery()
151  ->fetchAssociative();
152  }
153  return ‪$user;
154  }
155 
161  public function ‪init(): bool
162  {
163  return true;
164  }
165 
171  public function ‪reset()
172  {
173  // nothing to do
174  }
175 
182  public function ‪getServiceKey()
183  {
184  return $this->info['serviceKey'];
185  }
186 
193  public function ‪getServiceTitle()
194  {
195  return $this->info['title'];
196  }
197 
207  public function ‪getServiceOption($optionName, $defaultValue = '', $includeDefaultConfig = true)
208  {
209  $config = null;
210  $serviceType = $this->info['serviceType'] ?? '';
211  $serviceKey = $this->info['serviceKey'] ?? '';
212  $svOptions = ‪$GLOBALS['TYPO3_CONF_VARS']['SVCONF'][$serviceType] ?? [];
213  if (isset($svOptions[$serviceKey][$optionName])) {
214  $config = $svOptions[$serviceKey][$optionName];
215  } elseif ($includeDefaultConfig && isset($svOptions['default'][$optionName])) {
216  $config = $svOptions['default'][$optionName];
217  }
218  if (!isset($config)) {
219  $config = $defaultValue;
220  }
221  return $config;
222  }
223 
227  public function ‪getLastErrorArray(): array
228  {
229  return [];
230  }
231 }
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceOption
‪mixed getServiceOption($optionName, $defaultValue='', $includeDefaultConfig=true)
Definition: AbstractAuthenticationService.php:200
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getLastErrorArray
‪getLastErrorArray()
Definition: AbstractAuthenticationService.php:220
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\initAuth
‪initAuth($mode, $loginData, $authInfo, $pObj)
Definition: AbstractAuthenticationService.php:80
‪TYPO3\CMS\Webhooks\Message\$details
‪identifier readonly UriInterface readonly array $details
Definition: MfaVerificationErrorOccurredMessage.php:37
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$writeAttemptLog
‪bool $writeAttemptLog
Definition: AbstractAuthenticationService.php:66
‪TYPO3\CMS\Core\Authentication
Definition: AbstractAuthenticationService.php:16
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$info
‪array $info
Definition: AbstractAuthenticationService.php:70
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\getServiceTitle
‪string getServiceTitle()
Definition: AbstractAuthenticationService.php:186
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\writelog
‪writelog($type, $action, $error, $details_nr, $details, $data, $tablename='', $recuid='', $recpid='')
Definition: AbstractAuthenticationService.php:104
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService
Definition: AbstractAuthenticationService.php:29
‪TYPO3\CMS\Core\Database\Query\QueryHelper
Definition: QueryHelper.php:32
‪TYPO3\CMS\Webhooks\Message\$loginData
‪identifier readonly UriInterface readonly array $loginData
Definition: LoginErrorOccurredMessage.php:37
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$user
‪if($username|| $extraWhere) return $user
Definition: AbstractAuthenticationService.php:123
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$mode
‪string $mode
Definition: AbstractAuthenticationService.php:42
‪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:121
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$db_user
‪array $db_user
Definition: AbstractAuthenticationService.php:60
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$user
‪$user
Definition: AbstractAuthenticationService.php:122
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$pObj
‪AbstractUserAuthentication $pObj
Definition: AbstractAuthenticationService.php:36
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\reset
‪reset()
Definition: AbstractAuthenticationService.php:164
‪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:54
‪$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\getServiceKey
‪string getServiceKey()
Definition: AbstractAuthenticationService.php:175
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\init
‪init()
Definition: AbstractAuthenticationService.php:154
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Authentication\AbstractAuthenticationService\$login
‪array $login
Definition: AbstractAuthenticationService.php:48
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:65