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 $user_ids = $rbacreview->assignedUsers($role_id);
475 $member_ids = $object->getGroupMemberIds();
479 $course_ref_id = $tree->checkForParentType(
$ref_id,
'crs');
480 if (!$course_ref_id) {
481 return $this->
raiseError(
"No course for session",
"Client");
486 $member_ids = array_keys($event_part->getParticipants());
492 $xmlWriter->setObjects(
$data);
493 $xmlWriter->setAttachRoles($attachRoles);
495 if ($xmlWriter->start()) {
496 return $xmlWriter->getXML();
505 public function getUserForRole(
string $sid,
int $role_id,
bool $attachRoles,
int $active)
517 $rbacreview =
$DIC->rbac()->review();
518 $tree =
$DIC->repositoryTree();
519 $ilUser =
$DIC->user();
520 $access =
$DIC->access();
522 $global_roles = $rbacreview->getGlobalRoles();
524 if (in_array($role_id, $global_roles,
true)) {
527 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
528 return $this->
raiseError(
"Role access not permitted. ($role_id)",
"Server");
532 $rolfs = $rbacreview->getFoldersAssignedToRole($role_id,
true);
533 $access_granted =
true;
534 foreach ($rolfs as $rolf) {
535 if ($tree->isDeleted($rolf)) {
536 $access_granted =
false;
542 if (!$access->checkAccess(
'manage_members',
'', $rolf)) {
543 $access_granted =
false;
547 if (!$access->checkAccess(
'edit_permission',
'', $rolf)) {
548 $access_granted =
false;
555 $access_granted =
false;
557 if (!$access_granted || !count($rolfs)) {
558 return $this->
raiseError(
'Role access not permitted. ' .
'(' . $role_id .
')',
'Server');
565 $xmlWriter->setAttachRoles($attachRoles);
567 $xmlWriter->setObjects(
$data);
569 if ($xmlWriter->start()) {
570 return $xmlWriter->getXML();
572 return $this->
raiseError(
'Error in getUsersForRole',
'Server');
581 $xmlResultSet->addColumn(
"userid");
582 $xmlResultSet->addColumn(
"login");
583 $xmlResultSet->addColumn(
"action");
584 $xmlResultSet->addColumn(
"message");
586 foreach ($a_array as $username => $messages) {
589 $xmlRow->setValue(0, 0);
590 $xmlRow->setValue(1, $username);
591 $xmlRow->setValue(2,
"");
594 $xmlResultSet->addRow($xmlRow);
600 if ($xml_writer->start()) {
601 return $xml_writer->getXML();
604 return $this->
raiseError(
'Error in __getImportProtocolAsXML',
'Server');
614 $xmlResultSet->addColumn(
"userid");
615 $xmlResultSet->addColumn(
"login");
616 $xmlResultSet->addColumn(
"action");
617 $xmlResultSet->addColumn(
"message");
619 if (count($a_array)) {
620 foreach ($a_array as $username =>
$message) {
622 $xmlRow->setValue(0, $username);
623 $xmlRow->setValue(1,
$message[
"login"]);
624 $xmlRow->setValue(2,
$message[
"action"]);
625 $xmlRow->setValue(3,
$message[
"message"]);
627 $xmlResultSet->addRow($xmlRow);
633 if ($xml_writer->start()) {
634 return $xml_writer->getXML();
637 return $this->
raiseError(
'Error in __getUserMappingAsXML',
'Server');
653 string $query_operator,
668 $access =
$DIC->access();
671 return $this->
raiseError(
'Check access failed.',
'Server');
673 if (!count($a_keyfields)) {
674 return $this->
raiseError(
'At least one keyfield is needed',
'Client');
677 if (!count($a_keyvalues)) {
678 return $this->
raiseError(
'At least one keyvalue is needed',
'Client');
681 if (strcasecmp($query_operator,
"and") !== 0 || strcasecmp($query_operator,
"or") !== 0) {
682 $this->
raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
685 $query = $this->
buildSearchQuery($a_keyfields, $query_operator, $a_keyvalues);
687 $query =
"SELECT usr_data.*, usr_pref.value AS language
690 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = " .
691 $ilDB->quote(
"language",
"text") .
692 " WHERE 1 = 1 " . $query;
695 $query .=
" AND active = " .
$ilDB->quote($active);
698 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
702 $r =
$ilDB->query($query);
706 while ($row =
$ilDB->fetchAssoc($r)) {
711 $xmlWriter->setAttachRoles($attach_roles);
713 $xmlWriter->setObjects(
$data);
715 if ($xmlWriter->start()) {
716 return $xmlWriter->getXML();
718 return $this->
raiseError(
'Error in searchUser',
'Server');
724 private function buildSearchQuery(array $a_keyfields,
string $queryOperator, array $a_keyvalues): string
731 $allowed_fields = array(
"firstname",
742 foreach ($a_keyfields as $keyfield) {
743 $keyfield = strtolower($keyfield);
745 if (!in_array($keyfield, $allowed_fields)) {
749 $field_query = array();
750 foreach ($a_keyvalues as $keyvalue) {
751 if (strlen($keyvalue) >= 3) {
752 $field_query [] =
$ilDB->like(
$ilDB->quoteIdentifier($keyfield),
'text',
'%' . $keyvalue .
"%");
755 if (count($field_query)) {
756 $query [] = implode(
" " . strtoupper($queryOperator) .
" ", $field_query);
760 return count($query) ?
" AND ((" . implode(
") OR (", $query) .
"))" :
"AND 0";
766 public function getUserXML(
string $sid, array $a_user_ids,
bool $attach_roles)
777 $rbacsystem =
$DIC[
'rbacsystem'];
778 $access =
$DIC->access();
779 $ilUser =
$DIC[
'ilUser'];
784 if (count($a_user_ids) === 1) {
785 $usr_id = (
int) end($a_user_ids);
786 if ($usr_id === $ilUser->getId()) {
792 return $this->
raiseError(
'Check access failed.',
'Server');
798 $xmlWriter->setAttachRoles($attach_roles);
799 $xmlWriter->setObjects(
$data);
801 if ($xmlWriter->start()) {
802 return $xmlWriter->getXML();
805 return $this->
raiseError(
'User does not exist',
'Client');
819 $ilUser =
$DIC[
'ilUser'];
840 $parts = explode(
'::', $sid);
841 $query =
"SELECT usr_id FROM usr_session "
842 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
846 if (!(
int)
$data[
'usr_id']) {
847 return $this->
raiseError(
'User does not exist',
'Client');
849 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