38 public function login(
string $client,
string $username,
string $password)
46 return $this->
raiseError($e->getMessage(),
'Server');
51 $credentials->setUsername($username);
52 $credentials->setPassword($password);
55 $providers = $provider_factory->getProviders($credentials);
61 $frontend = $frontend_factory->getFrontend(
68 $frontend->authenticate();
70 switch ($status->getStatus()) {
97 $GLOBALS[
'DIC'][
'ilAuthSession']->logout();
113 $user_name = trim($user_name);
115 if ($user_name ===
'') {
116 return $this->
raiseError(
'No username given. Aborting',
'Client');
121 $ilUser = $DIC->user();
122 $access = $DIC->access();
125 strcasecmp($ilUser->getLogin(), $user_name) !== 0 &&
126 !$access->checkAccess(
143 public function importUsers(
string $sid,
int $folder_id,
string $usr_xml,
int $conflict_rule,
bool $send_account_mail)
154 $rbacreview = $DIC[
'rbacreview'];
155 $rbacsystem = $DIC[
'rbacsystem'];
156 $access = $DIC->access();
157 $tree = $DIC[
'tree'];
159 $ilUser = $DIC[
'ilUser'];
160 $ilLog = $DIC[
'ilLog'];
166 @domxml_open_mem($usr_xml, DOMXML_LOAD_PARSING, $error);
169 if (is_array($error)) {
170 foreach ($error as $err) {
171 $msg [] =
"(" . $err[
"line"] .
"," . $err[
"col"] .
"): " . $err[
"errormessage"];
176 $msg = implode(
"\n", $msg);
180 switch ($conflict_rule) {
192 'Missing permission for creating/modifying users accounts' .
self::USER_FOLDER_ID .
' ' . $ilUser->getId(),
199 if ($folder_id !== 0) {
201 if ($folder_id === -1) {
208 if (!$import_folder) {
209 return $this->
raiseError(
'Wrong reference id.',
'Server');
213 if ($import_folder->getType() !==
"usrf" && $import_folder->getType() !==
"cat") {
214 return $this->
raiseError(
'Folder must be a usr folder or a category.',
'Server');
218 if (!$rbacsystem->checkAccess(
'create_usr', $folder_id)) {
220 'Missing permission for creating users within ' . $import_folder->getTitle(),
229 $importParser->setXMLContent($usr_xml);
230 $importParser->startParsing();
232 switch ($importParser->getErrorLevel()) {
245 $importParser->setXMLContent($usr_xml);
247 $importParser->startParsing();
249 $roles = $importParser->getCollectedRoles();
254 $permitted_roles = array();
255 foreach ($roles as $role_id => $role) {
256 if (!is_numeric($role_id)) {
260 if (is_numeric($internalId) && $internalId > 0) {
261 $role_id = $internalId;
262 $role_name = $role_id;
267 $permitted_roles[$role_id] = $role_id;
271 "Could not find role " . $role_name .
". Either you use an invalid/deleted role " .
272 "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.",
278 $global_roles = $rbacreview->getGlobalRoles();
282 foreach ($permitted_roles as $role_id => $role_name) {
283 if ($role_id !=
"") {
284 if (in_array($role_id, $global_roles)) {
293 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)
297 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
302 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
303 if ($rbacreview->isDeleted($rolf[0])
304 || !$rbacsystem->checkAccess(
'write', $rolf[0])) {
306 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
317 $importParser->setSendMail($send_account_mail);
319 $importParser->setFolderId($folder_id);
320 $importParser->setXMLContent($usr_xml);
322 $importParser->setRoleAssignment($permitted_roles);
324 $importParser->startParsing();
334 static $checked_roles = array();
335 static $global_roles = null;
337 if (isset($checked_roles[$a_role])) {
338 return $checked_roles[$a_role];
343 $rbacsystem = $DIC[
'rbacsystem'];
344 $rbacreview = $DIC[
'rbacreview'];
345 $ilUser = $DIC[
'ilUser'];
346 $tree = $DIC[
'tree'];
347 $ilLog = $DIC[
'ilLog'];
349 $locations = $rbacreview->getFoldersAssignedToRole($a_role,
true);
354 $ilLog->write(__METHOD__ .
': Check global role');
358 $ilLog->write(__METHOD__ .
': ' . $a_folder);
360 $ilLog->write(__METHOD__ .
': No assignment allowed');
361 $checked_roles[$a_role] =
false;
367 $ilLog->write(__METHOD__ .
': Anonymous role chosen.');
368 $checked_roles[$a_role] =
false;
373 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
374 $ilLog->write(__METHOD__ .
': System role assignment forbidden.');
375 $checked_roles[$a_role] =
false;
380 $ilLog->write(__METHOD__ .
': Assignment allowed.');
381 $checked_roles[$a_role] =
true;
384 $ilLog->write(__METHOD__ .
': Check local role.');
387 $rolfs = $rbacreview->getFoldersAssignedToRole($a_role,
true);
394 if ($rbacreview->isDeleted($rolf)
395 || !$rbacsystem->checkAccess(
'edit_permission', $rolf)) {
396 $ilLog->write(__METHOD__ .
': Role deleted or no permission.');
397 $checked_roles[$a_role] =
false;
408 if ($a_folder !==
self::USER_FOLDER_ID && $a_folder !== 0 && !$tree->isGrandChild($a_folder, $rolf)) {
409 $ilLog->write(__METHOD__ .
': Not in path of category.');
410 $checked_roles[$a_role] =
false;
413 $ilLog->write(__METHOD__ .
': Assignment allowed.');
414 $checked_roles[$a_role] =
true;
434 $ilDB = $DIC[
'ilDB'];
435 $tree = $DIC[
'tree'];
436 $rbacreview = $DIC[
'rbacreview'];
437 $rbacsystem = $DIC[
'rbacsystem'];
438 $access = $DIC->access();
440 if ($ref_id === -1) {
448 return $this->
raiseError(
'Access denied',
"Client");
451 $object = $this->
checkObjectAccess($ref_id, array(
"crs",
"cat",
"grp",
"usrf",
"sess"),
"read",
true);
457 switch ($object->getType()) {
467 $roles = $object->__getLocalRoles();
469 foreach ($roles as $role_id) {
470 $data = array_merge($rbacreview->assignedUsers($role_id),
$data);
476 $member_ids = $object->getGroupMemberIds();
480 $course_ref_id = $tree->checkForParentType($ref_id,
'crs');
481 if (!$course_ref_id) {
482 return $this->
raiseError(
"No course for session",
"Client");
487 $member_ids = array_keys($event_part->getParticipants());
493 $xmlWriter->setObjects(
$data);
494 $xmlWriter->setAttachRoles($attachRoles);
496 if ($xmlWriter->start()) {
497 return $xmlWriter->getXML();
506 public function getUserForRole(
string $sid,
int $role_id,
bool $attachRoles,
int $active)
517 $ilDB = $DIC[
'ilDB'];
518 $rbacreview = $DIC->rbac()->review();
519 $tree = $DIC->repositoryTree();
520 $ilUser = $DIC->user();
521 $access = $DIC->access();
523 $global_roles = $rbacreview->getGlobalRoles();
525 if (in_array($role_id, $global_roles,
true)) {
528 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
529 return $this->
raiseError(
"Role access not permitted. ($role_id)",
"Server");
533 $rolfs = $rbacreview->getFoldersAssignedToRole($role_id,
true);
534 $access_granted =
true;
535 foreach ($rolfs as $rolf) {
536 if ($tree->isDeleted($rolf)) {
537 $access_granted =
false;
543 if (!$access->checkAccess(
'manage_members',
'', $rolf)) {
544 $access_granted =
false;
548 if (!$access->checkAccess(
'edit_permission',
'', $rolf)) {
549 $access_granted =
false;
556 $access_granted =
false;
558 if (!$access_granted || !count($rolfs)) {
559 return $this->
raiseError(
'Role access not permitted. ' .
'(' . $role_id .
')',
'Server');
566 $xmlWriter->setAttachRoles($attachRoles);
568 $xmlWriter->setObjects(
$data);
570 if ($xmlWriter->start()) {
571 return $xmlWriter->getXML();
573 return $this->
raiseError(
'Error in getUsersForRole',
'Server');
582 $xmlResultSet->addColumn(
"userid");
583 $xmlResultSet->addColumn(
"login");
584 $xmlResultSet->addColumn(
"action");
585 $xmlResultSet->addColumn(
"message");
587 foreach ($a_array as $username => $messages) {
590 $xmlRow->setValue(0, 0);
591 $xmlRow->setValue(1, $username);
592 $xmlRow->setValue(2,
"");
593 $xmlRow->setValue(3, $message);
595 $xmlResultSet->addRow($xmlRow);
601 if ($xml_writer->start()) {
602 return $xml_writer->getXML();
605 return $this->
raiseError(
'Error in __getImportProtocolAsXML',
'Server');
615 $xmlResultSet->addColumn(
"userid");
616 $xmlResultSet->addColumn(
"login");
617 $xmlResultSet->addColumn(
"action");
618 $xmlResultSet->addColumn(
"message");
620 if (count($a_array)) {
621 foreach ($a_array as $username =>
$message) {
623 $xmlRow->setValue(0, $username);
624 $xmlRow->setValue(1,
$message[
"login"]);
625 $xmlRow->setValue(2,
$message[
"action"]);
626 $xmlRow->setValue(3,
$message[
"message"]);
628 $xmlResultSet->addRow($xmlRow);
634 if ($xml_writer->start()) {
635 return $xml_writer->getXML();
638 return $this->
raiseError(
'Error in __getUserMappingAsXML',
'Server');
654 string $query_operator,
668 $ilDB = $DIC[
'ilDB'];
669 $access = $DIC->access();
672 return $this->
raiseError(
'Check access failed.',
'Server');
674 if (!count($a_keyfields)) {
675 $this->
raiseError(
'At least one keyfield is needed',
'Client');
678 if (!count($a_keyvalues)) {
679 $this->
raiseError(
'At least one keyvalue is needed',
'Client');
682 if (strcasecmp($query_operator,
"and") !== 0 || strcasecmp($query_operator,
"or") !== 0) {
683 $this->
raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
686 $query = $this->
buildSearchQuery($a_keyfields, $query_operator, $a_keyvalues);
688 $query =
"SELECT usr_data.*, usr_pref.value AS language 691 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = " .
692 $ilDB->quote(
"language",
"text") .
693 " WHERE 1 = 1 " . $query;
696 $query .=
" AND active = " .
$ilDB->quote($active);
699 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
707 while ($row =
$ilDB->fetchAssoc(
$r)) {
712 $xmlWriter->setAttachRoles($attach_roles);
714 $xmlWriter->setObjects(
$data);
716 if ($xmlWriter->start()) {
717 return $xmlWriter->getXML();
719 return $this->
raiseError(
'Error in searchUser',
'Server');
725 private function buildSearchQuery(array $a_keyfields,
string $queryOperator, array $a_keyvalues): string
729 $ilDB = $DIC[
'ilDB'];
732 $allowed_fields = array(
"firstname",
743 foreach ($a_keyfields as $keyfield) {
744 $keyfield = strtolower($keyfield);
746 if (!in_array($keyfield, $allowed_fields)) {
750 $field_query = array();
751 foreach ($a_keyvalues as $keyvalue) {
752 if (strlen($keyvalue) >= 3) {
753 $field_query [] =
$ilDB->like(
$ilDB->quoteIdentifier($keyfield),
'text',
'%' . $keyvalue .
"%");
756 if (count($field_query)) {
757 $query [] = implode(
" " . strtoupper($queryOperator) .
" ", $field_query);
761 return count($query) ?
" AND ((" . implode(
") OR (", $query) .
"))" :
"AND 0";
767 public function getUserXML(
string $sid, array $a_user_ids,
bool $attach_roles)
778 $rbacsystem = $DIC[
'rbacsystem'];
779 $access = $DIC->access();
780 $ilUser = $DIC[
'ilUser'];
781 $ilDB = $DIC[
'ilDB'];
785 if (count($a_user_ids) === 1) {
786 $usr_id = (
int) end($a_user_ids);
787 if ($usr_id === $ilUser->getId()) {
793 return $this->
raiseError(
'Check access failed.',
'Server');
799 $xmlWriter->setAttachRoles($attach_roles);
800 $xmlWriter->setObjects(
$data);
802 if ($xmlWriter->start()) {
803 return $xmlWriter->getXML();
806 return $this->
raiseError(
'User does not exist',
'Client');
820 $ilUser = $DIC[
'ilUser'];
839 $ilDB = $DIC[
'ilDB'];
841 $parts = explode(
'::', $sid);
842 $query =
"SELECT usr_id FROM usr_session " 843 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
847 if (!(
int)
$data[
'usr_id']) {
848 $this->
raiseError(
'User does not exist',
'Client');
850 return (
int) $data[
'usr_id'];
static _getUsersForRole(int $role_id, int $active=-1)
return array of complete users which belong to a specific role
XML Writer for XMLResultSet.
static getLogger(string $a_component_id)
Get component logger.
buildSearchQuery(array $a_keyfields, string $queryOperator, array $a_keyvalues)
create search term according to parameters
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const STATUS_AUTHENTICATION_FAILED
getUserMappingAsXML(array $a_array)
return user mapping as xml
raiseError(string $a_message, $a_code)
isPermittedRole(int $a_folder, int $a_role)
Row Class for XMLResultSet.
static _getUsersForGroup(array $a_mem_ids, int $active=-1)
return user data for group members
const IL_FAIL_ON_CONFLICT
static _lookupObjId(int $ref_id)
static getUserIdByLogin(string $a_login)
static getNewMailsData(ilObjUser $user, int $leftInterval=0)
static _lookupTitle(int $obj_id)
XML writer class Class to simplify manual writing of xml documents.
checkSession(string $sid)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static _getUserData(array $a_internalids)
return user data for given user ids
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 ...
login(string $client, string $username, string $password)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getUsersForContainer(string $sid, int $ref_id, bool $attachRoles, int $active)
const STATUS_AUTHENTICATED
lookupUser(string $sid, string $user_name)
static _getUsersForFolder(int $ref_id, int $active)
get users for a category or from system folder
static getInstance()
Get status instance.
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
static setClosingContext(int $a_context)
set closing context (for statistics)
getUserIdBySid(string $sid)
const IL_UPDATE_ON_CONFLICT
importUsers(string $sid, int $folder_id, string $usr_xml, int $conflict_rule, bool $send_account_mail)
searchUser(string $sid, array $a_keyfields, string $query_operator, array $a_keyvalues, bool $attach_roles, int $active)
return user xml following dtd 3.7
static _getAssignUsersStatus(int $a_role_id)
static _lookupType(int $id, bool $reference=false)
getUserXML(string $sid, array $a_user_ids, bool $attach_roles)
static _getUsersForIds(array $a_mem_ids, int $active=-1, int $timelimitowner=-1)
return user data for given user id
getImportProtocolAsXML(array $a_array)
Create XML ResultSet.
const IL_IGNORE_ON_CONFLICT
getUserForRole(string $sid, int $role_id, bool $attachRoles, int $active)