• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

webservice/soap/classes/class.ilSoapAuthentication.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00033 include_once 'Auth/Auth.php';
00034 
00035 class ilSoapAuthentication
00036 {
00037         /*
00038          * session id
00039          * @var string
00040          */
00041         var $sid = '';
00042 
00043         /*
00044          * username
00045          * @var string
00046          */
00047         var $username = '';
00048 
00049         /*
00050          * password
00051          * @var string
00052          */
00053         var $password = '';
00054 
00055 
00056         /*
00057          * client id
00058          * @var string
00059          */
00060         var $client = '';
00061 
00062         function ilSoapAuthentication()
00063         {
00064                 $this->__setMessage('');
00065                 $this->__setMessageCode('Client');
00066         }
00067 
00068 
00069         // Set/Get
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                 // Read ilias ini
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                 // And finally logout
00242                 $this->auth->start();
00243                 $this->auth->logout();
00244                 session_destroy();
00245 
00246                 return true;
00247 
00248         }
00249         // PRIVATE
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                 // get ilias ini file
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 ?>

Generated on Fri Dec 13 2013 08:00:20 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1