33 public function login(
string $client,
string $username,
string $password)
40 }
catch (Exception
$e) {
41 return $this->
raiseError($e->getMessage(),
'Server');
46 $credentials->setUsername($username);
47 $credentials->setPassword($password);
50 $providers = $provider_factory->getProviders($credentials);
56 $frontend = $frontend_factory->getFrontend(
63 $frontend->authenticate();
65 switch ($status->getStatus()) {
92 $GLOBALS[
'DIC'][
'ilAuthSession']->logout();
99 public function lookupUser(
string $sid,
string $user_name)
108 $user_name = trim($user_name);
110 if ($user_name ===
'') {
111 return $this->
raiseError(
'No username given. Aborting',
'Client');
116 $ilUser =
$DIC->user();
117 $access =
$DIC->access();
120 strcasecmp($ilUser->getLogin(), $user_name) !== 0 &&
121 !$access->checkAccess(
138 public function importUsers(
string $sid,
int $folder_id,
string $usr_xml,
int $conflict_rule,
bool $send_account_mail)
149 $rbacreview =
$DIC[
'rbacreview'];
150 $rbacsystem =
$DIC[
'rbacsystem'];
151 $access =
$DIC->access();
152 $tree =
$DIC[
'tree'];
154 $ilUser =
$DIC[
'ilUser'];
155 $ilLog =
$DIC[
'ilLog'];
158 $usr_xml = ltrim($usr_xml);
160 $doc =
new DOMDocument();
161 libxml_use_internal_errors(
true);
163 $is_loadable = $doc->loadXML($usr_xml);
164 $errors = libxml_get_errors();
165 libxml_clear_errors();
169 foreach ($errors as $err) {
170 $msg[] =
"(" . $err->line .
"," . $err->column .
"): " . trim($err->message);
172 libxml_clear_errors();
173 $msg = implode(
"\n", $msg);
177 switch ($conflict_rule) {
189 'Missing permission for creating/modifying users accounts' .
self::USER_FOLDER_ID .
' ' . $ilUser->getId(),
196 if ($folder_id !== 0) {
198 if ($folder_id === -1) {
205 if (!$import_folder) {
206 return $this->
raiseError(
'Wrong reference id.',
'Server');
210 if ($import_folder->getType() !==
"usrf" && $import_folder->getType() !==
"cat") {
211 return $this->
raiseError(
'Folder must be a usr folder or a category.',
'Server');
215 if (!$rbacsystem->checkAccess(
'create_usr', $folder_id)) {
217 'Missing permission for creating users within ' . $import_folder->getTitle(),
226 $importParser->setXMLContent($usr_xml);
227 $importParser->startParsing();
229 switch ($importParser->getErrorLevel()) {
242 $importParser->setXMLContent($usr_xml);
244 $importParser->startParsing();
246 $roles = $importParser->getCollectedRoles();
251 $permitted_roles = array();
252 foreach ($roles as $role_id => $role) {
253 if (!is_numeric($role_id)) {
257 if (is_numeric($internalId) && $internalId > 0) {
258 $role_id = $internalId;
259 $role_name = $role_id;
264 $permitted_roles[$role_id] = $role_id;
268 "Could not find role " . $role_name .
". Either you use an invalid/deleted role " .
269 "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.",
275 $global_roles = $rbacreview->getGlobalRoles();
279 foreach ($permitted_roles as $role_id => $role_name) {
280 if ($role_id !=
"") {
281 if (in_array($role_id, $global_roles)) {
290 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)
294 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
299 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
300 if ($rbacreview->isDeleted($rolf[0])
301 || !$rbacsystem->checkAccess(
'write', $rolf[0])) {
303 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
314 $importParser->setSendMail($send_account_mail);
316 $importParser->setFolderId($folder_id);
317 $importParser->setXMLContent($usr_xml);
319 $importParser->setRoleAssignment($permitted_roles);
321 $importParser->startParsing();
331 static $checked_roles = array();
332 static $global_roles =
null;
334 if (isset($checked_roles[$a_role])) {
335 return $checked_roles[$a_role];
340 $rbacsystem =
$DIC[
'rbacsystem'];
341 $rbacreview =
$DIC[
'rbacreview'];
342 $ilUser =
$DIC[
'ilUser'];
343 $tree =
$DIC[
'tree'];
344 $ilLog =
$DIC[
'ilLog'];
346 $locations = $rbacreview->getFoldersAssignedToRole($a_role,
true);
351 $ilLog->write(__METHOD__ .
': Check global role');
355 $ilLog->write(__METHOD__ .
': ' . $a_folder);
357 $ilLog->write(__METHOD__ .
': No assignment allowed');
358 $checked_roles[$a_role] =
false;
364 $ilLog->write(__METHOD__ .
': Anonymous role chosen.');
365 $checked_roles[$a_role] =
false;
370 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
371 $ilLog->write(__METHOD__ .
': System role assignment forbidden.');
372 $checked_roles[$a_role] =
false;
377 $ilLog->write(__METHOD__ .
': Assignment allowed.');
378 $checked_roles[$a_role] =
true;
381 $ilLog->write(__METHOD__ .
': Check local role.');
384 $rolfs = $rbacreview->getFoldersAssignedToRole($a_role,
true);
391 if ($rbacreview->isDeleted($rolf)
392 || !$rbacsystem->checkAccess(
'edit_permission', $rolf)) {
393 $ilLog->write(__METHOD__ .
': Role deleted or no permission.');
394 $checked_roles[$a_role] =
false;
405 if ($a_folder !==
self::USER_FOLDER_ID && $a_folder !== 0 && !$tree->isGrandChild($a_folder, $rolf)) {
406 $ilLog->write(__METHOD__ .
': Not in path of category.');
407 $checked_roles[$a_role] =
false;
410 $ilLog->write(__METHOD__ .
': Assignment allowed.');
411 $checked_roles[$a_role] =
true;
432 $tree =
$DIC[
'tree'];
433 $rbacreview =
$DIC[
'rbacreview'];
434 $rbacsystem =
$DIC[
'rbacsystem'];
435 $access =
$DIC->access();
445 return $this->
raiseError(
'Access denied',
"Client");
448 $object = $this->
checkObjectAccess($ref_id, array(
"crs",
"cat",
"grp",
"usrf",
"sess"),
"read",
true);
454 switch ($object->getType()) {
464 $roles = $object->__getLocalRoles();
466 foreach ($roles as $role_id) {
467 $data = array_merge($rbacreview->assignedUsers($role_id),
$data);
473 $member_ids = $object->getGroupMemberIds();
477 $course_ref_id = $tree->checkForParentType(
$ref_id,
'crs');
478 if (!$course_ref_id) {
479 return $this->
raiseError(
"No course for session",
"Client");
484 $member_ids = array_keys($event_part->getParticipants());
490 $xmlWriter->setObjects(
$data);
491 $xmlWriter->setAttachRoles($attachRoles);
493 if ($xmlWriter->start()) {
494 return $xmlWriter->getXML();
503 public function getUserForRole(
string $sid,
int $role_id,
bool $attachRoles,
int $active)
515 $rbacreview =
$DIC->rbac()->review();
516 $tree =
$DIC->repositoryTree();
517 $ilUser =
$DIC->user();
518 $access =
$DIC->access();
520 $global_roles = $rbacreview->getGlobalRoles();
522 if (in_array($role_id, $global_roles,
true)) {
525 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
526 return $this->
raiseError(
"Role access not permitted. ($role_id)",
"Server");
530 $rolfs = $rbacreview->getFoldersAssignedToRole($role_id,
true);
531 $access_granted =
true;
532 foreach ($rolfs as $rolf) {
533 if ($tree->isDeleted($rolf)) {
534 $access_granted =
false;
540 if (!$access->checkAccess(
'manage_members',
'', $rolf)) {
541 $access_granted =
false;
545 if (!$access->checkAccess(
'edit_permission',
'', $rolf)) {
546 $access_granted =
false;
553 $access_granted =
false;
555 if (!$access_granted || !count($rolfs)) {
556 return $this->
raiseError(
'Role access not permitted. ' .
'(' . $role_id .
')',
'Server');
563 $xmlWriter->setAttachRoles($attachRoles);
565 $xmlWriter->setObjects(
$data);
567 if ($xmlWriter->start()) {
568 return $xmlWriter->getXML();
570 return $this->
raiseError(
'Error in getUsersForRole',
'Server');
579 $xmlResultSet->addColumn(
"userid");
580 $xmlResultSet->addColumn(
"login");
581 $xmlResultSet->addColumn(
"action");
582 $xmlResultSet->addColumn(
"message");
584 foreach ($a_array as $username => $messages) {
587 $xmlRow->setValue(0, 0);
588 $xmlRow->setValue(1, $username);
589 $xmlRow->setValue(2,
"");
592 $xmlResultSet->addRow($xmlRow);
598 if ($xml_writer->start()) {
599 return $xml_writer->getXML();
602 return $this->
raiseError(
'Error in __getImportProtocolAsXML',
'Server');
612 $xmlResultSet->addColumn(
"userid");
613 $xmlResultSet->addColumn(
"login");
614 $xmlResultSet->addColumn(
"action");
615 $xmlResultSet->addColumn(
"message");
617 if (count($a_array)) {
618 foreach ($a_array as $username =>
$message) {
620 $xmlRow->setValue(0, $username);
621 $xmlRow->setValue(1,
$message[
"login"]);
622 $xmlRow->setValue(2,
$message[
"action"]);
623 $xmlRow->setValue(3,
$message[
"message"]);
625 $xmlResultSet->addRow($xmlRow);
631 if ($xml_writer->start()) {
632 return $xml_writer->getXML();
635 return $this->
raiseError(
'Error in __getUserMappingAsXML',
'Server');
651 string $query_operator,
666 $access =
$DIC->access();
669 return $this->
raiseError(
'Check access failed.',
'Server');
671 if (!count($a_keyfields)) {
672 $this->
raiseError(
'At least one keyfield is needed',
'Client');
675 if (!count($a_keyvalues)) {
676 $this->
raiseError(
'At least one keyvalue is needed',
'Client');
679 if (strcasecmp($query_operator,
"and") !== 0 || strcasecmp($query_operator,
"or") !== 0) {
680 $this->
raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
683 $query = $this->
buildSearchQuery($a_keyfields, $query_operator, $a_keyvalues);
685 $query =
"SELECT usr_data.*, usr_pref.value AS language
688 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = " .
689 $ilDB->quote(
"language",
"text") .
690 " WHERE 1 = 1 " . $query;
693 $query .=
" AND active = " .
$ilDB->quote($active);
696 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
700 $r =
$ilDB->query($query);
704 while ($row =
$ilDB->fetchAssoc($r)) {
709 $xmlWriter->setAttachRoles($attach_roles);
711 $xmlWriter->setObjects(
$data);
713 if ($xmlWriter->start()) {
714 return $xmlWriter->getXML();
716 return $this->
raiseError(
'Error in searchUser',
'Server');
722 private function buildSearchQuery(array $a_keyfields,
string $queryOperator, array $a_keyvalues): string
729 $allowed_fields = array(
"firstname",
740 foreach ($a_keyfields as $keyfield) {
741 $keyfield = strtolower($keyfield);
743 if (!in_array($keyfield, $allowed_fields)) {
747 $field_query = array();
748 foreach ($a_keyvalues as $keyvalue) {
749 if (strlen($keyvalue) >= 3) {
750 $field_query [] =
$ilDB->like(
$ilDB->quoteIdentifier($keyfield),
'text',
'%' . $keyvalue .
"%");
753 if (count($field_query)) {
754 $query [] = implode(
" " . strtoupper($queryOperator) .
" ", $field_query);
758 return count($query) ?
" AND ((" . implode(
") OR (", $query) .
"))" :
"AND 0";
764 public function getUserXML(
string $sid, array $a_user_ids,
bool $attach_roles)
775 $rbacsystem =
$DIC[
'rbacsystem'];
776 $access =
$DIC->access();
777 $ilUser =
$DIC[
'ilUser'];
782 if (count($a_user_ids) === 1) {
783 $usr_id = (
int) end($a_user_ids);
784 if ($usr_id === $ilUser->getId()) {
790 return $this->
raiseError(
'Check access failed.',
'Server');
796 $xmlWriter->setAttachRoles($attach_roles);
797 $xmlWriter->setObjects(
$data);
799 if ($xmlWriter->start()) {
800 return $xmlWriter->getXML();
803 return $this->
raiseError(
'User does not exist',
'Client');
817 $ilUser =
$DIC[
'ilUser'];
838 $parts = explode(
'::', $sid);
839 $query =
"SELECT usr_id FROM usr_session "
840 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
844 if (!(
int)
$data[
'usr_id']) {
845 $this->
raiseError(
'User does not exist',
'Client');
847 return (
int) $data[
'usr_id'];
const int STATUS_AUTHENTICATION_FAILED
const int STATUS_AUTHENTICATED
static getInstance()
Get status instance.
class ilEventParticipants
static getLogger(string $a_component_id)
Get component logger.
static getNewMailsData(ilObjUser $user, int $left_interval=0)
static _getAssignUsersStatus(int $a_role_id)
static _getUsersForIds(array $a_mem_ids, int $active=-1, int $timelimitowner=-1)
static _getUserData(array $a_internalids)
static _getUsersForFolder(int $ref_id, int $active)
static _getUsersForGroup(array $a_mem_ids, int $active=-1)
static getUserIdByLogin(string $a_login)
static _getUsersForRole(int $role_id, int $active=-1)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static setClosingContext(int $a_context)
set closing context (for statistics)
const int SESSION_CLOSE_USER
raiseError(string $a_message, $a_code)
checkSession(string $sid)
checkObjectAccess(int $ref_id, array $expected_type, string $permission, bool $returnObject=false)
check access for ref id: expected type, permission, return object instance if returnobject is true
isPermittedRole(int $a_folder, int $a_role)
getImportProtocolAsXML(array $a_array)
Create XML ResultSet.
getUserIdBySid(string $sid)
login(string $client, string $username, string $password)
getUserForRole(string $sid, int $role_id, bool $attachRoles, int $active)
searchUser(string $sid, array $a_keyfields, string $query_operator, array $a_keyvalues, bool $attach_roles, int $active)
return user xml following dtd 3.7
lookupUser(string $sid, string $user_name)
getUsersForContainer(string $sid, int $ref_id, bool $attachRoles, int $active)
getUserXML(string $sid, array $a_user_ids, bool $attach_roles)
getUserMappingAsXML(array $a_array)
return user mapping as xml
importUsers(string $sid, int $folder_id, string $usr_xml, int $conflict_rule, bool $send_account_mail)
buildSearchQuery(array $a_keyfields, string $queryOperator, array $a_keyvalues)
create search term according to parameters
const IL_IGNORE_ON_CONFLICT
const IL_UPDATE_ON_CONFLICT
const IL_FAIL_ON_CONFLICT
XML writer class Class to simplify manual writing of xml documents.
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
Row Class for XMLResultSet.
XML Writer for XMLResultSet.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts