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