ILIAS  release_4-4 Revision
ilAuthContainerECS Class Reference

Custom PEAR Auth Container for ECS auth checks. More...

+ Inheritance diagram for ilAuthContainerECS:
+ Collaboration diagram for ilAuthContainerECS:

Public Member Functions

 __construct ($a_params=array())
 Constructor. More...
 
 getAbreviation ()
 get abbreviation More...
 
 getMID ()
 get mid More...
 
 setCurrentServer (ilECSSetting $server=null)
 Set current server. More...
 
 getCurrentServer ()
 Get current server. More...
 
 getServerSettings ()
 Get server settings. More...
 
 fetchData ($a_username, $a_pass)
 Check for valid ecs_hash. More...
 
 validateHash ()
 Validate ECS hash. More...
 
 loginObserver ($a_username, $a_auth)
 Called from base class after successful login. More...
 
 failedLoginObserver ()
 Called from base class after failed login. More...
 
- Public Member Functions inherited from Auth_Container
 Auth_Container ()
 Constructor. More...
 
 fetchData ($username, $password, $isChallengeResponse=false)
 Fetch data from storage container. More...
 
 verifyPassword ($password1, $password2, $cryptType="md5")
 Crypt and verfiy the entered password. More...
 
 supportsChallengeResponse ()
 Returns true if the container supports Challenge Response password authentication. More...
 
 getCryptType ()
 Returns the crypt current crypt type of the container. More...
 
 listUsers ()
 List all users that are available from the storage container. More...
 
 getUser ($username)
 Returns a user assoc array. More...
 
 addUser ($username, $password, $additional=null)
 Add a new user to the storage container. More...
 
 removeUser ($username)
 Remove user from the storage container. More...
 
 changePassword ($username, $password)
 Change password for user in the storage container. More...
 
 log ($message, $level=AUTH_LOG_DEBUG)
 Log a message to the Auth log. More...
 
- Public Member Functions inherited from ilAuthContainerBase
 loginObserver ($a_username, $a_auth)
 Called after successful login. More...
 
 failedLoginObserver ($a_username, $a_auth)
 Called after failed login. More...
 
 checkAuthObserver ($a_username, $a_auth)
 Called after check auth requests. More...
 
 logoutObserver ($a_username, $a_auth)
 Called after logout. More...
 
 supportsCaptchaVerification ()
 Returns whether or not the auth container supports the verification of captchas This should be true for those auth methods, which are available in the default login form. More...
 

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 Attributes

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

Private Member Functions

 initECSServices ()
 Init ECS Services private. More...
 
 sendNotification ($user_obj)
 Send notification. More...
 

Additional Inherited Members

- Data Fields inherited from Auth_Container
 $activeUser = ""
 User that is currently selected from the storage container. More...
 
 $_auth_obj = null
 The Auth object this container is attached to. More...
 

Detailed Description

Custom PEAR Auth Container for ECS auth checks.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 34 of file class.ilAuthContainerECS.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthContainerECS::__construct (   $a_params = array())

Constructor.

public

Parameters

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

References $GLOBALS, initECSServices(), and Auth_Container\log().

52  {
53  parent::__construct($a_params);
54 
55  $this->initECSServices();
56 
57  $this->log = $GLOBALS['ilLog'];
58  }
$GLOBALS['ct_recipient']
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
initECSServices()
Init ECS Services private.
+ Here is the call graph for this function:

Member Function Documentation

◆ createUser()

ilAuthContainerECS::createUser ( ilECSUser  $user)
protected

create new user

protected

Definition at line 234 of file class.ilAuthContainerECS.php.

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

Referenced by loginObserver().

