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