ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAuthProviderECS Class Reference

Auth prvider for ecs auth. More...

+ Inheritance diagram for ilAuthProviderECS:
+ Collaboration diagram for ilAuthProviderECS:

Public Member Functions

 __construct (\ilAuthCredentials $credentials)
 Constructor. More...
 
 getAbreviation ()
 get abbreviation More...
 
 getMID ()
 get mid More...
 
 setMID ($a_mid)
 
 setCurrentServer (ilECSSetting $server=null)
 Set current server. More...
 
 getCurrentServer ()
 Get current server. More...
 
 getServerSettings ()
 Get server settings. More...
 
 doAuthentication (\ilAuthStatus $status)
 Tra ecs authentication. More...
 
 handleLogin ()
 Called from base class after successful login. More...
 
 validateHash ()
 Validate ECS hash. More...
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 

Protected Member Functions

 createUser (ilECSUser $user)
 create new user More...
 
 updateUser (ilECSUser $user, $a_local_user_id)
 update existing user More...
 
 resetMailOptions ($a_usr_id)
 Reset mail options to "local only". More...
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, $a_reason)
 Handle failed authentication. More...
 

Protected Attributes

 $mid = null
 
 $abreviation = null
 
 $currentServer = null
 
 $servers = null
 

Private Member Functions

 initECSServices ()
 Init ECS Services private. More...
 

Additional Inherited Members

- Data Fields inherited from ilAuthProvider
const STATUS_UNDEFINED = 0
 
const STATUS_AUTHENTICATION_SUCCESS = 1
 
const STATUS_AUTHENTICATION_FAILED = 2
 
const STATUS_MIGRATION = 3
 

Detailed Description

Auth prvider for ecs auth.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e

Definition at line 14 of file class.ilAuthProviderECS.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderECS::__construct ( \ilAuthCredentials  $credentials)

Constructor.

Parameters
\ilAuthCredentials$credentials

Definition at line 27 of file class.ilAuthProviderECS.php.

References initECSServices().

28  {
29  parent::__construct($credentials);
30 
31  $this->initECSServices();
32  }
initECSServices()
Init ECS Services private.
+ Here is the call graph for this function:

Member Function Documentation

◆ createUser()

ilAuthProviderECS::createUser ( ilECSUser  $user)
protected

create new user

protected

Definition at line 278 of file class.ilAuthProviderECS.php.

References $ilLog, $ilSetting, ilAuthUtils\_generateLogin(), ilObject\_writeImportId(), getAbreviation(), getCurrentServer(), ilECSUser\getEmail(), ilECSUser\getFirstname(), ilECSUser\getImportId(), ilECSUser\getInstitution(), ilECSUser\getLastname(), ilAuthProvider\getLogger(), ilECSUser\getLogin(), IL_PASSWD_CRYPTED, resetMailOptions(), and time.

Referenced by handleLogin().

279  {
280  global $ilClientIniFile, $ilSetting, $rbacadmin, $ilLog;
281 
282  $userObj = new ilObjUser();
283  $userObj->setOwner(SYSTEM_USER_ID);
284 
285  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
286  $local_user = ilAuthUtils::_generateLogin($this->getAbreviation() . '_' . $user->getLogin());
287 
288  $newUser["login"] = $local_user;
289  $newUser["firstname"] = $user->getFirstname();
290  $newUser["lastname"] = $user->getLastname();
291  $newUser['email'] = $user->getEmail();
292  $newUser['institution'] = $user->getInstitution();
293 
294  // set "plain md5" password (= no valid password)
295  $newUser["passwd"] = "";
296  $newUser["passwd_type"] = IL_PASSWD_CRYPTED;
297 
298  $newUser["auth_mode"] = "ecs";
299  $newUser["profile_incomplete"] = 0;
300 
301  // system data
302  $userObj->assignData($newUser);
303  $userObj->setTitle($userObj->getFullname());
304  $userObj->setDescription($userObj->getEmail());
305 
306  // set user language to system language
307  $userObj->setLanguage($ilSetting->get("language"));
308 
309  // Time limit
310  $userObj->setTimeLimitOwner(7);
311  $userObj->setTimeLimitUnlimited(0);
312  $userObj->setTimeLimitFrom(time() - 5);
313  $userObj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session", "expire"));
314 
315  #$now = new ilDateTime(time(), IL_CAL_UNIX);
316  #$userObj->setAgreeDate($now->get(IL_CAL_DATETIME));
317 
318  // Create user in DB
319  $userObj->setOwner(6);
320  $userObj->create();
321  $userObj->setActive(1);
322  $userObj->updateOwner();
323  $userObj->saveAsNew();
324  $userObj->writePrefs();
325 
326  if($global_role = $this->getCurrentServer()->getGlobalRole())
327  {
328  $rbacadmin->assignUser($this->getCurrentServer()->getGlobalRole(), $userObj->getId(), true);
329  }
330  ilObject::_writeImportId($userObj->getId(), $user->getImportId());
331 
332  $this->getLogger()->info('Created new remote user with usr_id: ' . $user->getImportId());
333 
334  // Send Mail
335  #$this->sendNotification($userObj);
336  $this->resetMailOptions($userObj->getId());
337 
338  return $userObj->getLogin();
339  }
resetMailOptions($a_usr_id)
Reset mail options to "local only".
getFirstname()
get firstname
getCurrentServer()
Get current server.
const IL_PASSWD_CRYPTED
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
getAbreviation()
get abbreviation
getLastname()
getLastname
getLogger()
Get logger.
getEmail()
get email
getLogin()
get login
getImportId()
get Email
global $ilSetting
Definition: privfeed.php:17
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getInstitution()
get institution
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doAuthentication()

