Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 include_once 'Auth/Auth.php';
00036
00037 class ilBaseAuthentication
00038 {
00039
00040
00041
00042
00043
00044 var $auth = null;
00045
00046
00047
00048
00049
00050
00051
00052 var $sid = '';
00053
00054
00055
00056
00057
00058 var $username = '';
00059
00060
00061
00062
00063
00064 var $password = '';
00065
00066
00067
00068
00069
00070
00071 var $client = '';
00072
00073 function ilBaseAuthentication()
00074 {
00075 $this->__setMessage('');
00076 $this->__setMessageCode('Client');
00077 $this->check_setting = true;
00078 }
00079
00080
00081
00082 function setClient($a_client)
00083 {
00084 $this->client = $a_client;
00085 $_COOKIE['ilClientId'] = $a_client;
00086 }
00087 function getClient()
00088 {
00089 return $this->client;
00090 }
00091 function setUsername($a_username)
00092 {
00093 $this->username = $a_username;
00094 $_POST['username'] = $a_username;
00095 }
00096 function getUsername()
00097 {
00098 return $this->username;
00099 }
00100 function setPassword($a_password)
00101 {
00102 $this->password = $a_password;
00103 $_POST['password'] = $a_password;
00104 }
00105 function getPassword()
00106 {
00107 return $this->password;
00108 }
00109 function setSid($a_sid)
00110 {
00111 $this->sid = $a_sid;
00112 $_COOKIE['PHPSESSID'] = $this->sid;
00113 }
00114 function getSid()
00115 {
00116 return $this->sid;
00117 }
00118
00119 function getMessage()
00120 {
00121 return $this->message;
00122 }
00123 function getMessageCode()
00124 {
00125 return $this->message_code;
00126 }
00127 function __setMessage($a_message)
00128 {
00129 $this->message = $a_message;
00130 }
00131 function __setMessageCode($a_message_code)
00132 {
00133 $this->message_code = $a_message_code;
00134 }
00135
00136 function authenticate()
00137 {
00138 if(!$this->getClient())
00139 {
00140 $this->__setMessage('No client given');
00141 return false;
00142 }
00143 if(!$this->getUsername())
00144 {
00145 $this->__setMessage('No username given');
00146 return false;
00147 }
00148
00149 if(!$this->__buildAuth())
00150 {
00151 return false;
00152 }
00153 if(!$this->__setSessionSaveHandler())
00154 {
00155 return false;
00156 }
00157 $this->auth->start();
00158
00159 if(!$this->auth->getAuth())
00160 {
00161 $this->__getAuthStatus();
00162
00163 return false;
00164 }
00165
00166 $this->setSid(session_id());
00167
00168 return true;
00169 }
00170
00171 function start()
00172 {
00173 if(!$this->getSid())
00174 {
00175 $this->__setMessage('No session id given');
00176 return false;
00177 }
00178
00179 $this->auth->start();
00180
00181 return true;
00182 }
00183
00184 function validateSession()
00185 {
00186 if(!$this->getClient())
00187 {
00188 $this->__setMessage('No client given');
00189 return false;
00190 }
00191 if(!$this->getSid())
00192 {
00193 $this->__setMessage('No session id given');
00194 return false;
00195 }
00196
00197 if(!$this->__buildAuth())
00198 {
00199 return false;
00200 }
00201 if(!$this->__setSessionSaveHandler())
00202 {
00203 return false;
00204 }
00205
00206 $this->auth->start();
00207 if(!$this->auth->getAuth())
00208 {
00209 $this->__setMessage('Session not valid');
00210
00211 return false;
00212 }
00213
00214 return true;
00215 }
00216
00217 function logout()
00218 {
00219 if(!$this->getClient())
00220 {
00221 $this->__setMessage('No client given');
00222 return false;
00223 }
00224 if(!$this->getSid())
00225 {
00226 $this->__setMessage('No session id given');
00227 return false;
00228 }
00229
00230
00231 #if(!$this->__buildAuth())
00232 #{
00233 # return false;
00234 #}
00235 #if(!$this->__setSessionSaveHandler())
00236 #{
00237 # return false;
00238 #}
00239
00240
00241 #$this->auth->start();
00242 $this->auth->logout();
00243 session_destroy();
00244
00245 return true;
00246
00247 }
00248
00249 function __buildAuth()
00250 {
00251 include_once './classes/class.ilIniFile.php';
00252
00253
00254 $this->ilias_ini =& new ilIniFile('./ilias.ini.php');
00255 $this->ilias_ini->read();
00256
00257 if(!@file_exists("./".$this->ilias_ini->readVariable('clients','path')."/".$this->getClient()."/client.ini.php"))
00258 {
00259 $this->__setMessageCode('Client');
00260 $this->__setMessage('Client does not exist');
00261
00262 return false;
00263 }
00264
00265 $this->ini =& new ilIniFile("./".$this->ilias_ini->readVariable('clients','path')."/".$this->getClient()."/client.ini.php");
00266 $this->ini->read();
00267
00268 $this->dsn = $this->ini->readVariable("db","type").
00269 "://".$this->ini->readVariable("db", "user").
00270 ":".$this->ini->readVariable("db", "pass").
00271 "@".$this->ini->readVariable("db", "host").
00272 "/".$this->ini->readVariable("db", "name");
00273
00274
00275 $this->auth_params = array(
00276 'dsn' => $this->dsn,
00277 'table' => $this->ini->readVariable("auth", "table"),
00278 'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00279 'passwordcol' => $this->ini->readVariable("auth", "passcol")
00280 );
00281
00282 $this->auth = new Auth("DB", $this->auth_params,"",false);
00283
00284 return true;
00285 }
00286
00287 function __setSessionSaveHandler()
00288 {
00289 include_once './include/inc.db_session_handler.php';
00290 include_once './classes/class.ilUtil.php';
00291 include_once './classes/class.ilErrorHandling.php';
00292 include_once './classes/class.ilDBx.php';
00293
00294
00295 $GLOBALS['ilDB'] =& new ilDBx($this->dsn);
00296
00297 if(ini_get('session.save_handler') != 'user')
00298 {
00299 ini_set("session.save_handler", "user");
00300 }
00301 if(!db_set_save_handler())
00302 {
00303 $this->__setMessageCode('Server');
00304 $this->__setMessage('Cannot set session handler');
00305
00306 return false;
00307 }
00308
00309 return true;
00310 }
00311
00312 function __getAuthStatus()
00313 {
00314 switch($this->auth->getStatus())
00315 {
00316 case AUTH_EXPIRED:
00317 $this->__setMessageCode('Server');
00318 $this->__setMessage('Session expired');
00319
00320 return false;
00321
00322 case AUTH_IDLED:
00323 $this->__setMessageCode('Server');
00324 $this->__setMessage('Session idled');
00325
00326 return false;
00327
00328 case AUTH_WRONG_LOGIN:
00329 default:
00330 $this->__setMessageCode('Client');
00331 $this->__setMessage('Wrong login');
00332
00333 return false;
00334
00335
00336 }
00337 }
00338 }
00339 ?>