235  {
236  global $ilClientIniFile, $ilSetting, $rbacadmin, $ilLog;
237 
238  $userObj = new ilObjUser();
239 
240  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
241  $local_user = ilAuthUtils::_generateLogin($this->getAbreviation() . '_' . $user->getLogin());
242 
243  $newUser["login"] = $local_user;
244  $newUser["firstname"] = $user->getFirstname();
245  $newUser["lastname"] = $user->getLastname();
246  $newUser['email'] = $user->getEmail();
247  $newUser['institution'] = $user->getInstitution();
248 
249  // set "plain md5" password (= no valid password)
250  $newUser["passwd"] = "";
251  $newUser["passwd_type"] = IL_PASSWD_MD5;
252 
253  $newUser["auth_mode"] = "ecs";
254  $newUser["profile_incomplete"] = 0;
255 
256  // system data
257  $userObj->assignData($newUser);
258  $userObj->setTitle($userObj->getFullname());
259  $userObj->setDescription($userObj->getEmail());
260 
261  // set user language to system language
262  $userObj->setLanguage($ilSetting->get("language"));
263 
264  // Time limit
265  $userObj->setTimeLimitOwner(7);
266  $userObj->setTimeLimitUnlimited(0);
267  $userObj->setTimeLimitFrom(time() - 5);
268  $userObj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session", "expire"));
269 
270  #$now = new ilDateTime(time(), IL_CAL_UNIX);
271  #$userObj->setAgreeDate($now->get(IL_CAL_DATETIME));
272 
273  // Create user in DB
274  $userObj->setOwner(6);
275  $userObj->create();
276  $userObj->setActive(1);
277  $userObj->updateOwner();
278  $userObj->saveAsNew();
279  $userObj->writePrefs();
280 
281  if($global_role = $this->getCurrentServer()->getGlobalRole())
282  {
283  $rbacadmin->assignUser($this->getCurrentServer()->getGlobalRole(), $userObj->getId(), true);
284  }
285  ilObject::_writeImportId($userObj->getId(), $user->getImportId());
286 
287  $ilLog->write(__METHOD__ . ': Created new remote user with usr_id: ' . $user->getImportId());
288 
289  // Send Mail
290  #$this->sendNotification($userObj);
291  $this->resetMailOptions($userObj->getId());
292 
293  return $userObj->getLogin();
294  }
getFirstname()
get firstname
getAbreviation()
get abbreviation
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
getLastname()
getLastname
_generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
getCurrentServer()
Get current server.
getEmail()
get email
getLogin()
get login
resetMailOptions($a_usr_id)
Reset mail options to "local only".
const IL_PASSWD_MD5
getImportId()
get Email
global $ilSetting
Definition: privfeed.php:40
getInstitution()
get institution
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ failedLoginObserver()

ilAuthContainerECS::failedLoginObserver ( )

Called from base class after failed login.

Parameters
stringusername

Definition at line 221 of file class.ilAuthContainerECS.php.

References Auth_Container\log().

222  {
223  $this->log->write(__METHOD__.': Login failed');
224  return false;
225  }
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
+ Here is the call graph for this function:

◆ fetchData()

ilAuthContainerECS::fetchData (   $a_username,
  $a_pass 
)

Check for valid ecs_hash.

Parameters
string$a_username
string$a_pass

Definition at line 114 of file class.ilAuthContainerECS.php.

References $GLOBALS, $ilLog, $server, getServerSettings(), setCurrentServer(), and validateHash().

115  {
116  global $ilLog;
117 
118  $ilLog->write(__METHOD__.': Starting ECS authentication.');
119 
120  if(!$this->getServerSettings()->activeServerExists())
121  {
122  $GLOBALS['ilLog']->write(__METHOD__.': no active ecs server found. Aborting');
123  return false;
124  }
125 
126  // Iterate through all active ecs instances
127  include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
128  foreach($this->getServerSettings()->getServers() as $server)
129  {
130  $this->setCurrentServer($server);
131  if($this->validateHash())
132  {
133  return true;
134  }
135  }
136  $GLOBALS['ilLog']->write(__METHOD__.': Could not validate ecs hash for any server');
137  return false;
138 
139  }
getServerSettings()
Get server settings.
$GLOBALS['ct_recipient']
$server
setCurrentServer(ilECSSetting $server=null)
Set current server.
validateHash()
Validate ECS hash.
+ Here is the call graph for this function:

◆ getAbreviation()

ilAuthContainerECS::getAbreviation ( )

get abbreviation

public

Parameters

Definition at line 67 of file class.ilAuthContainerECS.php.

References $abreviation.

Referenced by createUser().

+ Here is the caller graph for this function:

◆ getCurrentServer()

ilAuthContainerECS::getCurrentServer ( )

Get current server.

Returns
ilECSSetting

Definition at line 95 of file class.ilAuthContainerECS.php.

References $currentServer.

Referenced by createUser(), loginObserver(), sendNotification(), updateUser(), and validateHash().

+ Here is the caller graph for this function:

◆ getMID()

ilAuthContainerECS::getMID ( )

get mid

public

Definition at line 77 of file class.ilAuthContainerECS.php.

References $mid.

