ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
38 //
39 // inherited from ilSOAPAuthentication
40 //
41 /*
42 function disableSoapCheck()
43 function authenticate()
44 function validateSession()
45 function __checkSOAPEnabled()
46 */
47
48 //
49 // inherited from ilBaseAuthentication via ilSOAPAuthentication
50 //
51 /*
52 function setClient($a_client)
53 function getClient()
54 function setUsername($a_username)
55 function getUsername()
56 function setPassword($a_password) // not needed
57 function getPassword() // not needed
58 function setSid($a_sid)
59 function getSid()
60 function getMessage()
61 function getMessageCode()
62 function __setMessage($a_message)
63 function __setMessageCode($a_message_code)
64 function setPasswordType($a_type)
65 function getPasswordType()
66 function start()
67 function logout()
68 function __buildDSN()
69 function __setSessionSaveHandler()
70 function __getAuthStatus()
71 */
72
73 // set ticket
74 function setPT($a_pt)
75 {
76 $this->pt = $a_pt;
77 $_GET['ticket'] = $a_pt;
78 }
79 function getPT()
80 {
81 return $this->pt;
82 }
83
84 function authenticate()
85 {
86 include_once("./Services/Init/classes/class.ilInitialisation.php");
87 $this->init = new ilInitialisation();
88 $this->init->requireCommonIncludes();
89 //$init->initSettings();
90
91
92 if(!$this->getClient())
93 {
94 $this->__setMessage('No client given');
95 return false;
96 }
97
98 if(!$this->getUsername())
99 {
100 $this->__setMessage('No username given');
101 return false;
102 }
103 // Read ilias ini
104 if(!$this->__buildDSN())
105 {
106 $this->__setMessage('Error building dsn/Wrong client Id?');
107 return false;
108 }
109
110 if(!$this->__setSessionSaveHandler())
111 {
112 return false;
113 }
114 if(!$this->__checkAgreement('cas'))
115 {
116 return false;
117 }
118
119 if(!$this->__buildAuth())
120 {
121 return false;
122 }
123
124 if($this->soap_check and !$this->__checkSOAPEnabled())
125 {
126 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
127 $this->__setMessageCode('Server');
128
129 return false;
130 }
131
132 // check whether authentication is valid
133 //if (!$this->auth->checkCASAuth())
135 {
136 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
137 return false;
138 }
139
140 $this->auth->forceCASAuth();
141
142 if ($this->getUsername() != $this->auth->getCASUser())
143 {
144 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user does not match to ticket user.');
145 return false;
146 }
147
148 include_once('./Services/User/classes/class.ilObjUser.php');
149 $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->auth->getCASUser());
150 if ($local_user == "")
151 {
152 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user authenticated but not existing in ILIAS user database.');
153 return false;
154 }
155
156 /*
157 $init->initIliasIniFile();
158 $init->initSettings();
159 $ilias = new ILIAS();
160 $GLOBALS['ilias'] =& $ilias;*/
161
162 $this->auth->start();
163
164 if(!$this->auth->getAuth())
165 {
166 $this->__getAuthStatus();
167
168 return false;
169 }
170
171 $this->setSid(session_id());
172
173 return true;
174 }
175
176
178 {
179 if(!$this->getClient())
180 {
181 $this->__setMessage('No client given');
182 return false;
183 }
184 if(!$this->getSid())
185 {
186 $this->__setMessage('No session id given');
187 return false;
188 }
189
190 if(!$this->__buildDSN())
191 {
192 $this->__setMessage('Error building dsn');
193 return false;
194 }
195 if(!$this->__setSessionSaveHandler())
196 {
197 return false;
198 }
199 if(!$this->__buildAuth())
200 {
201 return false;
202 }
203 if($this->soap_check and !$this->__checkSOAPEnabled())
204 {
205 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
206 $this->__setMessageCode('Server');
207
208 return false;
209 }
210
211 // check whether authentication is valid
212 if (!$this->auth->checkCASAuth())
213 {
214 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
215 return false;
216 }
217 $this->auth->forceCASAuth();
218
219 $this->auth->start();
220 if(!$this->auth->getAuth())
221 {
222 $this->__setMessage('Session not valid');
223
224 return false;
225 }
226
227 return true;
228 }
229
230 function __buildAuth()
231 {
232
233 if (!is_object($this->db))
234 {
235 require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
236 $ilDB = ilDBWrapperFactory::getWrapper();
237 $ilDB->initFromIniFile();
238 $ilDB->connect();
239 $this->db = $ilDB;
240 }
241
242 $GLOBALS["ilDB"] = $this->db;
243 $this->init->initSettings();
244
245 $this->init->buildHTTPPath();
246 include_once './Services/Administration/classes/class.ilSetting.php';
247 $set = new ilSetting();
248
249 /*$query = "SELECT * FROM sett ings WHERE ".
250 " keyword = ".$this->db->quote("cas_server")." OR ".
251 " keyword = ".$this->db->quote("cas_port")." OR ".
252 " keyword = ".$this->db->quote("cas_uri");
253 $res = $this->db->query($query);
254 $cas_set = array();
255 while ($rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
256 {
257 $cas_set[$rec["keyword"]] = $rec["value"];
258 }*/
259 $cas_set["cas_server"] = $set->get("cas_server");
260 $cas_set["cas_port"] = $set->get("cas_port");
261 $cas_set["cas_uri"] = $set->get("cas_uri");
262
263 $auth_params = array(
264 "server_version" => CAS_VERSION_2_0,
265 "server_hostname" => $cas_set["cas_server"],
266 "server_port" => $cas_set["cas_port"],
267 "server_uri" => $cas_set["cas_uri"]);
268
269 include_once("Services/CAS/classes/class.ilCASAuth.php");
270 $this->auth = new ilCASAuth($auth_params);
271
272 // HTTP path will return full path to server.php directory
273 phpCAS::setFixedServiceURL(ILIAS_HTTP_PATH."/webservice/soap/server.php");
274
275 return true;
276 }
277}
278?>
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Class CASAuth.
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['loaded']
Global hash that tracks already loaded includes.
static checkAuthentication()
This method is called to check if the user is already authenticated locally or has a global cas sessi...
Definition: CAS.php:1073
static setFixedServiceURL($url)
Set the fixed URL that will be set as the CAS service parameter.
Definition: CAS.php:1566
const CAS_VERSION_2_0
Definition: CAS.php:78
global $ilDB