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

webservice/soap/classes/class.ilSoapAuthenticationCAS.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00034 include_once './webservice/soap/classes/class.ilSoapAuthentication.php';
00035 
00036 class ilSoapAuthenticationCAS extends ilSOAPAuthentication
00037 {
00038         function ilSoapAuthenticationCAS()
00039         {
00040                 parent::ilSOAPAuthentication();
00041         }
00042 
00043         //
00044         // inherited from ilSOAPAuthentication
00045         //
00046         /*
00047                 function disableSoapCheck()
00048                 function authenticate()
00049                 function validateSession()
00050                 function __checkSOAPEnabled()
00051         */
00052         
00053         //
00054         // inherited from ilBaseAuthentication via ilSOAPAuthentication
00055         //
00056         /*
00057                 function setClient($a_client)
00058                 function getClient()
00059                 function setUsername($a_username)
00060                 function getUsername()
00061                 function setPassword($a_password)               // not needed
00062                 function getPassword()                                  // not needed
00063                 function setSid($a_sid)
00064                 function getSid()
00065                 function getMessage()
00066                 function getMessageCode()
00067                 function __setMessage($a_message)
00068                 function __setMessageCode($a_message_code)
00069                 function setPasswordType($a_type)
00070                 function getPasswordType()
00071                 function start()
00072                 function logout()
00073                 function __buildDSN()
00074                 function __setSessionSaveHandler()
00075                 function __getAuthStatus()
00076         */
00077 
00078         // set ticket
00079         function setPT($a_pt)
00080         {
00081                 $this->pt = $a_pt;
00082                 $_GET['ticket'] = $a_pt;
00083         }
00084         function getPT()
00085         {
00086                 return $this->pt;
00087         }
00088 
00089         function authenticate()
00090         {
00091                 include_once("./Services/Init/classes/class.ilInitialisation.php");
00092                 $this->init = new ilInitialisation();
00093                 $this->init->requireCommonIncludes();
00094                 //$init->initSettings();
00095                 
00096                 
00097                 if(!$this->getClient())
00098                 {
00099                         $this->__setMessage('No client given');
00100                         return false;
00101                 }
00102                 
00103                 if(!$this->getUsername())
00104                 {
00105                         $this->__setMessage('No username given');
00106                         return false;
00107                 }
00108                 // Read ilias ini
00109                 if(!$this->__buildDSN())
00110                 {
00111                         $this->__setMessage('Error building dsn/Wrong client Id?');
00112                         return false;
00113                 }
00114                 
00115                 if(!$this->__setSessionSaveHandler())
00116                 {
00117                         return false;
00118                 }
00119                 if(!$this->__checkAgreement('cas'))
00120                 {
00121                         return false;
00122                 }
00123 
00124                 if(!$this->__buildAuth())
00125                 {
00126                         return false;
00127                 }
00128 
00129                 if($this->soap_check and !$this->__checkSOAPEnabled())
00130                 {
00131                         $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
00132                         $this->__setMessageCode('Server');
00133 
00134                         return false;
00135                 }
00136 
00137                 // check whether authentication is valid
00138                 //if (!$this->auth->checkCASAuth())
00139                 if (!phpCAS::checkAuthentication())
00140                 {
00141                         $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
00142                         return false;
00143                 }
00144 
00145                 $this->auth->forceCASAuth();
00146 
00147                 if ($this->getUsername() != $this->auth->getCASUser())
00148                 {
00149                         $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user does not match to ticket user.');
00150                         return false;
00151                 }
00152 
00153                 include_once('./Services/User/classes/class.ilObjUser.php');
00154                 $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->auth->getCASUser());
00155                 if ($local_user == "")
00156                 {
00157                         $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user authenticated but not existing in ILIAS user database.');
00158                         return false;
00159                 }
00160                                 
00161                 /*
00162                 $init->initIliasIniFile();
00163                 $init->initSettings();
00164                 $ilias =& new ILIAS();
00165                 $GLOBALS['ilias'] =& $ilias;*/
00166 
00167                 $this->auth->start();
00168 
00169                 if(!$this->auth->getAuth())
00170                 {
00171                         $this->__getAuthStatus();
00172 
00173                         return false;
00174                 }
00175 
00176                 $this->setSid(session_id());
00177 
00178                 return true;
00179         }
00180 
00181 
00182         function validateSession()
00183         {
00184                 if(!$this->getClient())
00185                 {
00186                         $this->__setMessage('No client given');
00187                         return false;
00188                 }
00189                 if(!$this->getSid())
00190                 {
00191                         $this->__setMessage('No session id given');
00192                         return false;
00193                 }
00194 
00195                 if(!$this->__buildDSN())
00196                 {
00197                         $this->__setMessage('Error building dsn');
00198                         return false;
00199                 }
00200                 if(!$this->__setSessionSaveHandler())
00201                 {
00202                         return false;
00203                 }
00204                 if(!$this->__buildAuth())
00205                 {
00206                         return false;
00207                 }
00208                 if($this->soap_check and !$this->__checkSOAPEnabled())
00209                 {
00210                         $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
00211                         $this->__setMessageCode('Server');
00212 
00213                         return false;
00214                 }
00215                 
00216                 // check whether authentication is valid
00217                 if (!$this->auth->checkCASAuth())
00218                 {
00219                         $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
00220                         return false;
00221                 }
00222                 $this->auth->forceCASAuth();
00223 
00224                 $this->auth->start();
00225                 if(!$this->auth->getAuth())
00226                 {
00227                         $this->__setMessage('Session not valid');
00228 
00229                         return false;
00230                 }
00231 
00232                 return true;
00233         }
00234 
00235         function __buildAuth()
00236         {
00237 
00238                 if (!is_object($this->db))
00239                 {
00240                         include_once './classes/class.ilDBx.php';
00241                         $this->db =& new ilDBx($this->dsn);
00242                 }
00243 
00244                 $GLOBALS["ilDB"] = $this->db;
00245                 $this->init->initSettings();
00246                 
00247                 $this->init->buildHTTPPath();
00248 
00249                 $query = "SELECT * FROM settings WHERE ".
00250                         " keyword = ".$this->db->quote("cas_server")." OR ".
00251                         " keyword = ".$this->db->quote("cas_port")." OR ".
00252                         " keyword = ".$this->db->quote("cas_uri");
00253                 $res = $this->db->query($query);
00254                 $cas_set = array();
00255                 while ($rec = $res->fetchRow(DB_FETCHMODE_ASSOC))
00256                 {
00257                         $cas_set[$rec["keyword"]] = $rec["value"];
00258                 }
00259 
00260                 $auth_params = array(
00261                         "server_version" => CAS_VERSION_2_0,
00262                         "server_hostname" => $cas_set["cas_server"],
00263                         "server_port" => $cas_set["cas_port"],
00264                         "server_uri" => $cas_set["cas_uri"]);
00265 
00266                 include_once("Services/CAS/classes/class.ilCASAuth.php");
00267                 $this->auth = new ilCASAuth($auth_params);
00268                 
00269                 // HTTP path will return full path to server.php directory
00270                 phpCAS::setFixedServiceURL(ILIAS_HTTP_PATH."/webservice/soap/server.php");
00271 
00272                 return true;
00273         }
00274 }
00275 ?>

Generated on Fri Dec 13 2013 17:57:03 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1