ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilLDAPAttributeToUser Class Reference

Update/create ILIAS user account by given LDAP attributes according to user attribute mapping settings. More...

+ Collaboration diagram for ilLDAPAttributeToUser:

Public Member Functions

 __construct (ilLDAPServer $a_server)
 Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes. More...
 
 getServer ()
 Get server settings. More...
 
 setUserData ($a_data)
 Set user data received from pear auth or by ldap_search. More...
 
 setNewUserAuthMode ($a_authmode)
 Set auth mode for new users. More...
 
 getNewUserAuthMode ()
 Get auth mode for new users. More...
 
 refresh ()
 Create/Update non existing users. More...
 

Private Member Functions

 usersToXML ()
 Create xml string of user according to mapping rules. More...
 
 convertInput ($a_value)
 A value can be an array or a string This function converts arrays to strings. More...
 
 doMapping ($user, $rule)
 doMapping More...
 
 initLDAPAttributeMapping ()
 
 initUserDefinedFields ()
 

Private Attributes

 $server_settings = null
 
 $role_assignment = null
 
 $db = null
 
 $user_data = array()
 
 $setting = null
 
 $mapping = null
 
 $new_user_auth_mode = 'ldap'
 

Detailed Description

Update/create ILIAS user account by given LDAP attributes according to user attribute mapping settings.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilLDAPAttributeToUser::__construct ( ilLDAPServer  $a_server)

Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.

Parameters
objectil

Definition at line 52 of file class.ilLDAPAttributeToUser.php.

References $ilDB, $ilLog, $ilSetting, $lng, and initLDAPAttributeMapping().

53  {
54  global $ilDB,$ilSetting,$lng,$ilLog;
55 
56  // Initialise language object
57  if(!is_object($lng))
58  {
59  include_once './Services/Language/classes/class.ilLanguage.php';
60  $lng = new ilLanguage('en');
61  }
62 
63  $this->log = $ilLog;
64 
65  $this->server_settings = $a_server;
66  $this->setting = $ilSetting;
67 
68  $this->initLDAPAttributeMapping();
69  }
global $ilSetting
Definition: privfeed.php:40
global $lng
Definition: privfeed.php:40
global $ilDB
language handling
+ Here is the call graph for this function:

Member Function Documentation

◆ convertInput()

ilLDAPAttributeToUser::convertInput (   $a_value)
private

A value can be an array or a string This function converts arrays to strings.

private

Parameters
arrayor string value
Returns
string

Definition at line 365 of file class.ilLDAPAttributeToUser.php.

Referenced by doMapping().

366  {
367  if(is_array($a_value))
368  {
369  return $a_value[0];
370  }
371  else
372  {
373  return $a_value;
374  }
375  }
+ Here is the caller graph for this function:

◆ doMapping()

ilLDAPAttributeToUser::doMapping (   $user,
  $rule 
)
private

doMapping

private

Definition at line 383 of file class.ilLDAPAttributeToUser.php.

References $mapping, and convertInput().

Referenced by usersToXML().

384  {
385  $mapping = trim(strtolower($rule['value']));
386 
387  if(strpos($mapping,',') === false)
388  {
389  return $this->convertInput($user[$mapping]);
390  }
391  // Is multiple mapping
392 
393  $fields = explode(',',$mapping);
394  $value = '';
395  foreach($fields as $field)
396  {
397  if(strlen($value))
398  {
399  $value .= ' ';
400  }
401  $value .= ($this->convertInput($user[trim($field)]));
402  }
403  return $value ? $value : '';
404  }
convertInput($a_value)
A value can be an array or a string This function converts arrays to strings.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewUserAuthMode()

ilLDAPAttributeToUser::getNewUserAuthMode ( )

Get auth mode for new users.

Definition at line 107 of file class.ilLDAPAttributeToUser.php.

References $new_user_auth_mode.

Referenced by usersToXML().

+ Here is the caller graph for this function:

◆ getServer()

ilLDAPAttributeToUser::getServer ( )

Get server settings.

Returns
ilLDAPServer

Definition at line 76 of file class.ilLDAPAttributeToUser.php.

References $server_settings.

Referenced by refresh(), and usersToXML().

+ Here is the caller graph for this function:

◆ initLDAPAttributeMapping()

ilLDAPAttributeToUser::initLDAPAttributeMapping ( )
private

Definition at line 408 of file class.ilLDAPAttributeToUser.php.

References ilLDAPAttributeMapping\_getInstanceByServerId().

Referenced by __construct().

