ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 public function setPT($a_pt)
75 {
76 $this->pt = $a_pt;
77 $_GET['ticket'] = $a_pt;
78 }
79 public function getPT()
80 {
81 return $this->pt;
82 }
83
84 public 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 $this->__setMessage('No client given');
94 return false;
95 }
96
97 if (!$this->getUsername()) {
98 $this->__setMessage('No username given');
99 return false;
100 }
101 // Read ilias ini
102 if (!$this->__buildDSN()) {
103 $this->__setMessage('Error building dsn/Wrong client Id?');
104 return false;
105 }
106
107 if (!$this->__setSessionSaveHandler()) {
108 return false;
109 }
110 if (!$this->__checkAgreement('cas')) {
111 return false;
112 }
113
114 if (!$this->__buildAuth()) {
115 return false;
116 }
117
118 if ($this->soap_check and !$this->__checkSOAPEnabled()) {
119 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
120 $this->__setMessageCode('Server');
121
122 return false;
123 }
124
125 // check whether authentication is valid
126 //if (!$this->auth->checkCASAuth())
128 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
129 return false;
130 }
131
132 $this->auth->forceCASAuth();
133
134 if ($this->getUsername() != $this->auth->getCASUser()) {
135 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user does not match to ticket user.');
136 return false;
137 }
138
139 include_once('./Services/User/classes/class.ilObjUser.php');
140 $local_user = ilObjUser::_checkExternalAuthAccount("cas", $this->auth->getCASUser());
141 if ($local_user == "") {
142 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): SOAP CAS user authenticated but not existing in ILIAS user database.');
143 return false;
144 }
145
146 /*
147 $init->initIliasIniFile();
148 $init->initSettings();
149 $ilias = new ILIAS();
150 $GLOBALS['ilias'] =& $ilias;*/
151
152 $this->auth->start();
153
154 if (!$this->auth->getAuth()) {
155 $this->__getAuthStatus();
156
157 return false;
158 }
159
160 $this->setSid(session_id());
161
162 return true;
163 }
164
165
166 public function validateSession()
167 {
168 if (!$this->getClient()) {
169 $this->__setMessage('No client given');
170 return false;
171 }
172 if (!$this->getSid()) {
173 $this->__setMessage('No session id given');
174 return false;
175 }
176
177 if (!$this->__buildDSN()) {
178 $this->__setMessage('Error building dsn');
179 return false;
180 }
181 if (!$this->__setSessionSaveHandler()) {
182 return false;
183 }
184 if (!$this->__buildAuth()) {
185 return false;
186 }
187 if ($this->soap_check and !$this->__checkSOAPEnabled()) {
188 $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
189 $this->__setMessageCode('Server');
190
191 return false;
192 }
193
194 // check whether authentication is valid
195 if (!$this->auth->checkCASAuth()) {
196 $this->__setMessage('ilSOAPAuthenticationCAS::authenticate(): No valid CAS authentication.');
197 return false;
198 }
199 $this->auth->forceCASAuth();
200
201 $this->auth->start();
202 if (!$this->auth->getAuth()) {
203 $this->__setMessage('Session not valid');
204
205 return false;
206 }
207
208 return true;
209 }
210
211 public function __buildAuth()
212 {
213 if (!is_object($this->db)) {
214 require_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
215 $ilDB = ilDBWrapperFactory::getWrapper();
216 $ilDB->initFromIniFile();
217 $ilDB->connect();
218 $this->db = $ilDB;
219 }
220
221 $GLOBALS["ilDB"] = $this->db;
222 $this->init->initSettings();
223
224 $this->init->buildHTTPPath();
225 include_once './Services/Administration/classes/class.ilSetting.php';
226 $set = new ilSetting();
227
228 /*$query = "SELECT * FROM sett ings WHERE ".
229 " keyword = ".$this->db->quote("cas_server")." OR ".
230 " keyword = ".$this->db->quote("cas_port")." OR ".
231 " keyword = ".$this->db->quote("cas_uri");
232 $res = $this->db->query($query);
233 $cas_set = array();
234 while ($rec = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
235 {
236 $cas_set[$rec["keyword"]] = $rec["value"];
237 }*/
238 $cas_set["cas_server"] = $set->get("cas_server");
239 $cas_set["cas_port"] = $set->get("cas_port");
240 $cas_set["cas_uri"] = $set->get("cas_uri");
241
242 $auth_params = array(
243 "server_version" => CAS_VERSION_2_0,
244 "server_hostname" => $cas_set["cas_server"],
245 "server_port" => $cas_set["cas_port"],
246 "server_uri" => $cas_set["cas_uri"]);
247
248 include_once("Services/CAS/classes/class.ilCASAuth.php");
249 $this->auth = new ilCASAuth($auth_params);
250
251 // HTTP path will return full path to server.php directory
252 phpCAS::setFixedServiceURL(ILIAS_HTTP_PATH . "/webservice/soap/server.php");
253
254 return true;
255 }
256}
$_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, $tryFallback=true)
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