11d4aeeb4a5ed5295066a04399daf9a0d07db37e
[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 /**
18 * Authentication services class
19 *
20 * @author René Fritz <r.fritz@colorcube.de>
21 */
22 class AbstractAuthenticationService extends \TYPO3\CMS\Core\Service\AbstractService {
23
24 /**
25 * User object
26 *
27 * @var \TYPO3\CMS\Core\Authentication\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 = array();
44
45 /**
46 * Various data
47 *
48 * @var array
49 */
50 public $authInfo = array();
51
52 /**
53 * User db table definition
54 *
55 * @var array
56 */
57 public $db_user = array();
58
59 /**
60 * Usergroups db table definition
61 *
62 * @var array
63 */
64 public $db_groups = array();
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 object $pObj Parent object
87 * @return void
88 */
89 public function initAuth($mode, $loginData, $authInfo, $pObj) {
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 if ($this->authInfo['loginType'] === 'BE') {
111 // Challenge is only stored in session during BE login with the superchallenged login type.
112 // In the frontend context the challenge is never stored in the session.
113 if ($passwordCompareStrategy !== 'superchallenged') {
114 $this->pObj->challengeStoredInCookie = FALSE;
115 }
116 // The TYPO3 standard login service relies on $passwordCompareStrategy being set
117 // to 'superchallenged' because of the password in the database is stored as md5 hash
118 $passwordCompareStrategy = 'superchallenged';
119 }
120 return $this->pObj->compareUident($user, $loginData, $passwordCompareStrategy);
121 }
122
123 /**
124 * Writes to log database table in pObj
125 *
126 * @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
127 * @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 !!)
128 * @param int $error flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
129 * @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
130 * @param string $details Default text that follows the message
131 * @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...
132 * @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.)
133 * @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.)
134 * @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.)
135 * @return void
136 */
137 public function writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '') {
138 if ($this->writeAttemptLog) {
139 $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
140 }
141 }
142
143 /*************************
144 *
145 * create/update user - EXPERIMENTAL
146 *
147 *************************/
148 /**
149 * Get a user from DB by username
150 *
151 * @param string $username User name
152 * @param string $extraWhere Additional WHERE clause: " AND ...
153 * @param array $dbUserSetup User db table definition: $this->db_user
154 * @return mixed User array or FALSE
155 */
156 public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '') {
157 $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
158 $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
159 return $user;
160 }
161
162 }