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.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 if ($err = $this->soap_client->getError())
00079 {
00080 die("SOAP Authentication Initialisation Error: ".$err);
00081 }
00082 }
00083
00089 function validateSOAPUser($a_ext_uid, $a_soap_pw)
00090 {
00091
00092 $local_user = ilObjUser::_checkExternalAuthAccount("soap", $a_ext_uid);
00093
00094 if ($local_user == "")
00095 {
00096 $new_user = true;
00097 }
00098 else
00099 {
00100 $new_user = false;
00101 }
00102
00103 $soapAction = "";
00104 $nspref = "";
00105 if ($this->use_dotnet)
00106 {
00107 $soapAction = $this->namespace."/isValidSession";
00108 $nspref = "ns1:";
00109 }
00110
00111 $valid = $this->soap_client->call('isValidSession',
00112 array($nspref.'ext_uid' => $a_ext_uid,
00113 $nspref.'soap_pw' => $a_soap_pw,
00114 $nspref.'new_user' => $new_user),
00115 $this->namespace,
00116 $soapAction);
00117
00118
00119 $valid["local_user"] = $local_user;
00120
00121 $this->valid = $valid;
00122
00123 return $valid;
00124 }
00125
00129 function getValidationData()
00130 {
00131 return $this->valid;
00132 }
00133
00140 function login()
00141 {
00142 global $ilias, $rbacadmin, $lng, $ilSetting;
00143
00144 if (empty($_GET["ext_uid"]) || empty($_GET["soap_pw"]))
00145 {
00146 $this->status = AUTH_WRONG_LOGIN;
00147 return;
00148 }
00149
00150 $validation_data = $this->validateSoapUser($_GET["ext_uid"], $_GET["soap_pw"]);
00151
00152 if (!$validation_data["valid"])
00153 {
00154 $this->status = AUTH_WRONG_LOGIN;
00155 return;
00156 }
00157
00158 $local_user = $validation_data["local_user"];
00159
00160 if ($local_user != "")
00161 {
00162
00163 $this->setAuth($local_user);
00164 }
00165 else
00166 {
00167 if (!$ilSetting->get("soap_auth_create_users"))
00168 {
00169 $this->status = AUTH_SOAP_NO_ILIAS_USER;
00170 $this->logout();
00171 return;
00172 }
00173
00174
00175 if ($validation_data["email"] != "")
00176 {
00177
00178
00179 $email_user = ilObjUser::_getLocalAccountsForEmail($validation_data["email"]);
00180
00181
00182
00183 if ($_POST["LoginMappedUser"] != "")
00184 {
00185 if (count($email_user) > 0)
00186 {
00187 if (ilObjUser::_checkPassword($_POST["usr_id"], $_POST["password"]))
00188 {
00189
00190
00191 ilObjUser::_writeExternalAccount($_POST["usr_id"], $_GET["ext_uid"]);
00192 ilObjUser::_writeAuthMode($_POST["usr_id"], "soap");
00193 $_GET["cmd"] = $_POST["cmd"] = $_GET["auth_stat"]= "";
00194 $local_user = ilObjUser::_lookupLogin($_POST["usr_id"]);
00195 $this->status = "";
00196 $this->setAuth($local_user);
00197 return;
00198 }
00199 else
00200 {
00201
00202 $this->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
00203 $this->sub_status = AUTH_WRONG_LOGIN;
00204 $this->logout();
00205 return;
00206 }
00207 }
00208 }
00209
00210 if (count($email_user) > 0 && $_POST["CreateUser"] == "")
00211 {
00212 $_GET["email"] = $validation_data["email"];
00213 $this->status = AUTH_SOAP_NO_ILIAS_USER_BUT_EMAIL;
00214 $this->logout();
00215 return;
00216 }
00217 }
00218
00219 $userObj = new ilObjUser();
00220
00221 $local_user = ilAuthUtils::_generateLogin($_GET["ext_uid"]);
00222
00223 $newUser["firstname"] = $validation_data["firstname"];
00224 $newUser["lastname"] = $validation_data["lastname"];
00225 $newUser["email"] = $validation_data["email"];
00226
00227 $newUser["login"] = $local_user;
00228
00229
00230 $newUser["passwd"] = "";
00231 $newUser["passwd_type"] = IL_PASSWD_MD5;
00232
00233
00234
00235 $pw = "";
00236
00237 if ($ilSetting->get("soap_auth_allow_local") &&
00238 $ilSetting->get("soap_auth_account_mail"))
00239 {
00240 $pw = ilUtil::generatePasswords(1);
00241 $pw = $pw[0];
00242 $newUser["passwd"] = md5($pw);
00243 $newUser["passwd_type"] = IL_PASSWD_MD5;
00244 }
00245
00246
00247 $newUser["auth_mode"] = "soap";
00248 $newUser["ext_account"] = $_GET["ext_uid"];
00249 $newUser["profile_incomplete"] = 1;
00250
00251
00252 $userObj->assignData($newUser);
00253 $userObj->setTitle($userObj->getFullname());
00254 $userObj->setDescription($userObj->getEmail());
00255
00256
00257 $userObj->setLanguage($lng->lang_default);
00258
00259
00260 $userObj->setTimeLimitOwner(7);
00261 $userObj->setTimeLimitUnlimited(1);
00262 $userObj->setTimeLimitFrom(time());
00263 $userObj->setTimeLimitUntil(time());
00264
00265
00266 $userObj->setOwner(6);
00267 $userObj->create();
00268 $userObj->setActive(1, 6);
00269
00270 $userObj->updateOwner();
00271
00272
00273 $userObj->saveAsNew(false);
00274
00275
00276 $userObj->writePrefs();
00277
00278
00279 $rbacadmin->assignUser($ilSetting->get('soap_auth_user_default_role'), $userObj->getId(),true);
00280
00281
00282 if ($ilSetting->get("soap_auth_account_mail"))
00283 {
00284 include_once("classes/class.ilObjUserFolder.php");
00285 $amail = ilObjUserFolder::_lookupNewAccountMail($ilSetting->get("language"));
00286 if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
00287 {
00288 include_once("classes/class.ilAccountMail.php");
00289 $acc_mail = new ilAccountMail();
00290
00291 if ($pw != "")
00292 {
00293 $acc_mail->setUserPassword($pw);
00294 }
00295 $acc_mail->setUser($userObj);
00296 $acc_mail->send();
00297 }
00298 }
00299
00300 unset($userObj);
00301
00302 $this->setAuth($local_user);
00303
00304 }
00305 }
00306
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00348 function logout()
00349 {
00350 parent::logout();
00351 }
00352
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00376
00377
00378
00379
00380
00381
00382
00383
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446 }
00447 ?>