409  {
410  include_once('Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
411  $this->mapping = ilLDAPAttributeMapping::_getInstanceByServerId($this->server_settings->getServerId());
412  }
static _getInstanceByServerId($a_server_id)
Get instance of class.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initUserDefinedFields()

ilLDAPAttributeToUser::initUserDefinedFields ( )
private

Definition at line 414 of file class.ilLDAPAttributeToUser.php.

References ilUserDefinedFields\_getInstance().

Referenced by usersToXML().

415  {
416  include_once('Services/User/classes/class.ilUserDefinedFields.php');
417  $this->udf = ilUserDefinedFields::_getInstance();
418  }
static _getInstance()
Get instance.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ refresh()

ilLDAPAttributeToUser::refresh ( )

Create/Update non existing users.

public

Definition at line 119 of file class.ilLDAPAttributeToUser.php.

References ilLDAPRoleAssignmentRules\getAllPossibleRoles(), getServer(), and usersToXML().

120  {
121  global $rbacadmin;
122 
123  $this->usersToXML();
124 
125  include_once './Services/User/classes/class.ilUserImportParser.php';
126  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
127 
128  $importParser = new ilUserImportParser();
129  $importParser->setXMLContent($this->writer->xmlDumpMem(false));
130  $importParser->setRoleAssignment(ilLDAPRoleAssignmentRules::getAllPossibleRoles($this->getServer()->getServerId()));
131  $importParser->setFolderId(7);
132  $importParser->startParsing();
133  $debug = $importParser->getProtocol();
134  #var_dump("<pre>",$this->writer->xmlDumpMem(),"</pre>");
135  #print_r($this->writer->xmlDumpMem($format));
136 
137  return true;
138  }
static getAllPossibleRoles($a_server_id)
Get all assignable roles (used for import parser)
getServer()
Get server settings.
usersToXML()
Create xml string of user according to mapping rules.
+ Here is the call graph for this function:

◆ setNewUserAuthMode()

ilLDAPAttributeToUser::setNewUserAuthMode (   $a_authmode)

Set auth mode for new users.

E.g. radius for radius authenticated user with ldap data source

Parameters
string$a_authmode

Definition at line 99 of file class.ilLDAPAttributeToUser.php.

100  {
101  $this->new_user_auth_mode = $a_authmode;
102  }

◆ setUserData()

ilLDAPAttributeToUser::setUserData (   $a_data)

Set user data received from pear auth or by ldap_search.

public

Parameters
arrayarray of auth data. array('ilias_account1' => array(firstname => 'Stefan',...),...)

Definition at line 89 of file class.ilLDAPAttributeToUser.php.

90  {
91  $this->user_data = $a_data;
92  }

◆ usersToXML()

ilLDAPAttributeToUser::usersToXML ( )
private

Create xml string of user according to mapping rules.

private

Definition at line 146 of file class.ilLDAPAttributeToUser.php.

References $data, ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), doMapping(), ilLDAPRoleAssignmentRules\getAssignmentsForCreation(), ilLDAPRoleAssignmentRules\getAssignmentsForUpdate(), getNewUserAuthMode(), getServer(), and initUserDefinedFields().

Referenced by refresh().

