ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSoapAuthentication.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 
33 include_once 'Auth/Auth.php';
34 include_once './Services/Authentication/classes/class.ilBaseAuthentication.php';
35 
37 {
38  var $soap_check = true;
39 
40 
42  {
43  // First unset all cookie inforamtions
44  unset($_COOKIE['PHPSESSID']);
45 
47  $this->__setMessageCode('Client');
48  }
49 
50  function disableSoapCheck()
51  {
52  $this->soap_check = false;
53  }
54 
55  function authenticate()
56  {
57  if(!$this->getClient())
58  {
59  $this->__setMessage('No client given');
60  return false;
61  }
62  if(!$this->getUsername())
63  {
64  $this->__setMessage('No username given');
65  return false;
66  }
67  // Read ilias ini
68  if(!$this->__buildDSN())
69  {
70  $this->__setMessage('Error building dsn/Wrong client Id?');
71  return false;
72  }
73  if(!$this->__setSessionSaveHandler())
74  {
75  return false;
76  }
77  if(!$this->__checkAgreement('local'))
78  {
79  return false;
80  }
81  if(!$this->__buildAuth())
82  {
83  return false;
84  }
85  if($this->soap_check and !$this->__checkSOAPEnabled())
86  {
87  $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
88  $this->__setMessageCode('Server');
89 
90  return false;
91  }
92 
93 
94  $this->auth->start();
95 
96  if(!$this->auth->getAuth())
97  {
98  $this->__getAuthStatus();
99 
100  return false;
101  }
102 
103  $this->setSid(session_id());
104 
105  return true;
106  }
107 
115  protected function __checkAgreement($a_auth_mode)
116  {
117  global $ilDB;
118 
119  include_once('./Services/User/classes/class.ilObjUser.php');
120  include_once('./Services/Administration/classes/class.ilSetting.php');
121 
122  $GLOBALS['ilSetting'] = new ilSetting();
123 
124  if(!$login = ilObjUser::_checkExternalAuthAccount($a_auth_mode,$this->getUsername()))
125  {
126  // User does not exist
127  return true;
128  }
129 
131  {
132  $this->__setMessage('User aggrement no accepted.');
133  return false;
134  }
135  return true;
136  }
137 
138 
139 
140  function validateSession()
141  {
142  if(!$this->getClient())
143  {
144  $this->__setMessage('No client given');
145  return false;
146  }
147  if(!$this->getSid())
148  {
149  $this->__setMessage('No session id given');
150  return false;
151  }
152 
153  if(!$this->__buildDSN())
154  {
155  $this->__setMessage('Error building dsn');
156  return false;
157  }
158  if(!$this->__checkClientEnabled())
159  {
160  $this->__setMessage('Client disabled.');
161  return false;
162  }
163 
164  if(!$this->__setSessionSaveHandler())
165  {
166  return false;
167  }
168  if(!$this->__buildAuth())
169  {
170  return false;
171  }
172 
173  if (!$this->__checkGivenSessionId())
174  {
175  $this->__setMessage('Unknown session id.');
176  session_regenerate_id();
177  return false;
178  }
179 
180  if($this->soap_check and !$this->__checkSOAPEnabled())
181  {
182  $this->__setMessage('SOAP is not enabled in ILIAS administration for this client');
183  $this->__setMessageCode('Server');
184 
185  return false;
186  }
187  $this->auth->start();
188  if(!$this->auth->getAuth())
189  {
190  $this->__setMessage('Session not valid');
191 
192  return false;
193  }
194 
195  return true;
196  }
197 
204  protected function __checkGivenSessionId()
205  {
206  if ($this->getSid() == "")
207  {
208  return true;
209  }
210  return db_session_exists($this->getSid());
211  }
212 
213 
214  // PRIVATE
216  {
217  include_once './classes/class.ilDBx.php';
218 
219 
220  $db =& new ilDBx($this->dsn);
221 
222  $query = "SELECT * FROM settings WHERE keyword = 'soap_user_administration' AND value = 1";
223 
224  $res = $db->query($query);
225 
226  return $res->numRows() ? true : false;
227  }
228 
230  {
231  if(is_object($this->ini) and $this->ini->readVariable('client','access'))
232  {
233  return true;
234  }
235  return false;
236  }
237 }
238 ?>