[!!!][TASK] Remove sysext:sv, move files to sysext:core
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Authentication / AbstractAuthenticationService.php
1 <?php
2 namespace TYPO3\CMS\Core\Authentication;
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
17 use TYPO3\CMS\Core\Service\AbstractService;
18
19 /**
20 * Authentication services class
21 */
22 class AbstractAuthenticationService extends AbstractService
23 {
24 /**
25 * User object
26 *
27 * @var AbstractUserAuthentication
28 */
29 public $pObj;
30
31 /**
32 * Subtype of the service which is used to call the service.
33 *
34 * @var string
35 */
36 public $mode;
37
38 /**
39 * Submitted login form data
40 *
41 * @var array
42 */
43 public $login = [];
44
45 /**
46 * Various data
47 *
48 * @var array
49 */
50 public $authInfo = [];
51
52 /**
53 * User db table definition
54 *
55 * @var array
56 */
57 public $db_user = [];
58
59 /**
60 * Usergroups db table definition
61 *
62 * @var array
63 */
64 public $db_groups = [];
65
66 /**
67 * If the writelog() functions is called if a login-attempt has be tried without success
68 *
69 * @var bool
70 */
71 public $writeAttemptLog = false;
72
73 /**
74 * If the \TYPO3\CMS\Core\Utility\GeneralUtility::devLog() function should be used
75 *
76 * @var bool
77 */
78 public $writeDevLog = false;
79
80 /**
81 * Initialize authentication service
82 *
83 * @param string $mode Subtype of the service which is used to call the service.
84 * @param array $loginData Submitted login form data
85 * @param array $authInfo Information array. Holds submitted form data etc.
86 * @param AbstractUserAuthentication $pObj Parent object
87 */
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->db_groups = $this->getServiceOption('db_groups', $authInfo['db_groups'], false);
97 $this->writeAttemptLog = $this->pObj->writeAttemptLog;
98 $this->writeDevLog = $this->pObj->writeDevLog;
99 }
100
101 /**
102 * Check the login data with the user record data for builtin login methods
103 *
104 * @param array $user User data array
105 * @param array $loginData Login data array
106 * @param string $passwordCompareStrategy Password compare strategy
107 * @return bool TRUE if login data matched
108 */
109 public function compareUident(array $user, array $loginData, $passwordCompareStrategy = '')
110 {
111 return $this->pObj->compareUident($user, $loginData, $passwordCompareStrategy);
112 }
113
114 /**
115 * Writes to log database table in pObj
116 *
117 * @param int $type denotes which module that has submitted the entry. This is the current list: 1=tce_db; 2=tce_file; 3=system (eg. sys_history save); 4=modules; 254=Personal settings changed; 255=login / out action: 1=login, 2=logout, 3=failed login (+ errorcode 3), 4=failure_warning_email sent
118 * @param int $action denotes which specific operation that wrote the entry (eg. 'delete', 'upload', 'update' and so on...). Specific for each $type. Also used to trigger update of the interface. (see the log-module for the meaning of each number !!)
119 * @param int $error flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
120 * @param int $details_nr The message number. Specific for each $type and $action. in the future this will make it possible to translate error messages to other languages
121 * @param string $details Default text that follows the message
122 * @param array $data Data that follows the log. Might be used to carry special information. If an array the first 5 entries (0-4) will be sprintf'ed the details-text...
123 * @param string $tablename Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
124 * @param int|string $recuid Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
125 * @param int|string $recpid Special field used by tce_main.php. These ($tablename, $recuid, $recpid) holds the reference to the record which the log-entry is about. (Was used in attic status.php to update the interface.)
126 */
127 public function writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '')
128 {
129 if ($this->writeAttemptLog) {
130 $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
131 }
132 }
133
134 /**
135 * Get a user from DB by username
136 *
137 * @param string $username User name
138 * @param string $extraWhere Additional WHERE clause: " AND ...
139 * @param array|string $dbUserSetup User db table definition, or empty string for $this->db_user
140 * @return mixed User array or FALSE
141 */
142 public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '')
143 {
144 $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
145 $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
146 return $user;
147 }
148 }