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

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

Generated on Fri Dec 13 2013 09:06:33 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1