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)) {
251 $this->writer->xmlElement(
'Gender', [],
'm');
256 $this->writer->xmlElement(
'Gender', [],
'f');
261 $this->writer->xmlElement(
'Gender', [],
'n');
267 $this->writer->xmlElement(
'Firstname', [], $value);
271 $this->writer->xmlElement(
'Lastname', [], $value);
275 $this->writer->xmlElement(
'Hobby', [], $value);
279 $this->writer->xmlElement(
'Title', [], $value);
283 $this->writer->xmlElement(
'Institution', [], $value);
287 $this->writer->xmlElement(
'Department', [], $value);
291 $this->writer->xmlElement(
'Street', [], $value);
295 $this->writer->xmlElement(
'City', [], $value);
299 $this->writer->xmlElement(
'PostalCode', [], $value);
303 $this->writer->xmlElement(
'Country', [], $value);
307 $this->writer->xmlElement(
'PhoneOffice', [], $value);
311 $this->writer->xmlElement(
'PhoneHome', [], $value);
315 $this->writer->xmlElement(
'PhoneMobile', [], $value);
319 $this->writer->xmlElement(
'Fax', [], $value);
323 $this->writer->xmlElement(
'Email', [], $value);
327 $this->writer->xmlElement(
'SecondEmail', [], $value);
330 case 'matriculation':
331 $this->writer->xmlElement(
'Matriculation', [], $value);
336 if (strpos($field,
'udf_') !== 0) {
339 $id_data = explode(
'_', $field);
340 if (!isset($id_data[1])) {
344 $definition = $this->udf->getDefinition((
int) $id_data[1]);
345 if (empty($definition)) {
346 $this->
logger->warning(sprintf(
347 "Invalid/Orphaned UD field mapping detected: %s",
353 $this->writer->xmlElement(
356 'Id' => $definition[
'il_id'],
357 'Name' => $definition[
'field_name']
364 $this->writer->xmlEndTag(
'User');
368 $this->
logger->info(
'LDAP: Started creation of ' . $cnt_create .
' users.');
371 $this->
logger->info(
'LDAP: Started update of ' . $cnt_update .
' users.');
373 $this->writer->xmlEndTag(
'Users');
385 if (is_array($a_value)) {
392 private function doMapping(array $user, array $rule): string
394 $mapping = strtolower(trim($rule[
'value']));
396 if (strpos($mapping,
',') ===
false) {
401 $fields = explode(
',', $mapping);
403 foreach ($fields as $field) {
407 $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.
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.