147  {
148  include_once('./Services/Xml/classes/class.ilXmlWriter.php');
149  $this->writer = new ilXmlWriter();
150  $this->writer->xmlStartTag('Users');
151 
152  $cnt_update = 0;
153  $cnt_create = 0;
154 
155  // Single users
156  foreach($this->user_data as $external_account => $user)
157  {
158  $user['ilExternalAccount'] = $external_account;
159 
160  // Required fields
161  if($user['ilInternalAccount'])
162  {
163  $usr_id = ilObjUser::_lookupId($user['ilInternalAccount']);
164 
165  ++$cnt_update;
166  // User exists
167  $this->writer->xmlStartTag('User',array('Id' => $usr_id,'Action' => 'Update'));
168  $this->writer->xmlElement('Login',array(),$user['ilInternalAccount']);
169  $this->writer->xmlElement('ExternalAccount',array(),$external_account);
170  $this->writer->xmlElement('AuthMode',array(type => $this->getNewUserAuthMode()),null);
171  $rules = $this->mapping->getRulesForUpdate();
172 
173  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
175  $this->getServer()->getServerId(),
176  $usr_id,
177  $external_account,
178  $user) as $role_data)
179  {
180  $this->writer->xmlElement('Role',
181  array('Id' => $role_data['id'],
182  'Type' => $role_data['type'],
183  'Action' => $role_data['action']),'');
184  }
185  }
186  else
187  {
188  ++$cnt_create;
189  // Create user
190  $this->writer->xmlStartTag('User',array('Action' => 'Insert'));
191  $this->writer->xmlElement('Login',array(),ilAuthUtils::_generateLogin($external_account));
192 
193  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
195  $this->getServer()->getServerId(),
196  $external_account,
197  $user) as $role_data)
198  {
199  $this->writer->xmlElement('Role',
200  array('Id' => $role_data['id'],
201  'Type' => $role_data['type'],
202  'Action' => $role_data['action']),'');
203  }
204 
205  $rules = $this->mapping->getRules();
206 
207  }
208 
209  $this->writer->xmlElement('Active',array(),"true");
210  $this->writer->xmlElement('TimeLimitOwner',array(),7);
211  $this->writer->xmlElement('TimeLimitUnlimited',array(),1);
212  $this->writer->xmlElement('TimeLimitFrom',array(),time());
213  $this->writer->xmlElement('TimeLimitUntil',array(),time());
214 
215  // only for new users.
216  // If auth_mode is 'default' (ldap) this status should remain.
217  if(!$user['ilInternalAccount'])
218  {
219  $this->writer->xmlElement('AuthMode',
220  array('type' => $this->getNewUserAuthMode()),
221  $this->getNewUserAuthMode()
222  );
223  $this->writer->xmlElement('ExternalAccount',array(),$external_account);
224  }
225  foreach($rules as $field => $data)
226  {
227  // Do Mapping: it is possible to assign multiple ldap attribute to one user data field
228  if(!($value = $this->doMapping($user,$data)))
229  {
230  continue;
231  }
232 
233  switch($field)
234  {
235  case 'gender':
236  switch(strtolower($value))
237  {
238  case 'm':
239  case 'male':
240  $this->writer->xmlElement('Gender',array(),'m');
241  break;
242 
243  case 'f':
244  case 'female':
245  default:
246  $this->writer->xmlElement('Gender',array(),'f');
247  break;
248 
249  }
250  break;
251 
252  case 'firstname':
253  $this->writer->xmlElement('Firstname',array(),$value);
254  break;
255 
256  case 'lastname':
257  $this->writer->xmlElement('Lastname',array(),$value);
258  break;
259 
260  case 'hobby':
261  $this->writer->xmlElement('Hobby',array(),$value);
262  break;
263 
264  case 'title':
265  $this->writer->xmlElement('Title',array(),$value);
266  break;
267 
268  case 'institution':
269  $this->writer->xmlElement('Institution',array(),$value);
270  break;
271 
272  case 'department':
273  $this->writer->xmlElement('Department',array(),$value);
274  break;
275 
276  case 'street':
277  $this->writer->xmlElement('Street',array(),$value);
278  break;
279 
280  case 'city':
281  $this->writer->xmlElement('City',array(),$value);
282  break;
283 
284  case 'zipcode':
285  $this->writer->xmlElement('PostalCode',array(),$value);
286  break;
287 
288  case 'country':
289  $this->writer->xmlElement('Country',array(),$value);
290  break;
291 
292  case 'phone_office':
293  $this->writer->xmlElement('PhoneOffice',array(),$value);
294  break;
295 
296  case 'phone_home':
297  $this->writer->xmlElement('PhoneHome',array(),$value);
298  break;
299 
300  case 'phone_mobile':
301  $this->writer->xmlElement('PhoneMobile',array(),$value);
302  break;
303 
304  case 'fax':
305  $this->writer->xmlElement('Fax',array(),$value);
306  break;
307 
308  case 'email':
309  $this->writer->xmlElement('Email',array(),$value);
310  break;
311 
312  case 'matriculation':
313  $this->writer->xmlElement('Matriculation',array(),$value);
314  break;
315 
316  /*
317  case 'photo':
318  $this->writer->xmlElement('PersonalPicture',array('encoding' => 'Base64','imagetype' => 'image/jpeg'),
319  base64_encode($this->convertInput($user[$value])));
320  break;
321  */
322  default:
323  // Handle user defined fields
324  if(substr($field,0,4) != 'udf_')
325  {
326  continue;
327  }
328  $id_data = explode('_',$field);
329  if(!isset($id_data[1]))
330  {
331  continue;
332  }
333  $this->initUserDefinedFields();
334  $definition = $this->udf->getDefinition($id_data[1]);
335  $this->writer->xmlElement('UserDefinedField',array('Id' => $definition['il_id'],
336  'Name' => $definition['field_name']),
337  $value);
338  break;
339 
340 
341  }
342  }
343  $this->writer->xmlEndTag('User');
344  }
345 
346  if($cnt_create)
347  {
348  $this->log->write('LDAP: Started creation of '.$cnt_create.' users.');
349  }
350  if($cnt_update)
351  {
352  $this->log->write('LDAP: Started update of '.$cnt_update.' users.');
353  }
354  $this->writer->xmlEndTag('Users');
355  }
static getAssignmentsForCreation($a_server_id, $a_usr_name, $a_usr_data)
doMapping($user, $rule)
doMapping
XML writer class.
static _lookupId($a_user_str)
Lookup id by login.
static getAssignmentsForUpdate($a_server_id, $a_usr_id, $a_usr_name, $a_usr_data)
type $ilDB type $rbacadmin type $rbacreview type $ilSetting type $ilLog
$data
_generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
getNewUserAuthMode()
Get auth mode for new users.
getServer()
Get server settings.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilLDAPAttributeToUser::$db = null
private

Definition at line 38 of file class.ilLDAPAttributeToUser.php.

◆ $mapping

ilLDAPAttributeToUser::$mapping = null
private

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

Referenced by doMapping().

◆ $new_user_auth_mode

ilLDAPAttributeToUser::$new_user_auth_mode = 'ldap'
private

Definition at line 44 of file class.ilLDAPAttributeToUser.php.

Referenced by getNewUserAuthMode().

◆ $role_assignment

ilLDAPAttributeToUser::$role_assignment = null
private

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

◆ $server_settings

ilLDAPAttributeToUser::$server_settings = null
private

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

Referenced by getServer().

◆ $setting

ilLDAPAttributeToUser::$setting = null
private

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

◆ $user_data

ilLDAPAttributeToUser::$user_data = array()
private

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


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