78  {
79  return $this->mid;
80  }

◆ getServerSettings()

ilAuthContainerECS::getServerSettings ( )

Get server settings.

Returns
ilECSServerSettings

Definition at line 104 of file class.ilAuthContainerECS.php.

References $servers.

Referenced by fetchData().

105  {
106  return $this->servers;
107  }
+ Here is the caller graph for this function:

◆ initECSServices()

ilAuthContainerECS::initECSServices ( )
private

Init ECS Services private.

Parameters

Definition at line 360 of file class.ilAuthContainerECS.php.

References ilECSServerSettings\getInstance().

Referenced by __construct().

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

◆ loginObserver()

ilAuthContainerECS::loginObserver (   $a_username,
  $a_auth 
)

Called from base class after successful login.

Parameters
stringusername

Definition at line 191 of file class.ilAuthContainerECS.php.

References $_GET, $usr_id, ilObject\_lookupObjIdByImportId(), createUser(), getCurrentServer(), Auth_Container\log(), and updateUser().

192  {
193  include_once('./Services/WebServices/ECS/classes/class.ilECSUser.php');
194 
195  $user = new ilECSUser($_GET);
196 
197  if(!$usr_id = ilObject::_lookupObjIdByImportId($user->getImportId()))
198  {
199  $username = $this->createUser($user);
200  }
201  else
202  {
203  $username = $this->updateUser($user,$usr_id);
204  }
205 
206  // set user imported
207  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
208  $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
209  $import->save();
210 
211  $a_auth->setAuth($username);
212  $this->log->write(__METHOD__.': Login succesesful');
213  return true;
214  }
updateUser(ilECSUser $user, $a_local_user_id)
update existing user
$_GET["client_id"]
createUser(ilECSUser $user)
create new user
getCurrentServer()
Get current server.
Storage of ECS imported objects.
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
Stores relevant user data.
static _lookupObjIdByImportId($a_import_id)
+ Here is the call graph for this function:

◆ resetMailOptions()

ilAuthContainerECS::resetMailOptions (   $a_usr_id)
protected

Reset mail options to "local only".

Definition at line 341 of file class.ilAuthContainerECS.php.

References $options, and IL_MAIL_LOCAL.

Referenced by createUser(), and updateUser().

342  {
343  include_once './Services/Mail/classes/class.ilMailOptions.php';
344  $options = new ilMailOptions($a_usr_id);
345  $options->updateOptions(
346  $options->getSignature(),
347  $options->getLinebreak(),
349  $options->getCronjobNotification()
350  );
351  }
Class UserMail this class handles user mails.
const IL_MAIL_LOCAL
if(!is_array($argv)) $options
+ Here is the caller graph for this function:

◆ sendNotification()

ilAuthContainerECS::sendNotification (   $user_obj)
private

Send notification.

private

Parameters

Definition at line 373 of file class.ilAuthContainerECS.php.

References $GLOBALS, $lang, ilMail\_getAutoGeneratedMessageString(), ilLanguageFactory\_getLanguage(), and getCurrentServer().

374  {
375  if(!count($this->getCurrentServer()->getUserRecipients()))
376  {
377  return true;
378  }
379 
380  include_once('./Services/Language/classes/class.ilLanguageFactory.php');
381  include_once './Services/Language/classes/class.ilLanguage.php';
383  $GLOBALS['lng'] = $lang;
384  $GLOBALS['ilUser'] = $user_obj;
385  $lang->loadLanguageModule('ecs');
386 
387  include_once('./Services/Mail/classes/class.ilMail.php');
388  $mail = new ilMail(6);
389  $mail->enableSoap(false);
390  $subject = $lang->txt('ecs_new_user_subject');
391 
392  // build body
393  $body = $lang->txt('ecs_new_user_body')."\n\n";
394  $body .= $lang->txt('ecs_new_user_profile')."\n\n";
395  $body .= $user_obj->getProfileAsString($lang)."\n\n";
397 
398  $mail->sendMail(
399  $this->getCurrentServer()->getUserRecipientsAsString(),
400  "",
401  "",
402  $subject,
403  $body,
404  array(),
405  array("normal")
406  );
407  }
static _getLanguage($a_lang_key='')
Get langauge object.
$GLOBALS['ct_recipient']
Class Mail this class handles base functions for mail handling.
getCurrentServer()
Get current server.
static _getAutoGeneratedMessageString($lang=null)
get auto generated info string
+ Here is the call graph for this function:

