ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSoapAuthenticationCAS.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
34include_once './webservice/soap/classes/class.ilSoapAuthentication.php';
35
37{
39 {
40 parent::ilSOAPAuthentication();
41 }
42
43 //
44 // inherited from ilSOAPAuthentication
45 //
46 /*
47 function disableSoapCheck()
48 function authenticate()
49 function validateSession()
50 function __checkSOAPEnabled()
51 */
52
53 //
54 // inherited from ilBaseAuthentication via ilSOAPAuthentication
55 //
56 /*
57 function setClient($a_client)
58 function getClient()
59 function setUsername($a_username)
60 function getUsername()
61 function setPassword($a_password) // not needed
62 function getPassword() // not needed
63 function setSid($a_sid)
64 function getSid()
65 function getMessage()
66 function getMessageCode()
67 function __setMessage($a_message)
68 function __setMessageCode($a_message_code)
69 function setPasswordType($a_type)
70 function getPasswordType()
71 function start()
72 function logout()
73 function __buildDSN()
74 function __setSessionSaveHandler()
75 function __getAuthStatus()
76 */
77
78 // set ticket
79 function setPT($a_pt)
80 {
81 $this->pt = $a_pt;
82 $_GET['ticket'] = $a_pt;
83 }
84 function getPT()
85 {
86 return $this->pt;
87 }
88
89 function authenticate()
90 {
91 include_once("./Services/Init/classes/class.ilInitialisation.php");
92 $this->init = new ilInitialisation();
93 $this->init->requireCommonIncludes();
94 //$init->initSettings();
95
96
97 if(!$this->getClient())
98 {
99 $this->__setMessage('No client given');
100 return false;
101 }
102
103 if(!$this->getUsername())
104 {
105 $this->__setMessage('No username given');
106 return false;
107 }
108 // Read ilias ini
109 if(!$this->__buildDSN())
110 {
111 $this->__setMessage('Error building dsn/Wrong client Id?');
112 return false;
113 }
114
115 if(!$this->__setSessionSaveHandler())
116 {
117 return false;
118 }
119 if(!$this->__checkAgreement('cas'))
120 {
121 return false;
122 }
123
124 if(!$this->__buildAuth())
125 {
126 return false;
127 }
128
129 if($this->soap_check and !$this->__checkSOAPEnabled())
130 {
131 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
132 $this->__setMessageCode('Server');
133
134 return false;
135 }
136
137 // check whether authentication is valid
138 //if (!$this->auth->checkCASAuth())
140 {
141 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
142 return false;
143 }
144
145 $this->auth->forceCASAuth();
146
147 if ($this->getUsername() != $this->auth->getCASUser())
148 {
149 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user does not match to ticket user.');
150 return false;
151 }
152
153 include_once('./Services/User/classes/class.ilObjUser.php');
154 $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->auth->getCASUser());
155 if ($local_user == "")
156 {
157 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user authenticated but not existing in ILIAS user database.');
158 return false;
159 }
160
161 /*
162 $init->initIliasIniFile();
163 $init->initSettings();
164 $ilias =& new ILIAS();
165 $GLOBALS['ilias'] =& $ilias;*/
166
167 $this->auth->start();
168
169 if(!$this->auth->getAuth())
170 {
171 $this->__getAuthStatus();
172
173 return false;
174 }
175
176 $this->setSid(session_id());
177
178 return true;
179 }
180
181
183 {
184 if(!$this->getClient())
185 {
186 $this->__setMessage('No client given');
187 return false;
188 }
189 if(!$this->getSid())
190 {
191 $this->__setMessage('No session id given');
192 return false;
193 }
194
195 if(!$this->__buildDSN())
196 {
197 $this->__setMessage('Error building dsn');
198 return false;
199 }
200 if(!$this->__setSessionSaveHandler())
201 {
202 return false;
203 }
204 if(!$this->__buildAuth())
205 {
206 return false;
207 }
208 if($this->soap_check and !$this->__checkSOAPEnabled())
209 {
210 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
211 $this->__setMessageCode('Server');
212
213 return false;
214 }
215
216 // check whether authentication is valid
217 if (!$this->auth->checkCASAuth())
218 {
219 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
220 return false;
221 }
222 $this->auth->forceCASAuth();
223
224 $this->auth->start();
225 if(!$this->auth->getAuth())
226 {
227 $this->__setMessage('Session not valid');
228
229 return false;
230 }
231
232 return true;
233 }
234
235 function __buildAuth()
236 {
237
238 if (!is_object($this->db))
239 {
240 require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
242 $ilDB->initFromIniFile();
243 $ilDB->connect();
244 $this->db = $ilDB;
245 }
246
247 $GLOBALS["ilDB"] = $this->db;
248 $this->init->initSettings();
249
250 $this->init->buildHTTPPath();
251 include_once './Services/Administration/classes/class.ilSetting.php';
252 $set = new ilSetting();
253
254 /*$query = "SELECT * FROM sett ings WHERE ".
255 " keyword = ".$this->db->quote("cas_server")." OR ".
256 " keyword = ".$this->db->quote("cas_port")." OR ".
257 " keyword = ".$this->db->quote("cas_uri");
258 $res = $this->db->query($query);
259 $cas_set = array();
260 while ($rec = $res->fetchRow(DB_FETCHMODE_ASSOC))
261 {
262 $cas_set[$rec["keyword"]] = $rec["value"];
263 }*/
264 $cas_set["cas_server"] = $set->get("cas_server");
265 $cas_set["cas_port"] = $set->get("cas_port");
266 $cas_set["cas_uri"] = $set->get("cas_uri");
267
268 $auth_params = array(
269 "server_version" => CAS_VERSION_2_0,
270 "server_hostname" => $cas_set["cas_server"],
271 "server_port" => $cas_set["cas_port"],
272 "server_uri" => $cas_set["cas_uri"]);
273
274 include_once("Services/CAS/classes/class.ilCASAuth.php");
275 $this->auth = new ilCASAuth($auth_params);
276
277 // HTTP path will return full path to server.php directory
278 phpCAS::setFixedServiceURL(ILIAS_HTTP_PATH."/webservice/soap/server.php");
279
280 return true;
281 }
282}
283?>
$_GET["client_id"]
Class CASAuth.
static getWrapper($a_type, $a_inactive_mysqli=null)
ILIAS Initialisation Utility Class perform basic setup: init database handler, load configuration fil...
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
ILIAS Setting Class.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
checkAuthentication()
This method is called to check if the user is authenticated (use the gateway feature).
Definition: CAS.php:933
setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
Definition: CAS.php:1374
const CAS_VERSION_2_0
Definition: CAS.php:81
global $ilDB