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
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
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
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 $init = new ilInitialisation();
00093 $init->requireCommonIncludes();
00094 $init->buildHTTPPath();
00095
00096 if(!$this->getClient())
00097 {
00098 $this->__setMessage('No client given');
00099 return false;
00100 }
00101 if(!$this->getUsername())
00102 {
00103 $this->__setMessage('No username given');
00104 return false;
00105 }
00106
00107 if(!$this->__buildDSN())
00108 {
00109 $this->__setMessage('Error building dsn/Wrong client Id?');
00110 return false;
00111 }
00112 if(!$this->__setSessionSaveHandler())
00113 {
00114 return false;
00115 }
00116
00117 if(!$this->__buildAuth())
00118 {
00119 return false;
00120 }
00121 if($this->soap_check and !$this->__checkSOAPEnabled())
00122 {
00123 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
00124 $this->__setMessageCode('Server');
00125
00126 return false;
00127 }
00128
00129
00130
00131 if (!phpCAS::checkAuthentication())
00132 {
00133 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
00134 return false;
00135 }
00136 $this->auth->forceCASAuth();
00137
00138 if ($this->getUsername() != $this->auth->getCASUser())
00139 {
00140 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user does not match to ticket user.');
00141 return false;
00142 }
00143
00144 include_once("classes/class.ilObjUser.php");
00145 $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->auth->getCASUser());
00146 if ($local_user == "")
00147 {
00148 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user authenticated but not existing in ILIAS user database.');
00149 return false;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159 $this->auth->start();
00160
00161 if(!$this->auth->getAuth())
00162 {
00163 $this->__getAuthStatus();
00164
00165 return false;
00166 }
00167
00168 $this->setSid(session_id());
00169
00170 return true;
00171 }
00172
00173
00174 function validateSession()
00175 {
00176 if(!$this->getClient())
00177 {
00178 $this->__setMessage('No client given');
00179 return false;
00180 }
00181 if(!$this->getSid())
00182 {
00183 $this->__setMessage('No session id given');
00184 return false;
00185 }
00186
00187 if(!$this->__buildDSN())
00188 {
00189 $this->__setMessage('Error building dsn');
00190 return false;
00191 }
00192 if(!$this->__setSessionSaveHandler())
00193 {
00194 return false;
00195 }
00196 if(!$this->__buildAuth())
00197 {
00198 return false;
00199 }
00200 if($this->soap_check and !$this->__checkSOAPEnabled())
00201 {
00202 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
00203 $this->__setMessageCode('Server');
00204
00205 return false;
00206 }
00207
00208
00209 if (!$this->auth->checkCASAuth())
00210 {
00211 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
00212 return false;
00213 }
00214 $this->auth->forceCASAuth();
00215
00216 $this->auth->start();
00217 if(!$this->auth->getAuth())
00218 {
00219 $this->__setMessage('Session not valid');
00220
00221 return false;
00222 }
00223
00224 return true;
00225 }
00226
00227 function __buildAuth()
00228 {
00229
00230 if (!is_object($this->db))
00231 {
00232 include_once './classes/class.ilDBx.php';
00233 $this->db =& new ilDBx($this->dsn);
00234 }
00235
00236 $query = "SELECT * FROM settings WHERE ".
00237 " keyword = ".$this->db->quote("cas_server")." OR ".
00238 " keyword = ".$this->db->quote("cas_port")." OR ".
00239 " keyword = ".$this->db->quote("cas_uri");
00240 $res = $this->db->query($query);
00241 $cas_set = array();
00242 while ($rec = $res->fetchRow(DB_FETCHMODE_ASSOC))
00243 {
00244 $cas_set[$rec["keyword"]] = $rec["value"];
00245 }
00246
00247 $auth_params = array(
00248 "server_version" => CAS_VERSION_2_0,
00249 "server_hostname" => $cas_set["cas_server"],
00250 "server_port" => $cas_set["cas_port"],
00251 "server_uri" => $cas_set["cas_uri"]);
00252
00253 include_once("Services/CAS/classes/class.ilCASAuth.php");
00254 $this->auth = new ilCASAuth($auth_params);
00255
00256
00257 phpCAS::setFixedServiceURL(ILIAS_HTTP_PATH."/server.php");
00258
00259 return true;
00260 }
00261 }
00262 ?>