ilAuthProviderECS::doAuthentication ( \ilAuthStatus  $status)

Tra ecs authentication.

Parameters
\ilAuthStatus$status
Returns
boolean

Implements ilAuthProviderInterface.

Definition at line 94 of file class.ilAuthProviderECS.php.

References $server, ilAuthProvider\getLogger(), getServerSettings(), ilAuthProvider\handleAuthenticationFail(), handleLogin(), ilAuthStatus\setAuthenticatedUserId(), setCurrentServer(), ilAuthStatus\setStatus(), ilAuthStatus\STATUS_AUTHENTICATED, and validateHash().

95  {
96  $this->getLogger()->debug('Starting ECS authentication');
97  if(!$this->getServerSettings()->activeServerExists())
98  {
99  $this->getLogger()->warning('No active ecs server found. Aborting');
100  $this->handleAuthenticationFail($status, 'err_wrong_login');
101  return false;
102  }
103 
104  // Iterate through all active ecs instances
105  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
106  foreach($this->getServerSettings()->getServers() as $server)
107  {
108  $this->setCurrentServer($server);
109  if($this->validateHash())
110  {
111  // handle successful authentication
112  $new_usr_id = $this->handleLogin();
113  $this->getLogger()->info('ECS authentication successful.');
115  $status->setAuthenticatedUserId($new_usr_id);
116  return true;
117  }
118  }
119 
120  $this->getLogger()->warning('Could not validate ecs hash for any active server.');
121  $this->handleAuthenticationFail($status, 'err_wrong_login');
122  return false;
123  }
handleLogin()
Called from base class after successful login.
getServerSettings()
Get server settings.
setCurrentServer(ilECSSetting $server=null)
Set current server.
getLogger()
Get logger.
$server
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
validateHash()
Validate ECS hash.
+ Here is the call graph for this function:

◆ getAbreviation()

ilAuthProviderECS::getAbreviation ( )

get abbreviation

public

Parameters

Definition at line 41 of file class.ilAuthProviderECS.php.

References $abreviation.

Referenced by createUser().

42  {
43  return $this->abreviation;
44  }
+ Here is the caller graph for this function:

◆ getCurrentServer()

ilAuthProviderECS::getCurrentServer ( )

Get current server.

Returns
ilECSSetting

Definition at line 74 of file class.ilAuthProviderECS.php.

References $currentServer.

Referenced by createUser(), handleLogin(), updateUser(), and validateHash().

75  {
76  return $this->currentServer;
77  }
+ Here is the caller graph for this function:

◆ getMID()

ilAuthProviderECS::getMID ( )

get mid

public

Definition at line 51 of file class.ilAuthProviderECS.php.

References $mid.

Referenced by handleLogin().

52  {
53  return $this->mid;
54  }
+ Here is the caller graph for this function:

◆ getServerSettings()

ilAuthProviderECS::getServerSettings ( )

Get server settings.

Returns
ilECSServerSettings

Definition at line 83 of file class.ilAuthProviderECS.php.

References $servers.

Referenced by doAuthentication().

84  {
85  return $this->servers;
86  }
+ Here is the caller graph for this function:

◆ handleLogin()

ilAuthProviderECS::handleLogin ( )

Called from base class after successful login.

Parameters
stringusername

Definition at line 131 of file class.ilAuthProviderECS.php.

