ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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...
 
 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 347 of file class.ilLDAPAttributeToUser.php.

Referenced by doMapping().

348  {
349  if(is_array($a_value))
350  {
351  return $a_value[0];
352  }
353  else
354  {
355  return $a_value;
356  }
357  }
+ Here is the caller graph for this function:

◆ doMapping()

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

doMapping

private

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

References $mapping, and convertInput().

Referenced by usersToXML().

366  {
367  $mapping = trim(strtolower($rule['value']));
368 
369  if(strpos($mapping,',') === false)
370  {
371  return $this->convertInput($user[$mapping]);
372  }
373  // Is multiple mapping
374 
375  $fields = explode(',',$mapping);
376  $value = '';
377  foreach($fields as $field)
378  {
379  if(strlen($value))
380  {
381  $value .= ' ';
382  }
383  $value .= ($this->convertInput($user[trim($field)]));
384  }
385  return $value ? $value : '';
386  }
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 96 of file class.ilLDAPAttributeToUser.php.

References $new_user_auth_mode.

Referenced by usersToXML().

+ Here is the caller graph for this function:

◆ initLDAPAttributeMapping()

ilLDAPAttributeToUser::initLDAPAttributeMapping ( )
private

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

References ilLDAPAttributeMapping\_getInstanceByServerId().

Referenced by __construct().

391  {
392  include_once('Services/LDAP/classes/class.ilLDAPAttributeMapping.php');
393  $this->mapping = ilLDAPAttributeMapping::_getInstanceByServerId($this->server_settings->getServerId());
394  }
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 396 of file class.ilLDAPAttributeToUser.php.

References ilUserDefinedFields\_getInstance().

Referenced by usersToXML().

397  {
398  include_once('Services/User/classes/class.ilUserDefinedFields.php');
399  $this->udf = ilUserDefinedFields::_getInstance();
400  }
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 108 of file class.ilLDAPAttributeToUser.php.

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

109  {
110  global $rbacadmin;
111 
112  $this->usersToXML();
113 
114  include_once './Services/User/classes/class.ilUserImportParser.php';
115  include_once './Services/LDAP/classes/class.ilLDAPRoleAssignmentRules.php';
116 
117  $importParser = new ilUserImportParser();
118  $importParser->setXMLContent($this->writer->xmlDumpMem(false));
119  $importParser->setRoleAssignment(ilLDAPRoleAssignmentRules::getAllPossibleRoles());
120  $importParser->setFolderId(7);
121  $importParser->startParsing();
122  $debug = $importParser->getProtocol();
123  #var_dump("<pre>",$this->writer->xmlDumpMem(),"</pre>");
124  #print_r($this->writer->xmlDumpMem($format));
125 
126  return true;
127  }
static getAllPossibleRoles()
Get all assignable roles (used for import parser)
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 88 of file class.ilLDAPAttributeToUser.php.

89  {
90  $this->new_user_auth_mode = $a_authmode;
91  }

◆ 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 78 of file class.ilLDAPAttributeToUser.php.

79  {
80  $this->user_data = $a_data;
81  }

◆ usersToXML()

ilLDAPAttributeToUser::usersToXML ( )
private

Create xml string of user according to mapping rules.

private

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

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

Referenced by refresh().

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

◆ $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: