19declare(strict_types=1);
54 $this->
logger = $DIC->logger()->auth();
55 $this->
profile = $DIC[
'user']->profile();
57 $this->server_settings = $a_server;
79 $this->user_data = $a_data;
88 $this->new_user_auth_mode = $a_authmode;
105 if (!in_array($a_mode, $this->modes,
true)) {
106 $this->modes[] = $a_mode;
117 return in_array($a_mode, $this->modes,
true);
129 $importParser->setXMLContent($this->writer->xmlDumpMem(
false));
131 $importParser->setFolderId(7);
132 $importParser->startParsing();
151 $this->writer->xmlElement(
154 'Id' => $role_data[
'id'],
155 'Type' => $role_data[
'type'],
156 'Action' => $role_data[
'action']
175 $this->writer->xmlElement(
178 'Id' => $role_data[
'id'],
179 'Type' => $role_data[
'type'],
180 'Action' => $role_data[
'action']
193 $this->writer->xmlStartTag(
'Users');
199 foreach ($this->user_data as $external_account => $user) {
200 $external_account = (string) $external_account;
202 $user[
'ilExternalAccount'] = $external_account;
205 if ($user[
'ilInternalAccount']) {
210 $this->writer->xmlStartTag(
'User', [
'Id' => $usr_id,
'Action' =>
'Update']);
211 $this->writer->xmlElement(
'Login', [], $user[
'ilInternalAccount']);
212 $this->writer->xmlElement(
'ExternalAccount', [], $external_account);
220 $rules = $this->mapping->getRulesForUpdate();
224 $this->writer->xmlStartTag(
'User', [
'Action' =>
'Insert']);
228 $rules = $this->mapping->getRules(
true);
231 $this->writer->xmlElement(
'Active', [],
"true");
232 $this->writer->xmlElement(
'TimeLimitOwner', [], 7);
233 $this->writer->xmlElement(
'TimeLimitUnlimited', [], 1);
234 $this->writer->xmlElement(
'TimeLimitFrom', [], time());
235 $this->writer->xmlElement(
'TimeLimitUntil', [], time());
239 if (!$user[
'ilInternalAccount']) {
240 $this->writer->xmlElement(
245 $this->writer->xmlElement(
'ExternalAccount', [], $external_account);
247 foreach ($rules as $field =>
$data) {
255 switch (strtolower($value)) {
258 $this->writer->xmlElement(
'Gender', [],
'm');
263 $this->writer->xmlElement(
'Gender', [],
'f');
268 $this->writer->xmlElement(
'Gender', [],
'n');
274 $this->writer->xmlElement(
'Firstname', [], $value);
278 $this->writer->xmlElement(
'Lastname', [], $value);
282 $this->writer->xmlElement(
'Hobby', [], $value);
286 $this->writer->xmlElement(
'Title', [], $value);
290 $this->writer->xmlElement(
'Institution', [], $value);
294 $this->writer->xmlElement(
'Department', [], $value);
298 $this->writer->xmlElement(
'Street', [], $value);
302 $this->writer->xmlElement(
'City', [], $value);
306 $this->writer->xmlElement(
'PostalCode', [], $value);
310 $this->writer->xmlElement(
'Country', [], $value);
314 $this->writer->xmlElement(
'PhoneOffice', [], $value);
318 $this->writer->xmlElement(
'PhoneHome', [], $value);
322 $this->writer->xmlElement(
'PhoneMobile', [], $value);
326 $this->writer->xmlElement(
'Fax', [], $value);
330 $this->writer->xmlElement(
'Email', [], $value);
334 $this->writer->xmlElement(
'SecondEmail', [], $value);
337 case 'matriculation':
338 $this->writer->xmlElement(
'Matriculation', [], $value);
343 if (strpos($field,
'udf_') !== 0) {
346 $id_data = explode(
'_', $field);
347 if (!isset($id_data[1])) {
351 if (!isset($this->user_defined_fields[$id_data[1]])) {
352 $this->
logger->warning(sprintf(
353 "Invalid/Orphaned UD field mapping detected: %s",
359 $this->writer->xmlElement(
362 'Id' => $this->user_defined_fields[$id_data[1]]->getIdentifier(),
363 'Name' => $this->user_defined_fields[$id_data[1]]->
getLabel()
370 $this->writer->xmlEndTag(
'User');
374 $this->
logger->info(
'LDAP: Started creation of ' . $cnt_create .
' users.');
377 $this->
logger->info(
'LDAP: Started update of ' . $cnt_update .
' users.');
379 $this->writer->xmlEndTag(
'Users');
391 if (is_array($a_value)) {
398 private function doMapping(array $user, array $rule): string
400 $mapping = strtolower(trim($rule[
'value']));
402 if (strpos(
$mapping,
',') ===
false) {
409 foreach ($fields as $field) {
413 $value .= ($this->
convertInput($user[trim($field)] ??
''));
425 if ($this->user_defined_fields ===
null) {
426 $this->user_defined_fields = $this->
profile->getAllUserDefinedFields();
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
static _getInstanceByServerId(int $a_server_id)
Update/create ILIAS user account by given LDAP attributes according to user attribute mapping setting...
initLDAPAttributeMapping()
__construct(ilLDAPServer $a_server)
Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.
ilLDAPServer $server_settings
parseRoleAssignmentsForCreation(string $a_external_account, array $a_user)
Parse role assignments for update of user account.
string $new_user_auth_mode
convertInput($a_value)
A value can be an array or a string This function converts arrays to strings.
parseRoleAssignmentsForUpdate(int $a_usr_id, string $a_external_account, array $user)
Parse role assignments for update of user account.
const MODE_INITIALIZE_ROLES
usersToXML()
Create xml string of user according to mapping rules.
getNewUserAuthMode()
Get auth mode for new users.
ilLDAPAttributeMapping $mapping
doMapping(array $user, array $rule)
isModeActive(int $a_mode)
Check if mode is active.
getServer()
Get server settings.
array $user_defined_fields
setUserData(array $a_data)
Set user data received from pear auth or by ldap_search.
addMode(int $a_mode)
Add import mode.
refresh()
Create/Update non existing users.
setNewUserAuthMode(string $a_authmode)
Set auth mode for new users.
static getAllPossibleRoles(int $a_server_id)
Get all assignable roles (used for import parser)
static getAssignmentsForCreation(int $a_server_id, string $a_usr_name, array $a_usr_data)
static getAssignmentsForUpdate(int $a_server_id, $a_usr_id, $a_usr_name, $a_usr_data)
Component logger with individual log levels by component id.
static _lookupId(string|array $a_user_str)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...