ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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...
 
 setMID ($a_mid)
 
 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 @access 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.

@access public

Parameters

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

52 {
53 parent::__construct($a_params);
54
55 $this->initECSServices();
56
57 $this->log = $GLOBALS['ilLog'];
58 }
log($message, $level=AUTH_LOG_DEBUG)
Log a message to the Auth log.
Definition: Container.php:246
initECSServices()
Init ECS Services @access private.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276

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

+ Here is the call graph for this function:

Member Function Documentation

◆ createUser()

ilAuthContainerECS::createUser ( ilECSUser  $user)
protected

create new user

@access protected

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

303 {
304 global $ilClientIniFile, $ilSetting, $rbacadmin, $ilLog;
305
306 $userObj = new ilObjUser();
307
308 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
309 $local_user = ilAuthUtils::_generateLogin($this->getAbreviation() . '_' . $user->getLogin());
310
311 $newUser["login"] = $local_user;
312 $newUser["firstname"] = $user->getFirstname();
313 $newUser["lastname"] = $user->getLastname();
314 $newUser['email'] = $user->getEmail();
315 $newUser['institution'] = $user->getInstitution();
316
317 // set "plain md5" password (= no valid password)
318 $newUser["passwd"] = "";
319 $newUser["passwd_type"] = IL_PASSWD_CRYPTED;
320
321 $newUser["auth_mode"] = "ecs";
322 $newUser["profile_incomplete"] = 0;
323
324 // system data
325 $userObj->assignData($newUser);
326 $userObj->setTitle($userObj->getFullname());
327 $userObj->setDescription($userObj->getEmail());
328
329 // set user language to system language
330 $userObj->setLanguage($ilSetting->get("language"));
331
332 // Time limit
333 $userObj->setTimeLimitOwner(7);
334 $userObj->setTimeLimitUnlimited(0);
335 $userObj->setTimeLimitFrom(time() - 5);
336 $userObj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session", "expire"));
337
338 #$now = new ilDateTime(time(), IL_CAL_UNIX);
339 #$userObj->setAgreeDate($now->get(IL_CAL_DATETIME));
340
341 // Create user in DB
342 $userObj->setOwner(6);
343 $userObj->create();
344 $userObj->setActive(1);
345 $userObj->updateOwner();
346 $userObj->saveAsNew();
347 $userObj->writePrefs();
348
349 if($global_role = $this->getCurrentServer()->getGlobalRole())
350 {
351 $rbacadmin->assignUser($this->getCurrentServer()->getGlobalRole(), $userObj->getId(), true);
352 }
353 ilObject::_writeImportId($userObj->getId(), $user->getImportId());
354
355 $ilLog->write(__METHOD__ . ': Created new remote user with usr_id: ' . $user->getImportId());
356
357 // Send Mail
358 #$this->sendNotification($userObj);
359 $this->resetMailOptions($userObj->getId());
360
361 return $userObj->getLogin();
362 }
const IL_PASSWD_CRYPTED
resetMailOptions($a_usr_id)
Reset mail options to "local only".
getCurrentServer()
Get current server.
getAbreviation()
get abbreviation
_generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
getFirstname()
get firstname
getLastname()
getLastname
getLogin()
get login
getImportId()
get Email
getEmail()
get email
getInstitution()
get institution
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
global $ilSetting
Definition: privfeed.php:40

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

Referenced by loginObserver().

+ 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 289 of file class.ilAuthContainerECS.php.

290 {
291 $this->log->write(__METHOD__.': Login failed');
292 return false;
293 }

References Auth_Container\log().

+ 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 119 of file class.ilAuthContainerECS.php.

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

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

+ Here is the call graph for this function:

◆ getAbreviation()

ilAuthContainerECS::getAbreviation ( )

get abbreviation

@access 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 100 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

@access public

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

References $mid.

Referenced by loginObserver().

+ Here is the caller graph for this function:

◆ getServerSettings()

ilAuthContainerECS::getServerSettings ( )

Get server settings.

Returns
ilECSServerSettings

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

References $servers.

Referenced by fetchData().

+ Here is the caller graph for this function:

◆ initECSServices()

ilAuthContainerECS::initECSServices ( )
private

Init ECS Services @access private.

Parameters

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

429 {
430 include_once './Services/WebServices/ECS/classes/class.ilECSServerSettings.php';
431 $this->servers = ilECSServerSettings::getInstance();
432 }
static getInstance()
Get singleton instance.

References ilECSServerSettings\getInstance().

Referenced by __construct().

+ 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

Reimplemented from ilAuthContainerBase.

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

245 {
246 include_once('./Services/WebServices/ECS/classes/class.ilECSUser.php');
247
248 $user = new ilECSUser($_GET);
249
250 if(!$usr_id = ilObject::_lookupObjIdByImportId($user->getImportId()))
251 {
252 $username = $this->createUser($user);
253 }
254 else
255 {
256 $username = $this->updateUser($user,$usr_id);
257 }
258
259 // set user imported
260 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
261 $import = new ilECSImport($this->getCurrentServer()->getServerId(), $usr_id);
262 $import->save();
263
264 // Store remote user data
265 include_once './Services/WebServices/ECS/classes/class.ilECSRemoteUser.php';
266 $remote = new ilECSRemoteUser();
267 $remote->setServerId($this->getCurrentServer()->getServerId());
268 $remote->setMid($this->getMID());
269 $remote->setRemoteUserId($user->getImportId());
270 $remote->setUserId(ilObjUser::_lookupId($username));
271
272 $GLOBALS['ilLog']->write(__METHOD__.': Current username '.$username);
273
274 if(!$remote->exists())
275 {
276 $remote->create();
277 }
278
279 $a_auth->setAuth($username);
280 $this->log->write(__METHOD__.': Login succesesful');
281 return true;
282 }
$_GET["client_id"]
createUser(ilECSUser $user)
create new user
updateUser(ilECSUser $user, $a_local_user_id)
update existing user
Storage of ECS imported objects.
Storage of ecs remote user.
Stores relevant user data.
static _lookupId($a_user_str)
Lookup id by login.
static _lookupObjIdByImportId($a_import_id)

References $_GET, $GLOBALS, ilObjUser\_lookupId(), ilObject\_lookupObjIdByImportId(), createUser(), getCurrentServer(), getMID(), Auth_Container\log(), and updateUser().

+ Here is the call graph for this function:

◆ resetMailOptions()

ilAuthContainerECS::resetMailOptions (   $a_usr_id)
protected

Reset mail options to "local only".

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

410 {
411 include_once './Services/Mail/classes/class.ilMailOptions.php';
412 $options = new ilMailOptions($a_usr_id);
413 $options->updateOptions(
414 $options->getSignature(),
415 $options->getLinebreak(),
417 $options->getCronjobNotification()
418 );
419 }
const IL_MAIL_LOCAL
Class UserMail this class handles user mails.
if(!is_array($argv)) $options

References $options, and IL_MAIL_LOCAL.

Referenced by createUser(), and updateUser().

+ Here is the caller graph for this function:

◆ sendNotification()

ilAuthContainerECS::sendNotification (   $user_obj)
private

Send notification.

@access private

Parameters

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

442 {
443 if(!count($this->getCurrentServer()->getUserRecipients()))
444 {
445 return true;
446 }
447
448 include_once('./Services/Language/classes/class.ilLanguageFactory.php');
449 include_once './Services/Language/classes/class.ilLanguage.php';
451 $GLOBALS['lng'] = $lang;
452 $GLOBALS['ilUser'] = $user_obj;
453 $lang->loadLanguageModule('ecs');
454
455 include_once('./Services/Mail/classes/class.ilMail.php');
456 $mail = new ilMail(6);
457 $mail->enableSoap(false);
458 $subject = $lang->txt('ecs_new_user_subject');
459
460 // build body
461 $body = $lang->txt('ecs_new_user_body')."\n\n";
462 $body .= $lang->txt('ecs_new_user_profile')."\n\n";
463 $body .= $user_obj->getProfileAsString($lang)."\n\n";
465
466 $mail->sendMail(
467 $this->getCurrentServer()->getUserRecipientsAsString(),
468 "",
469 "",
470 $subject,
471 $body,
472 array(),
473 array("normal")
474 );
475 }
static _getLanguage($a_lang_key='')
Get langauge object.
Class Mail this class handles base functions for mail handling.
static _getAutoGeneratedMessageString($lang=null)
get auto generated info string

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

+ Here is the call graph for this function:

◆ setCurrentServer()

ilAuthContainerECS::setCurrentServer ( ilECSSetting  $server = null)

Set current server.

Parameters
ilECSSetting$server

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

92 {
93 $this->currentServer = $server;
94 }

References $server.

Referenced by fetchData().

+ Here is the caller graph for this function:

◆ setMID()

ilAuthContainerECS::setMID (   $a_mid)

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

83 {
84 $this->mid = $a_mid;
85 }

Referenced by validateHash().

+ Here is the caller graph for this function:

◆ updateUser()

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

update existing user

@access protected

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

370 {
371 global $ilClientIniFile,$ilLog,$rbacadmin;
372
373 $user_obj = new ilObjUser($a_local_user_id);
374 $user_obj->setFirstname($user->getFirstname());
375 $user_obj->setLastname($user->getLastname());
376 $user_obj->setEmail($user->getEmail());
377 $user_obj->setInstitution($user->getInstitution());
378 $user_obj->setActive(true);
379
380 $until = $user_obj->getTimeLimitUntil();
381
382 if($until < (time() + $ilClientIniFile->readVariable('session','expire')))
383 {
384 $user_obj->setTimeLimitFrom(time() - 60);
385 $user_obj->setTimeLimitUntil(time() + $ilClientIniFile->readVariable("session","expire"));
386 }
387 $user_obj->update();
388 $user_obj->refreshLogin();
389
390 if($global_role = $this->getCurrentServer()->getGlobalRole())
391 {
392 $rbacadmin->assignUser(
393 $this->getCurrentServer()->getGlobalRole(),
394 $user_obj->getId(),
395 true
396 );
397 }
398
399 $this->resetMailOptions($a_local_user_id);
400
401 $ilLog->write(__METHOD__.': Finished update of remote user with usr_id: '.$user->getImportId());
402 return $user_obj->getLogin();
403 }

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

Referenced by loginObserver().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateHash()

ilAuthContainerECS::validateHash ( )

Validate ECS hash.

@access public

Parameters
stringusername
stringpass

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

156 {
157 global $ilLog;
158
159 // fetch hash
160 if(isset($_GET['ecs_hash']) and strlen($_GET['ecs_hash']))
161 {
162 $hash = $_GET['ecs_hash'];
163 }
164 if(isset($_GET['ecs_hash_url']))
165 {
166 $hashurl = urldecode($_GET['ecs_hash_url']);
167 $hash = basename(parse_url($hashurl,PHP_URL_PATH));
168 //$hash = urldecode($_GET['ecs_hash_url']);
169 }
170
171 $GLOBALS['ilLog']->write(__METHOD__.': Using ecs hash '. $hash);
172
173 // Check if hash is valid ...
174 try
175 {
176 include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
177 $connector = new ilECSConnector($this->getCurrentServer());
178 $res = $connector->getAuth($hash);
179 $auths = $res->getResult();
180
181 $GLOBALS['ilLog']->write(__METHOD__.': Auths: '.print_r($auths,TRUE));
182
183 if($auths->pid)
184 {
185 try
186 {
187 include_once './Services/WebServices/ECS/classes/class.ilECSCommunityReader.php';
189 $part = $reader->getParticipantByMID($auths->pid);
190
191 if(is_object($part) and is_object($part->getOrganisation()))
192 {
193 $this->abreviation = $part->getOrganisation()->getAbbreviation();
194 }
195 else
196 {
197 $this->abreviation = $auths->abbr;
198 }
199 }
200 catch(Exception $e)
201 {
202 $ilLog->write(__METHOD__.': Authentication failed with message: '.$e->getMessage());
203 return false;
204 }
205 }
206 else
207 {
208 $this->abreviation = $auths->abbr;
209 }
210
211 $ilLog->write(__METHOD__.': Got abr: '.$this->abreviation);
212 }
214 {
215 $ilLog->write(__METHOD__.': Authentication failed with message: '.$e->getMessage());
216 return false;
217 }
218
219 // read current mid
220 try
221 {
222 include_once('./Services/WebServices/ECS/classes/class.ilECSConnector.php');
223 $connector = new ilECSConnector($this->getCurrentServer());
224 $details = $connector->getAuth($hash,TRUE);
225
226 $GLOBALS['ilLog']->write(__METHOD__.': '.print_r($details,TRUE));
227 $GLOBALS['ilLog']->write(__METHOD__.': Token created for mid '. $details->getFirstSender());
228
229 $this->setMID($details->getFirstSender());
230 }
232 {
233 $ilLog->write(__METHOD__.': Receiving mid failed with message: '.$e->getMessage());
234 return false;
235 }
236 return TRUE;
237 }
static getInstanceByServerId($a_server_id)
Get instance by server id.

References $_GET, $GLOBALS, $ilLog, $reader, $res, getCurrentServer(), ilECSCommunityReader\getInstanceByServerId(), and setMID().

Referenced by fetchData().

+ 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: