19 declare(strict_types=1);
48 $this->
logger = $DIC->logger()->auth();
50 $this->server_settings = $a_server;
72 $this->user_data = $a_data;
81 $this->new_user_auth_mode = $a_authmode;
95 public function addMode(
int $a_mode): void
98 if (!in_array($a_mode, $this->modes,
true)) {
99 $this->modes[] = $a_mode;
110 return in_array($a_mode, $this->modes,
true);
122 $importParser->setXMLContent($this->writer->xmlDumpMem(
false));
124 $importParser->setFolderId(7);
125 $importParser->startParsing();
144 $this->writer->xmlElement(
147 'Id' => $role_data[
'id'],
148 'Type' => $role_data[
'type'],
149 'Action' => $role_data[
'action']
168 $this->writer->xmlElement(
171 'Id' => $role_data[
'id'],
172 'Type' => $role_data[
'type'],
173 'Action' => $role_data[
'action']
186 $this->writer->xmlStartTag(
'Users');
192 foreach ($this->user_data as $external_account => $user) {
193 $external_account = (string) $external_account;
195 $user[
'ilExternalAccount'] = $external_account;
198 if ($user[
'ilInternalAccount']) {
203 $this->writer->xmlStartTag(
'User', [
'Id' => $usr_id,
'Action' =>
'Update']);
204 $this->writer->xmlElement(
'Login', [], $user[
'ilInternalAccount']);
205 $this->writer->xmlElement(
'ExternalAccount', [], $external_account);
213 $rules = $this->mapping->getRulesForUpdate();
217 $this->writer->xmlStartTag(
'User', [
'Action' =>
'Insert']);
221 $rules = $this->mapping->getRules(
true);
224 $this->writer->xmlElement(
'Active', [],
"true");
225 $this->writer->xmlElement(
'TimeLimitOwner', [], 7);
226 $this->writer->xmlElement(
'TimeLimitUnlimited', [], 1);
227 $this->writer->xmlElement(
'TimeLimitFrom', [], time());
228 $this->writer->xmlElement(
'TimeLimitUntil', [], time());
232 if (!$user[
'ilInternalAccount']) {
233 $this->writer->xmlElement(
238 $this->writer->xmlElement(
'ExternalAccount', [], $external_account);
240 foreach ($rules as $field =>
$data) {
248 switch (strtolower($value)) {
252 $this->writer->xmlElement(
'Gender', [],
'm');
257 $this->writer->xmlElement(
'Gender', [],
'f');
262 $this->writer->xmlElement(
'Gender', [],
'n');
268 $this->writer->xmlElement(
'Firstname', [], $value);
272 $this->writer->xmlElement(
'Lastname', [], $value);
276 $this->writer->xmlElement(
'Hobby', [], $value);
280 $this->writer->xmlElement(
'Title', [], $value);
284 $this->writer->xmlElement(
'Institution', [], $value);
288 $this->writer->xmlElement(
'Department', [], $value);
292 $this->writer->xmlElement(
'Street', [], $value);
296 $this->writer->xmlElement(
'City', [], $value);
300 $this->writer->xmlElement(
'PostalCode', [], $value);
304 $this->writer->xmlElement(
'Country', [], $value);
308 $this->writer->xmlElement(
'PhoneOffice', [], $value);
312 $this->writer->xmlElement(
'PhoneHome', [], $value);
316 $this->writer->xmlElement(
'PhoneMobile', [], $value);
320 $this->writer->xmlElement(
'Fax', [], $value);
324 $this->writer->xmlElement(
'Email', [], $value);
328 $this->writer->xmlElement(
'SecondEmail', [], $value);
331 case 'matriculation':
332 $this->writer->xmlElement(
'Matriculation', [], $value);
337 if (strpos($field,
'udf_') !== 0) {
340 $id_data = explode(
'_', $field);
341 if (!isset($id_data[1])) {
345 $definition = $this->udf->getDefinition((
int) $id_data[1]);
346 if (empty($definition)) {
347 $this->
logger->warning(sprintf(
348 "Invalid/Orphaned UD field mapping detected: %s",
354 $this->writer->xmlElement(
357 'Id' => $definition[
'il_id'],
358 'Name' => $definition[
'field_name']
367 $this->writer->xmlEndTag(
'User');
371 $this->
logger->info(
'LDAP: Started creation of ' . $cnt_create .
' users.');
374 $this->
logger->info(
'LDAP: Started update of ' . $cnt_update .
' users.');
376 $this->writer->xmlEndTag(
'Users');
388 if (is_array($a_value)) {
395 private function doMapping(array $user, array $rule): string
397 $mapping = strtolower(trim($rule[
'value']));
399 if (strpos($mapping,
',') ===
false) {
404 $fields = explode(
',', $mapping);
406 foreach ($fields as $field) {
410 $value .= ($this->
convertInput($user[trim($field)] ??
''));
static getAssignmentsForUpdate(int $a_server_id, $a_usr_id, $a_usr_name, $a_usr_data)
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
Additional user data fields definition.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupId($a_user_str)
setNewUserAuthMode(string $a_authmode)
Set auth mode for new users.
ilLDAPServer $server_settings
parseRoleAssignmentsForCreation(string $a_external_account, array $a_user)
Parse role assignments for update of user account.
parseRoleAssignmentsForUpdate(int $a_usr_id, string $a_external_account, array $user)
Parse role assignments for update of user account.
convertInput($a_value)
A value can be an array or a string This function converts arrays to strings.
setUserData(array $a_data)
Set user data received from pear auth or by ldap_search.
string $new_user_auth_mode
static getAllPossibleRoles(int $a_server_id)
Get all assignable roles (used for import parser)
const MODE_INITIALIZE_ROLES
ilLDAPAttributeMapping $mapping
__construct(ilLDAPServer $a_server)
Construct of ilLDAPAttribute2XML Defines between LDAP and ILIAS user attributes.
initLDAPAttributeMapping()
doMapping(array $user, array $rule)
static getAssignmentsForCreation(int $a_server_id, string $a_usr_name, array $a_usr_data)
refresh()
Create/Update non existing users.
This class stores the settings that define the mapping between LDAP attribute and user profile fields...
getNewUserAuthMode()
Get auth mode for new users.
isModeActive(int $a_mode)
Check if mode is active.
Update/create ILIAS user account by given LDAP attributes according to user attribute mapping setting...
getServer()
Get server settings.
static _getInstanceByServerId(int $a_server_id)
addMode(int $a_mode)
Add import mode.
usersToXML()
Create xml string of user according to mapping rules.