ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthContainerSOAP.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 include_once 'Auth/Container/LDAP.php';
25 include_once("./webservice/soap/lib/nusoap.php");
26 
36 {
37  protected $server_host = null;
38  protected $server_port = null;
39  protected $server_uri = null;
40  protected $server_https = null;
41  protected $server_nms = null;
42  protected $use_dot_net = null;
43 
44  protected $uri = null;
45 
46  protected $client = null;
47  protected $response = null;
48 
52  public function __construct()
53  {
54  $_POST['username'] = $_GET['ext_uid'];
55  $_POST['password'] = $_GET['soap_pw'];
56 
58  $this->initClient();
59  }
60 
65  public function initClient()
66  {
67  global $ilSetting;
68 
69  $this->server_host = $ilSetting->get('soap_auth_server');
70  $this->server_port = $ilSetting->get('soap_auth_port');
71  $this->server_uri = $ilSetting->get('soap_auth_uri');
72  $this->server_https = $ilSetting->get('soap_auth_use_https');
73  $this->server_nms = $ilSetting->get('soap_auth_namespace');
74  $this->use_dot_net = $ilSetting->get('use_dotnet');
75 
76  $this->uri = $this->server_https ? 'https://' : 'http://';
77  $this->uri .= $this->server_host;
78 
79  if($this->server_port > 0)
80  {
81  $this->uri .= (':'.$this->server_port);
82  }
83  if($this->server_uri)
84  {
85  $this->uri .= ('/'.$this->server_uri);
86  }
87  $this->client = new nusoap_client($this->uri);
88  }
89 
97  public function fetchData($a_username,$a_password,$isChallengeResponse = false)
98  {
99  $GLOBALS['ilLog']->write(__METHOD__.': Soap auth fetch data');
100 
101  // check whether external user exists in ILIAS database
102  $local_user = ilObjUser::_checkExternalAuthAccount("soap", $a_username);
103 
104  if ($local_user == "")
105  {
106  $new_user = true;
107  }
108  else
109  {
110  $new_user = false;
111  }
112 
113  $soapAction = "";
114  $nspref = "";
115  if ($this->use_dotnet)
116  {
117  $soapAction = $this->server_nms."/isValidSession";
118  $nspref = "ns1:";
119  }
120  $valid = $this->client->call('isValidSession',
121  array($nspref.'ext_uid' => $a_username,
122  $nspref.'soap_pw' => $a_password,
123  $nspref.'new_user' => $new_user),
124  $this->server_nms,
125  $soapAction);
126 //echo "<br>== Request ==";
127 //echo '<br><pre>' . htmlspecialchars($this->soap_client->request, ENT_QUOTES) . '</pre><br>';
128 //echo "<br>== Response ==";
129 //echo "<br>Valid: -".$valid["valid"]."-";
130 //echo '<br><pre>' . htmlspecialchars($this->soap_client->response, ENT_QUOTES) . '</pre>';
131 
132  if (trim($valid["valid"]) == "false")
133  {
134  $valid["valid"] = false;
135  }
136 
137  // to do check SOAP error!?
138  $valid["local_user"] = $local_user;
139  $this->response = $valid;
140  return $valid['valid'] == true;
141  }
142 
149  public function loginObserver($a_username,$a_auth)
150  {
151  global $ilias, $rbacadmin, $lng, $ilSetting;
152 
153  $GLOBALS['ilLog']->write(__METHOD__.': SOAP login observer called');
154 
155 
156  // TODO: handle passed credentials via GET
157  /*
158  if (empty($_GET["ext_uid"]) || empty($_GET["soap_pw"]))
159  {
160  $this->status = AUTH_WRONG_LOGIN;
161  return;
162  }
163  */
164 
165  // Not required anymore
166  /*
167  $validation_data = $this->validateSoapUser($_GET["ext_uid"], $_GET["soap_pw"]);
168 
169  if (!$validation_data["valid"])
170  {
171  $this->status = AUTH_WRONG_LOGIN;
172  return;
173  }
174  */
175 
176  $local_user = $this->response["local_user"];
177  if ($local_user != "")
178  {
179  // to do: handle update of user
180  $a_auth->setAuth($local_user);
181  return true;
182  }
183  if(!$ilSetting->get("soap_auth_create_users"))
184  {
185  $a_auth->status = AUTH_SOAP_NO_ILIAS_USER;
186  $a_auth->logout();
187  return false;
188  }
189 //echo "1";
190  // try to map external user via e-mail to ILIAS user
191  if ($this->response["email"] != "")
192  {
193 //echo "2";
194 //var_dump ($_POST);
195  $email_user = ilObjUser::_getLocalAccountsForEmail($this->response["email"]);
196 
197  // check, if password has been provided in user mapping screen
198  // (see ilStartUpGUI::showUserMappingSelection)
199  // FIXME
200  if ($_POST["LoginMappedUser"] != "")
201  {
202  if (count($email_user) > 0)
203  {
204  if (ilObjUser::_checkPassword($_POST["usr_id"], $_POST["password"]))
205  {
206  // password is correct -> map user
207  //$this->setAuth($local_user); (use login not id)
208  ilObjUser::_writeExternalAccount($_POST["usr_id"], $_GET["ext_uid"]);
209  ilObjUser::_writeAuthMode($_POST["usr_id"], "soap");
210  $_GET["cmd"] = $_POST["cmd"] = $_GET["auth_stat"]= "";
211  $local_user = ilObjUser::_lookupLogin($_POST["usr_id"]);
212  $a_auth->status = '';
213  $a_auth->setAuth($local_user);
214  return true;
215  }
216  else
217  {
218 //echo "6"; exit;
219 
220  $a_auth->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
221  $a_auth->sub_status = AUTH_WRONG_LOGIN;
222  $a_auth->logout();
223  return false;
224  }
225  }
226  }
227 
228  if (count($email_user) > 0 && $_POST["CreateUser"] == "")
229  {
230  $_GET["email"] = $this->response["email"];
231  $a_auth->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
232  $a_auth->logout();
233  return false;
234  }
235  }
236 
237  $userObj = new ilObjUser();
238  $local_user = ilAuthUtils::_generateLogin($a_username);
239 
240  $newUser["firstname"] = $this->response["firstname"];
241  $newUser["lastname"] = $this->response["lastname"];
242  $newUser["email"] = $this->response["email"];
243 
244  $newUser["login"] = $local_user;
245 
246  // to do: set valid password and send mail
247  $newUser["passwd"] = "";
248  $newUser["passwd_type"] = IL_PASSWD_MD5;
249 
250  // generate password, if local authentication is allowed
251  // and account mail is activated
252  $pw = "";
253 
254  if ($ilSetting->get("soap_auth_allow_local") &&
255  $ilSetting->get("soap_auth_account_mail"))
256  {
257  $pw = ilUtil::generatePasswords(1);
258  $pw = $pw[0];
259  $newUser["passwd"] = md5($pw);
260  $newUser["passwd_type"] = IL_PASSWD_MD5;
261  }
262 
263  //$newUser["gender"] = "m";
264  $newUser["auth_mode"] = "soap";
265  $newUser["ext_account"] = $a_username;
266  $newUser["profile_incomplete"] = 1;
267 
268  // system data
269  $userObj->assignData($newUser);
270  $userObj->setTitle($userObj->getFullname());
271  $userObj->setDescription($userObj->getEmail());
272 
273  // set user language to system language
274  $userObj->setLanguage($lng->lang_default);
275 
276  // Time limit
277  $userObj->setTimeLimitOwner(7);
278  $userObj->setTimeLimitUnlimited(1);
279  $userObj->setTimeLimitFrom(time());
280  $userObj->setTimeLimitUntil(time());
281 
282  // Create user in DB
283  $userObj->setOwner(0);
284  $userObj->create();
285  $userObj->setActive(1);
286 
287  $userObj->updateOwner();
288 
289  //insert user data in table user_data
290  $userObj->saveAsNew(false);
291 
292  // setup user preferences
293  $userObj->writePrefs();
294 
295  // to do: test this
296  $rbacadmin->assignUser($ilSetting->get('soap_auth_user_default_role'), $userObj->getId(),true);
297 
298  // send account mail
299  if ($ilSetting->get("soap_auth_account_mail"))
300  {
301  include_once('./Services/User/classes/class.ilObjUserFolder.php');
302  $amail = ilObjUserFolder::_lookupNewAccountMail($ilSetting->get("language"));
303  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
304  {
305  include_once("Services/Mail/classes/class.ilAccountMail.php");
306  $acc_mail = new ilAccountMail();
307 
308  if ($pw != "")
309  {
310  $acc_mail->setUserPassword($pw);
311  }
312  $acc_mail->setUser($userObj);
313  $acc_mail->send();
314  }
315  }
316 
317  unset($userObj);
318  $a_auth->setAuth($local_user);
319  return true;
320  }
321 }