[TASK] Make sysexts composer names standards compliant
[Packages/TYPO3.CMS.git] / typo3 / sysext / sv / Classes / AbstractAuthenticationService.php
1 <?php
2 namespace TYPO3\CMS\Sv;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2004-2013 René Fritz <r.fritz@colorcube.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * Authentication services class
32 *
33 * @author René Fritz <r.fritz@colorcube.de>
34 */
35 class AbstractAuthenticationService extends \TYPO3\CMS\Core\Service\AbstractService {
36
37 /**
38 * User object
39 *
40 * @var \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
41 * @todo Define visibility
42 */
43 public $pObj;
44
45 // Subtype of the service which is used to call the service.
46 /**
47 * @todo Define visibility
48 */
49 public $mode;
50
51 // Submitted login form data
52 /**
53 * @todo Define visibility
54 */
55 public $login = array();
56
57 // Various data
58 /**
59 * @todo Define visibility
60 */
61 public $authInfo = array();
62
63 // User db table definition
64 /**
65 * @todo Define visibility
66 */
67 public $db_user = array();
68
69 // Usergroups db table definition
70 /**
71 * @todo Define visibility
72 */
73 public $db_groups = array();
74
75 // If the writelog() functions is called if a login-attempt has be tried without success
76 /**
77 * @todo Define visibility
78 */
79 public $writeAttemptLog = FALSE;
80
81 // If the \TYPO3\CMS\Core\Utility\GeneralUtility::devLog() function should be used
82 /**
83 * @todo Define visibility
84 */
85 public $writeDevLog = FALSE;
86
87 /**
88 * Initialize authentication service
89 *
90 * @param string $mode Subtype of the service which is used to call the service.
91 * @param array $loginData Submitted login form data
92 * @param array $authInfo Information array. Holds submitted form data etc.
93 * @param object $pObj Parent object
94 * @return void
95 * @todo Define visibility
96 */
97 public function initAuth($mode, $loginData, $authInfo, $pObj) {
98 $this->pObj = $pObj;
99 // Sub type
100 $this->mode = $mode;
101 $this->login = $loginData;
102 $this->authInfo = $authInfo;
103 $this->db_user = $this->getServiceOption('db_user', $authInfo['db_user'], FALSE);
104 $this->db_groups = $this->getServiceOption('db_groups', $authInfo['db_groups'], FALSE);
105 $this->writeAttemptLog = $this->pObj->writeAttemptLog;
106 $this->writeDevLog = $this->pObj->writeDevLog;
107 }
108
109 /**
110 * Check the login data with the user record data for builtin login methods
111 *
112 * @param array $user User data array
113 * @param array $loginData Login data array
114 * @param string $passwordCompareStrategy Password compare strategy
115 * @return boolean TRUE if login data matched
116 * @todo Define visibility
117 */
118 public function compareUident(array $user, array $loginData, $passwordCompareStrategy = '') {
119 if ($this->authInfo['loginType'] === 'BE') {
120 // Challenge is only stored in session during BE login with the superchallenged login type.
121 // In the frontend context the challenge is never stored in the session.
122 if ($passwordCompareStrategy !== 'superchallenged') {
123 $this->pObj->challengeStoredInCookie = FALSE;
124 }
125 // The TYPO3 standard login service relies on $passwordCompareStrategy being set
126 // to 'superchallenged' because of the password in the database is stored as md5 hash
127 $passwordCompareStrategy = 'superchallenged';
128 }
129 return $this->pObj->compareUident($user, $loginData, $passwordCompareStrategy);
130 }
131
132 /**
133 * Writes to log database table in pObj
134 *
135 * @param integer $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
136 * @param integer $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 !!)
137 * @param integer $error flag. 0 = message, 1 = error (user problem), 2 = System Error (which should not happen), 3 = security notice (admin)
138 * @param integer $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
139 * @param string $details Default text that follows the message
140 * @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...
141 * @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.)
142 * @param integer $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.)
143 * @param integer $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.)
144 * @return void
145 * @todo Define visibility
146 */
147 public function writelog($type, $action, $error, $details_nr, $details, $data, $tablename = '', $recuid = '', $recpid = '') {
148 if ($this->writeAttemptLog) {
149 $this->pObj->writelog($type, $action, $error, $details_nr, $details, $data, $tablename, $recuid, $recpid);
150 }
151 }
152
153 /*************************
154 *
155 * create/update user - EXPERIMENTAL
156 *
157 *************************/
158 /**
159 * Get a user from DB by username
160 *
161 * @param string $username User name
162 * @param string $extraWhere Additional WHERE clause: " AND ...
163 * @param array $dbUserSetup User db table definition: $this->db_user
164 * @return mixed User array or FALSE
165 * @todo Define visibility
166 */
167 public function fetchUserRecord($username, $extraWhere = '', $dbUserSetup = '') {
168 $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
169 $user = $this->pObj->fetchUserRecord($dbUser, $username, $extraWhere);
170 return $user;
171 }
172
173 }