ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  protected $uri = null;
44  protected $client = null;
45  protected $response = null;
46 
50  public function __construct()
51  {
52  $_POST['username'] = $_GET['ext_uid'];
53  $_POST['password'] = $_GET['soap_pw'];
54 
55  parent::__construct();
56  $this->initClient();
57  }
58 
62  public function initClient()
63  {
64  global $ilSetting;
65 
66  $this->server_host = $ilSetting->get('soap_auth_server');
67  $this->server_port = $ilSetting->get('soap_auth_port');
68  $this->server_uri = $ilSetting->get('soap_auth_uri');
69  $this->server_https = $ilSetting->get('soap_auth_use_https');
70  $this->server_nms = $ilSetting->get('soap_auth_namespace');
71  $this->use_dot_net = $ilSetting->get('use_dotnet');
72 
73  $this->uri = $this->server_https ? 'https://' : 'http://';
74  $this->uri .= $this->server_host;
75 
76  if($this->server_port > 0)
77  {
78  $this->uri .= (':'.$this->server_port);
79  }
80  if($this->server_uri)
81  {
82  $this->uri .= ('/'.$this->server_uri);
83  }
84  $this->client = new nusoap_client($this->uri);
85  }
86 
94  public function fetchData($a_username, $a_password, $isChallengeResponse = false)
95  {
96  $GLOBALS['ilLog']->write(__METHOD__.': Soap auth fetch data');
97 
98  // check whether external user exists in ILIAS database
99  $local_user = ilObjUser::_checkExternalAuthAccount("soap", $a_username);
100 
101  if ($local_user == "")
102  {
103  $new_user = true;
104  }
105  else
106  {
107  $new_user = false;
108  }
109 
110  $soapAction = "";
111  $nspref = "";
112  if ($this->use_dotnet)
113  {
114  $soapAction = $this->server_nms."/isValidSession";
115  $nspref = "ns1:";
116  }
117  $valid = $this->client->call('isValidSession',
118  array($nspref.'ext_uid' => $a_username,
119  $nspref.'soap_pw' => $a_password,
120  $nspref.'new_user' => $new_user),
121  $this->server_nms,
122  $soapAction);
123 
124  if (trim($valid["valid"]) == "false")
125  {
126  $valid["valid"] = false;
127  }
128 
129  // to do check SOAP error!?
130  $valid["local_user"] = $local_user;
131  $this->response = $valid;
132 
133  return $valid['valid'] == true;
134  }
135 
142  public function loginObserver($a_username,$a_auth)
143  {
144  global $rbacadmin, $lng, $ilSetting;
145 
146  $GLOBALS['ilLog']->write(__METHOD__.': SOAP login observer called');
147 
148  $local_user = $this->response["local_user"];
149  if ($local_user != "")
150  {
151  // to do: handle update of user
152  $a_auth->setAuth($local_user);
153  return true;
154  }
155  if(!$ilSetting->get("soap_auth_create_users"))
156  {
157  $a_auth->status = AUTH_SOAP_NO_ILIAS_USER;
158  $a_auth->logout();
159  return false;
160  }
161 
162  $userObj = new ilObjUser();
163  $local_user = ilAuthUtils::_generateLogin($a_username);
164 
165  $newUser["firstname"] = $this->response["firstname"];
166  $newUser["lastname"] = $this->response["lastname"];
167  $newUser["email"] = $this->response["email"];
168 
169  $newUser["login"] = $local_user;
170 
171  // to do: set valid password and send mail
172  $newUser["passwd"] = "";
173  $newUser["passwd_type"] = IL_PASSWD_CRYPTED;
174 
175  // generate password, if local authentication is allowed
176  // and account mail is activated
177  $pw = "";
178 
179  if ($ilSetting->get("soap_auth_allow_local") &&
180  $ilSetting->get("soap_auth_account_mail"))
181  {
182  $pw = ilUtil::generatePasswords(1);
183  $pw = $pw[0];
184  $newUser["passwd"] = $pw;
185  $newUser["passwd_type"] = IL_PASSWD_PLAIN;
186  }
187 
188  //$newUser["gender"] = "m";
189  $newUser["auth_mode"] = "soap";
190  $newUser["ext_account"] = $a_username;
191  $newUser["profile_incomplete"] = 1;
192 
193  // system data
194  $userObj->assignData($newUser);
195  $userObj->setTitle($userObj->getFullname());
196  $userObj->setDescription($userObj->getEmail());
197 
198  // set user language to system language
199  $userObj->setLanguage($lng->lang_default);
200 
201  // Time limit
202  $userObj->setTimeLimitOwner(7);
203  $userObj->setTimeLimitUnlimited(1);
204  $userObj->setTimeLimitFrom(time());
205  $userObj->setTimeLimitUntil(time());
206 
207  // Create user in DB
208  $userObj->setOwner(0);
209  $userObj->create();
210  $userObj->setActive(1);
211 
212  $userObj->updateOwner();
213 
214  //insert user data in table user_data
215  $userObj->saveAsNew(false);
216 
217  // setup user preferences
218  $userObj->writePrefs();
219 
220  // to do: test this
221  $rbacadmin->assignUser($ilSetting->get('soap_auth_user_default_role'), $userObj->getId(),true);
222 
223  // send account mail
224  if ($ilSetting->get("soap_auth_account_mail"))
225  {
226  include_once('./Services/User/classes/class.ilObjUserFolder.php');
227  $amail = ilObjUserFolder::_lookupNewAccountMail($ilSetting->get("language"));
228  if (trim($amail["body"]) != "" && trim($amail["subject"]) != "")
229  {
230  include_once("Services/Mail/classes/class.ilAccountMail.php");
231  $acc_mail = new ilAccountMail();
232 
233  if ($pw != "")
234  {
235  $acc_mail->setUserPassword($pw);
236  }
237  $acc_mail->setUser($userObj);
238  $acc_mail->send();
239  }
240  }
241 
242  unset($userObj);
243  $a_auth->setAuth($local_user);
244  return true;
245  }
246 }
initClient()
Init soap client.
const IL_PASSWD_PLAIN
$_POST['username']
Definition: cron.php:12
$_GET["client_id"]
$valid
const IL_PASSWD_CRYPTED
loginObserver($a_username, $a_auth)
Called after login and successful call of fetch data.
static generatePasswords($a_number)
Generate a number of passwords.
fetchData($a_username, $a_password, $isChallengeResponse=false)
Call is isValidSession of soap server.
const AUTH_SOAP_NO_ILIAS_USER
_generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
[nu]soapclient higher level class for easy usage.
Definition: nusoap.php:7059
$new_user
global $ilSetting
Definition: privfeed.php:40
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
global $lng
Definition: privfeed.php:40
Class ilAccountMail.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
Authentication against external SOAP server