◆ setCurrentServer()

ilAuthContainerECS::setCurrentServer ( ilECSSetting  $server = null)

Set current server.

Parameters
ilECSSetting$server

Definition at line 86 of file class.ilAuthContainerECS.php.

References $server.

Referenced by fetchData().

87  {
88  $this->currentServer = $server;
89  }
$server
+ Here is the caller graph for this function:

◆ updateUser()

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

update existing user

protected

Definition at line 301 of file class.ilAuthContainerECS.php.

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

Referenced by loginObserver().

302  {
303  global $ilClientIniFile,$ilLog,$rbacadmin;
304 
305  $user_obj = new ilObjUser($a_local_user_id);
306  $user_obj->setFirstname($user->getFirstname());
307  $user_obj->setLastname($user->getLastname());
308  $user_obj->setEmail($user->getEmail());
309  $user_obj->setInstitution($user->getInstitution());
310  $user_obj->setActive(true);
311 
312  $until = $user_obj->getTimeLimitUntil();
313 
314  if($until < (time() + $ilClientIniFile->readVariable('session','expire')))
315  {
316  $user_obj->setTimeLimitFrom(time() - 60);
317  $user_obj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session","expire"));
318  }
319  $user_obj->update();
320  $user_obj->refreshLogin();
321 
322  if($global_role = $this->getCurrentServer()->getGlobalRole())
323  {
324  $rbacadmin->assignUser(
325  $this->getCurrentServer()->getGlobalRole(),
326  $user_obj->getId(),
327  true
328  );
329  }
330 
331  $this->resetMailOptions($a_local_user_id);
332 
333  $ilLog->write(__METHOD__.': Finished update of remote user with usr_id: '.$user->getImportId());
334  return $user_obj->getLogin();
335  }
getFirstname()
get firstname
getLastname()
getLastname
getCurrentServer()
Get current server.
getEmail()
get email
resetMailOptions($a_usr_id)
Reset mail options to "local only".
getImportId()
get Email
getInstitution()
get institution
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateHash()

ilAuthContainerECS::validateHash ( )

Validate ECS hash.

public

Parameters
stringusername
stringpass

Definition at line 150 of file class.ilAuthContainerECS.php.

References $_GET, $GLOBALS, $ilLog, $res, and getCurrentServer().

Referenced by fetchData().

151  {
152  global $ilLog;
153 
154  // fetch hash
155  if(isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash']))
156  {
157  $hash = $_GET['ecs_hash'];
158  }
159  if(isset($_GET['ecs_hash_url']))
160  {
161  $hashurl = urldecode($_GET['ecs_hash_url']);
162  $hash = basename(parse_url($hashurl,PHP_URL_PATH));
163  //$hash = urldecode($_GET['ecs_hash_url']);
164  }
165 
166  $GLOBALS['ilLog']->write(__METHOD__.': Using ecs hash '. $hash);
167 
168  // Check if hash is valid ...
169  try
170  {
171  include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
172  $connector = new ilECSConnector($this->getCurrentServer());
173  $res = $connector->getAuth($hash);
174  $auths = $res->getResult();
175  $this->abreviation = $auths->abbr;
176  $ilLog->write(__METHOD__.': Got abr: '.$this->abreviation);
177  return true;
178  }
179  catch(ilECSConnectorException $e)
180  {
181  $ilLog->write(__METHOD__.': Authentication failed with message: '.$e->getMessage());
182  return false;
183  }
184  }
$_GET["client_id"]
$GLOBALS['ct_recipient']
getCurrentServer()
Get current server.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $abreviation

ilAuthContainerECS::$abreviation = null
protected

Definition at line 37 of file class.ilAuthContainerECS.php.

Referenced by getAbreviation().

◆ $currentServer

ilAuthContainerECS::$currentServer = null
protected

Definition at line 39 of file class.ilAuthContainerECS.php.

Referenced by getCurrentServer().

◆ $log

ilAuthContainerECS::$log
protected

Definition at line 42 of file class.ilAuthContainerECS.php.

◆ $mid

ilAuthContainerECS::$mid = null
protected

Definition at line 36 of file class.ilAuthContainerECS.php.

Referenced by getMID().

◆ $servers

ilAuthContainerECS::$servers = null
protected

Definition at line 40 of file class.ilAuthContainerECS.php.

Referenced by getServerSettings().


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