Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 include_once("Auth/Auth.php");
00026 include_once("./webservice/soap/lib/nusoap.php");
00027
00034 class ilSOAPAuth extends Auth
00035 {
00036 var $valid = array();
00037
00042 function ilSOAPAuth($a_params)
00043 {
00044 parent::Auth("");
00045
00046 $this->server_hostname = $a_params["server_hostname"];
00047 $this->server_port = (int) $a_params["server_port"];
00048 $this->server_uri = $a_params["server_uri"];
00049 $this->namespace = $a_params["namespace"];
00050 $this->use_dotnet = $a_params["use_dotnet"];
00051 if ($a_params["https"])
00052 {
00053 $this->https = true;
00054 $uri = "https://";
00055 }
00056 else
00057 {
00058 $this->https = false;
00059 $uri = "http://";
00060 }
00061
00062 $uri.= $this->server_hostname;
00063
00064 if ($this->server_port > 0)
00065 {
00066 $uri.= ":".$this->server_port;
00067 }
00068
00069 if ($this->server_uri != "")
00070 {
00071 $uri.= "/".$this->server_uri;
00072 }
00073
00074 $this->uri = $uri;
00075
00076 $this->soap_client = new soap_client($this->uri);
00077
00078
00079 if ($err = $this->soap_client->getError())
00080 {
00081 die("SOAP Authentication Initialisation Error: ".$err);
00082 }
00083 }
00084
00088 static function testConnection($a_ext_uid, $a_soap_pw, $a_new_user)
00089 {
00090 global $ilSetting;
00091
00092 $settings = $ilSetting->getAll();
00093
00094 $server_hostname = $settings["soap_auth_server"];
00095 $server_port = (int) $settings["soap_auth_port"];
00096 $server_uri = $settings["soap_auth_uri"];
00097 $namespace = $settings["soap_auth_namespace"];
00098 $use_dotnet = $settings["soap_auth_use_dotnet"];
00099 if ($settings["soap_auth_use_https"])
00100 {
00101 $uri = "https://";
00102 }
00103 else
00104 {
00105 $uri = "http://";
00106 }
00107
00108 $uri.= $server_hostname;
00109
00110 if ($server_port > 0)
00111 {
00112 $uri.= ":".$server_port;
00113 }
00114
00115 if ($server_uri != "")
00116 {
00117 $uri.= "/".$server_uri;
00118 }
00119
00120 $soap_client = new soap_client($uri);
00121 if ($err = $soap_client->getError())
00122 {
00123 return "SOAP Authentication Initialisation Error: ".$err;
00124 }
00125
00126 $soapAction = "";
00127 $nspref = "";
00128 if ($use_dotnet)
00129 {
00130 $soapAction = $namespace."/isValidSession";
00131 $nspref = "ns1:";
00132 }
00133
00134 $valid = $soap_client->call('isValidSession',
00135 array($nspref.'ext_uid' => $a_ext_uid,
00136 $nspref.'soap_pw' => $a_soap_pw,
00137 $nspref.'new_user' => $a_new_user),
00138 $namespace,
00139 $soapAction);
00140
00141 return
00142 "<br>== Request ==".
00143 '<br><pre>' . htmlspecialchars(str_replace("\" ", "\"\n ", str_replace(">", ">\n", $soap_client->request)), ENT_QUOTES) . '</pre><br>'.
00144 "<br>== Response ==".
00145 "<br>Valid: -".$valid["valid"]."-".
00146 '<br><pre>' . htmlspecialchars(str_replace("\" ", "\"\n ", str_replace(">", ">\n", $soap_client->response)), ENT_QUOTES) . '</pre>';
00147 }
00148
00154 function validateSOAPUser($a_ext_uid, $a_soap_pw)
00155 {
00156
00157 $local_user = ilObjUser::_checkExternalAuthAccount("soap", $a_ext_uid);
00158
00159 if ($local_user == "")
00160 {
00161 $new_user = true;
00162 }
00163 else
00164 {
00165 $new_user = false;
00166 }
00167
00168 $soapAction = "";
00169 $nspref = "";
00170 if ($this->use_dotnet)
00171 {
00172 $soapAction = $this->namespace."/isValidSession";
00173 $nspref = "ns1:";
00174 }
00175
00176 $valid = $this->soap_client->call('isValidSession',
00177 array($nspref.'ext_uid' => $a_ext_uid,
00178 $nspref.'soap_pw' => $a_soap_pw,
00179 $nspref.'new_user' => $new_user),
00180 $this->namespace,
00181 $soapAction);
00182
00183
00184
00185
00186
00187
00188
00189
00190 $valid["local_user"] = $local_user;
00191
00192 $this->valid = $valid;
00193
00194 return $valid;
00195 }
00196
00200 function getValidationData()
00201 {
00202 return $this->valid;
00203 }
00204
00211 function login()
00212 {
00213 global $ilias, $rbacadmin, $lng, $ilSetting;
00214
00215 if (empty($_GET["ext_uid"]) || empty($_GET["soap_pw"]))
00216 {
00217 $this->status = AUTH_WRONG_LOGIN;
00218 return;
00219 }
00220
00221 $validation_data = $this->validateSoapUser($_GET["ext_uid"], $_GET["soap_pw"]);
00222
00223 if (!$validation_data["valid"])
00224 {
00225 $this->status = AUTH_WRONG_LOGIN;
00226 return;
00227 }
00228
00229 $local_user = $validation_data["local_user"];
00230
00231 if ($local_user != "")
00232 {
00233
00234 $this->setAuth($local_user);
00235 }
00236 else
00237 {
00238 if (!$ilSetting->get("soap_auth_create_users"))
00239 {
00240 $this->status = AUTH_SOAP_NO_ILIAS_USER;
00241 $this->logout();
00242 return;
00243 }
00244
00245
00246 if ($validation_data["email"] != "")
00247 {
00248
00249
00250 $email_user = ilObjUser::_getLocalAccountsForEmail($validation_data["email"]);
00251
00252
00253
00254 if ($_POST["LoginMappedUser"] != "")
00255 {
00256 if (count($email_user) > 0)
00257 {
00258 if (ilObjUser::_checkPassword($_POST["usr_id"], $_POST["password"]))
00259 {
00260
00261
00262 ilObjUser::_writeExternalAccount($_POST["usr_id"], $_GET["ext_uid"]);
00263 ilObjUser::_writeAuthMode($_POST["usr_id"], "soap");
00264 $_GET["cmd"] = $_POST["cmd"] = $_GET["auth_stat"]= "";
00265 $local_user = ilObjUser::_lookupLogin($_POST["usr_id"]);
00266 $this->status = "";
00267 $this->setAuth($local_user);
00268 return;
00269 }
00270 else
00271 {
00272
00273 $this->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
00274 $this->sub_status = AUTH_WRONG_LOGIN;
00275 $this->logout();
00276 return;
00277 }
00278 }
00279 }
00280
00281 if (count($email_user) > 0 && $_POST["CreateUser"] == "")
00282 {
00283 $_GET["email"] = $validation_data["email"];
00284 $this->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
00285 $this->logout();
00286 return;
00287 }
00288 }
00289
00290 $userObj = new ilObjUser();
00291
00292 $local_user = ilAuthUtils::_generateLogin($_GET["ext_uid"]);
00293
00294 $newUser["firstname"] = $validation_data["firstname"];
00295 $newUser["lastname"] = $validation_data["lastname"];
00296 $newUser["email"] = $validation_data["email"];
00297
00298 $newUser["login"] = $local_user;
00299
00300
00301 $newUser["passwd"] = "";
00302 $newUser["passwd_type"] = IL_PASSWD_MD5;
00303
00304
00305
00306 $pw = "";
00307
00308 if ($ilSetting->get("soap_auth_allow_local") &&
00309 $ilSetting->get("soap_auth_account_mail"))
00310 {
00311 $pw = ilUtil::generatePasswords(1);
00312 $pw = $pw[0];
00313 $newUser["passwd"] = md5($pw);
00314 $newUser["passwd_type"] = IL_PASSWD_MD5;
00315 }
00316
00317
00318 $newUser["auth_mode"] = "soap";
00319 $newUser["ext_account"] = $_GET["ext_uid"];
00320 $newUser["profile_incomplete"] = 1;
00321
00322
00323 $userObj->assignData($newUser);
00324 $userObj->setTitle($userObj->getFullname());
00325 $userObj->setDescription($userObj->getEmail());
00326
00327
00328 $userObj->setLanguage($lng->lang_default);
00329
00330
00331 $userObj->setTimeLimitOwner(7);
00332 $userObj->setTimeLimitUnlimited(1);
00333 $userObj->setTimeLimitFrom(time());
00334 $userObj->setTimeLimitUntil(time());
00335
00336
00337 $userObj->setOwner(6);
00338 $userObj->create();
00339 $userObj->setActive(1, 6);
00340
00341 $userObj->updateOwner();
00342
00343
00344 $userObj->saveAsNew(false);
00345
00346
00347 $userObj->writePrefs();
00348
00349
00350 $rbacadmin->assignUser($ilSetting->get('soap_auth_user_default_role'), $userObj->getId(),true);
00351
00352
00353 if ($ilSetting->get("soap_auth_account_mail"))
00354 {
00355 include_once('./Services/User/classes/class.ilObjUserFolder.php');
00356 $amail = ilObjUserFolder::_lookupNewAccountMail($ilSetting->get("language"));
00357 if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
00358 {
00359 include_once("Services/Mail/classes/class.ilAccountMail.php");
00360 $acc_mail = new ilAccountMail();
00361
00362 if ($pw != "")
00363 {
00364 $acc_mail->setUserPassword($pw);
00365 }
00366 $acc_mail->setUser($userObj);
00367 $acc_mail->send();
00368 }
00369 }
00370
00371 unset($userObj);
00372
00373 $this->setAuth($local_user);
00374
00375 }
00376 }
00377
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00419 function logout()
00420 {
00421 parent::logout();
00422 }
00423
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00447
00448
00449
00450
00451
00452
00453
00454
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517 }
00518 ?>