References $_GET, ilObjUser\_lookupId(), ilObject\_lookupObjIdByImportId(), createUser(), getCurrentServer(), ilAuthProvider\getLogger(), getMID(), and updateUser().

Referenced by doAuthentication().

132  {
133  include_once('./Services/WebServices/ECS/classes/class.ilECSUser.php');
134 
135  $user = new ilECSUser($_GET);
136 
137  if(!$usr_id = ilObject::_lookupObjIdByImportId($user->getImportId()))
138  {
139  $username = $this->createUser($user);
140  }
141  else
142  {
143  $username = $this->updateUser($user,$usr_id);
144  }
145 
146  // set user imported
147  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
148  $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
149  $import->save();
150 
151  // Store remote user data
152  include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
153  $remote = new ilECSRemoteUser();
154  $remote->setServerId($this->getCurrentServer()->getServerId());
155  $remote->setMid($this->getMID());
156  $remote->setRemoteUserId($user->getImportId());
157  $remote->setUserId(ilObjUser::_lookupId($username));
158 
159  $this->getLogger()->info('Current user is: ' . $username);
160 
161  if(!$remote->exists())
162  {
163  $remote->create();
164  }
165  return ilObjUser::_lookupId($username);
166  }
$_GET["client_id"]
getCurrentServer()
Get current server.
Storage of ecs remote user.
static _lookupId($a_user_str)
Lookup id by login.
createUser(ilECSUser $user)
create new user
Storage of ECS imported objects.
getLogger()
Get logger.
updateUser(ilECSUser $user, $a_local_user_id)
update existing user
Stores relevant user data.
static _lookupObjIdByImportId($a_import_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initECSServices()

ilAuthProviderECS::initECSServices ( )
private

Init ECS Services private.

Parameters

Definition at line 267 of file class.ilAuthProviderECS.php.

References ilECSServerSettings\getInstance().

Referenced by __construct().

268  {
269  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
270  $this->servers = ilECSServerSettings::getInstance();
271  }
static getInstance()
Get singleton instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resetMailOptions()

ilAuthProviderECS::resetMailOptions (   $a_usr_id)
protected

Reset mail options to "local only".

Definition at line 386 of file class.ilAuthProviderECS.php.

References $options, and IL_MAIL_LOCAL.

Referenced by createUser(), and updateUser().

387  {
388  include_once './Services/Mail/classes/class.ilMailOptions.php';
389  $options = new ilMailOptions($a_usr_id);
390  $options->updateOptions(
391  $options->getSignature(),
392  $options->getLinebreak(),
394  $options->getCronjobNotification()
395  );
396  }
Class UserMail this class handles user mails.
const IL_MAIL_LOCAL
if(!is_array($argv)) $options
+ Here is the caller graph for this function:

◆ setCurrentServer()

ilAuthProviderECS::setCurrentServer ( ilECSSetting  $server = null)

Set current server.

Parameters
ilECSSetting$server

Definition at line 65 of file class.ilAuthProviderECS.php.

References $server.

Referenced by doAuthentication().

66  {
67  $this->currentServer = $server;
68  }
$server
+ Here is the caller graph for this function:

◆ setMID()

ilAuthProviderECS::setMID (   $a_mid)

Definition at line 56 of file class.ilAuthProviderECS.php.

Referenced by validateHash().

57  {
58  $this->mid = $a_mid;
59  }
+ Here is the caller graph for this function:

◆ updateUser()

ilAuthProviderECS::updateUser ( ilECSUser  $user,
  $a_local_user_id 
)
protected

update existing user

protected

Definition at line 346 of file class.ilAuthProviderECS.php.

References $ilLog, getCurrentServer(), ilECSUser\getEmail(), ilECSUser\getFirstname(), ilECSUser\getImportId(), ilECSUser\getInstitution(), ilECSUser\getLastname(), ilAuthProvider\getLogger(), resetMailOptions(), and time.

Referenced by handleLogin().

347  {
348  global $ilClientIniFile,$ilLog,$rbacadmin;
349 
350  $user_obj = new ilObjUser($a_local_user_id);
351  $user_obj->setFirstname($user->getFirstname());
352  $user_obj->setLastname($user->getLastname());
353  $user_obj->setEmail($user->getEmail());
354  $user_obj->setInstitution($user->getInstitution());
355  $user_obj->setActive(true);
356 
357  $until = $user_obj->getTimeLimitUntil();
358 
359  if($until < (time() + $ilClientIniFile->readVariable('session','expire')))
360  {
361  $user_obj->setTimeLimitFrom(time() - 60);
362  $user_obj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session","expire"));
363  }
364  $user_obj->update();
365  $user_obj->refreshLogin();
366 
367  if($global_role = $this->getCurrentServer()->getGlobalRole())
368  {
369  $rbacadmin->assignUser(
370  $this->getCurrentServer()->getGlobalRole(),
371  $user_obj->getId(),
372  true
373  );
374  }
375 
376  $this->resetMailOptions($a_local_user_id);
377 
378  $this->getLogger()->debug('Finished update of remote user with usr_id: ' . $user->getImportId());
379  return $user_obj->getLogin();
380  }
resetMailOptions($a_usr_id)
Reset mail options to "local only".
getFirstname()
get firstname
getCurrentServer()
Get current server.
getLastname()
getLastname
getLogger()
Get logger.
getEmail()
get email
getImportId()
get Email
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
getInstitution()
get institution
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateHash()

ilAuthProviderECS::validateHash ( )

Validate ECS hash.

public

Parameters
stringusername
stringpass

Definition at line 177 of file class.ilAuthProviderECS.php.

References $_GET, $ilLog, $reader, $res, ilLogLevel\DEBUG, getCurrentServer(), ilECSCommunityReader\getInstanceByServerId(), ilAuthProvider\getLogger(), and setMID().

Referenced by doAuthentication().

178  {
179  global $ilLog;
180 
181  // fetch hash
182  if(isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash']))
183  {
184  $hash = $_GET['ecs_hash'];
185  }
186  if(isset($_GET['ecs_hash_url']))
187  {
188  $hashurl = urldecode($_GET['ecs_hash_url']);
189  $hash = basename(parse_url($hashurl,PHP_URL_PATH));
190  //$hash = urldecode($_GET['ecs_hash_url']);
191  }
192 
193  $this->getLogger()->info('Using ecs hash: ' . $hash);
194  // Check if hash is valid ...
195  try
196  {
197  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
198  $connector = new ilECSConnector($this->getCurrentServer());
199  $res = $connector->getAuth($hash);
200  $auths = $res->getResult();
201 
202  $this->getLogger()->dump($auths, ilLogLevel::DEBUG);
203 
204  if($auths->pid)
205  {
206  try
207  {
208  include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
210  $part = $reader->getParticipantByMID($auths->pid);
211 
212  if(is_object($part) and is_object($part->getOrganisation()))
213  {
214  $this->abreviation = $part->getOrganisation()->getAbbreviation();
215  }
216  else
217  {
218  $this->abreviation = $auths->abbr;
219  }
220  }
221  catch(Exception $e)
222  {
223  $this->getLogger()->warning('Authentication failed with message: ' . $e->getMessage());
224  return false;
225  }
226  }
227  else
228  {
229  $this->abreviation = $auths->abbr;
230  }
231 
232  $this->getLogger()->debug('Got abbreviation: ' . $this->abreviation);
233  }
234  catch(ilECSConnectorException $e)
235  {
236  $this->getLogger()->warning('Authentication failed with message: ' . $e->getMessage());
237  return false;
238  }
239 
240  // read current mid
241  try
242  {
243  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
244  $connector = new ilECSConnector($this->getCurrentServer());
245  $details = $connector->getAuth($hash,TRUE);
246 
247  $this->getLogger()->dump($details, ilLogLevel::DEBUG);
248  $this->getLogger()->debug('Token create for mid: ' . $details->getFirstSender());
249 
250  $this->setMID($details->getFirstSender());
251  }
252  catch(ilECSConnectorException $e)
253  {
254  $this->getLogger()->warning('Receiving mid failed with message: ' . $e->getMessage());
255  return false;
256  }
257  return true;
258  }
$_GET["client_id"]
getCurrentServer()
Get current server.
static getInstanceByServerId($a_server_id)
Get instance by server id.
getLogger()
Get logger.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $abreviation

ilAuthProviderECS::$abreviation = null
protected

Definition at line 17 of file class.ilAuthProviderECS.php.

Referenced by getAbreviation().

◆ $currentServer

ilAuthProviderECS::$currentServer = null
protected

Definition at line 19 of file class.ilAuthProviderECS.php.

Referenced by getCurrentServer().

◆ $mid

ilAuthProviderECS::$mid = null
protected

Definition at line 16 of file class.ilAuthProviderECS.php.

Referenced by getMID().

◆ $servers

ilAuthProviderECS::$servers = null
protected

Definition at line 20 of file class.ilAuthProviderECS.php.

Referenced by getServerSettings().


The documentation for this class was generated from the following file: