[CLEANUP] Improve the @param/@return/@var PHPDoc
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / Classes / AbstractAuthenticationService.php
1 <?php
2 namespace TYPO3\CMS\Sv;
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\Authentication\AbstractUserAuthentication;
18
19 /**
20 * Authentication services class
21 *
22 * @author René Fritz <r.fritz@colorcube.de>
23 */
24 class AbstractAuthenticationService extends \TYPO3\CMS\Core\Service\AbstractService {
25
26 /**
27 * User object
28 *
29 * @var \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
30 */
31 public $pObj;
32
33 /**
34 * Subtype of the service which is used to call the service.
35 *
36 * @var string
37 */
38 public $mode;
39
40 /**
41 * Submitted login form data
42 *
43 * @var array
44 */
45 public $login = array();
46
47 /**
48 * Various data
49 *
50 * @var array
51 */
52 public $authInfo = array();
53
54 /**
55 * User db table definition
56 *
57 * @var array
58 */
59 public $db_user = array();
60
61 /**
62 * Usergroups db table definition
63 *
64 * @var array
65 */
66 public $db_groups = array();
67
68 /**
69 * If the writelog() functions is called if a login-attempt has be tried without success
70 *
71 * @var bool
72 */
73 public $writeAttemptLog = FALSE;
74
75 /**
76 * If the \TYPO3\CMS\Core\Utility\GeneralUtility::devLog() function should be used
77 *
78 * @var bool
79 */
80 public $writeDevLog = FALSE;
81
82 /**
83 * Initialize authentication service
84 *
85 * @param string $mode Subtype of the service which is used to call the service.
86 * @param array $loginData Submitted login form data
87 * @param array $authInfo Information array. Holds submitted form data etc.
88 * @param AbstractUserAuthentication $pObj Parent object
89 * @return void
90 */
91 public function initAuth($mode, $loginData, $authInfo, $pObj) {
92 $this->pObj = $pObj;
93 // Sub type
94 $this->mode = $mode;
95 $this->login = $loginData;
96 $this->authInfo = $authInfo;
97 $this->db_user = $this->getServiceOption('db_user', $authInfo['db_user'], FALSE);
98 $this->db_groups = $this->getServiceOption('db_groups', $authInfo['db_groups'], FALSE);
99 $this->writeAttemptLog = $this->pObj->writeAttemptLog;
100 $this->writeDevLog = $this->pObj->writeDevLog;
101 }
102
103 /**
104 * Check the login data with the user record data for builtin login methods
105 *
106 * @param array $user User data array
107 * @param array $loginData Login data array
108 * @param string $passwordCompareStrategy Password compare strategy
109 * @return bool TRUE if login data matched
110 */
111 public function compareUident(array $user, array $loginData, $passwordCompareStrategy = '') {
112 if ($this->authInfo['loginType'] === 'BE') {
113 // Challenge is only stored in session during BE login with the superchallenged login type.
114 // In the frontend context the challenge is never stored in the session.
115 if ($passwordCompareStrategy !== 'superchallenged') {
116 $this->pObj->challengeStoredInCookie = FALSE;
117 }
118 // The TYPO3 standard login service relies on $passwordCompareStrategy being set
119 // to 'superchallenged' because of the password in the database is stored as md5 hash
120 $passwordCompareStrategy = 'superchallenged';
121 }
122 return $this->pObj->compareUident($user, $loginData, $passwordCompareStrategy);
123 }
124
125 /**
126 * Writes to log database table in pObj
127 *
128 * @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
129 * @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 !!)
130 * @param int $error flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
131 * @param int $details_nr The message number. Specific for each $type and $action. in the future this will make it possible to translate errormessages to other languages
132 * @param string $details Default text that follows the message
133 * @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...
134 * @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.)
135 * @param int $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.)
136 * @param int $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.)
137 * @return void
138 */
139 public function writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '') {
140 if ($this->writeAttemptLog) {
141 $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
142 }
143 }
144
145 /*************************
146 *
147 * create/update user - EXPERIMENTAL
148 *
149 *************************/
150 /**
151 * Get a user from DB by username
152 *
153 * @param string $username User name
154 * @param string $extraWhere Additional WHERE clause: " AND ...
155 * @param array $dbUserSetup User db table definition: $this->db_user
156 * @return mixed User array or FALSE
157 */
158 public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '') {
159 $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
160 $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
161 return $user;
162 }
163
164 }