30 include_once
'./webservice/soap/classes/class.ilSoapAdministration.php';
39 public function login(
string $client,
string $username,
string $password)
47 return $this->
raiseError($e->getMessage(),
'Server');
51 include_once
'./Services/Authentication/classes/Frontend/class.ilAuthFrontendCredentials.php';
53 $credentials->setUsername($username);
54 $credentials->setPassword($password);
56 include_once
'./Services/Authentication/classes/Provider/class.ilAuthProviderFactory.php';
58 $providers = $provider_factory->getProviders($credentials);
60 include_once
'./Services/Authentication/classes/class.ilAuthStatus.php';
63 include_once
'./Services/Authentication/classes/Frontend/class.ilAuthFrontendFactory.php';
66 $frontend = $frontend_factory->getFrontend(
73 $frontend->authenticate();
75 switch ($status->getStatus()) {
101 include_once
'./Services/Authentication/classes/class.ilSession.php';
103 $GLOBALS[
'DIC'][
'ilAuthSession']->logout();
119 $user_name = trim($user_name);
121 if ($user_name ===
'') {
122 return $this->
raiseError(
'No username given. Aborting',
'Client');
128 $access = $DIC->access();
131 strcasecmp(
$ilUser->getLogin(), $user_name) !== 0 &&
132 !$access->checkAccess(
149 public function importUsers(
string $sid,
int $folder_id,
string $usr_xml,
int $conflict_rule,
bool $send_account_mail)
158 include_once
'./Services/User/classes/class.ilUserImportParser.php';
159 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
160 include_once
'./Services/Object/classes/class.ilObjectFactory.php';
163 $rbacreview = $DIC[
'rbacreview'];
164 $rbacsystem = $DIC[
'rbacsystem'];
165 $access = $DIC->access();
166 $tree = $DIC[
'tree'];
169 $ilLog = $DIC[
'ilLog'];
178 if (is_array($error)) {
179 foreach ($error as $err) {
180 $msg [] =
"(" . $err[
"line"] .
"," . $err[
"col"] .
"): " . $err[
"errormessage"];
185 $msg = implode(
"\n", $msg);
189 switch ($conflict_rule) {
208 if ($folder_id !== 0) {
210 if ($folder_id === -1) {
217 if (!$import_folder) {
218 return $this->
raiseError(
'Wrong reference id.',
'Server');
222 if ($import_folder->getType() !==
"usrf" && $import_folder->getType() !==
"cat") {
223 return $this->
raiseError(
'Folder must be a usr folder or a category.',
'Server');
227 if (!$rbacsystem->checkAccess(
'create_usr', $folder_id)) {
229 'Missing permission for creating users within ' . $import_folder->getTitle(),
238 $importParser->setXMLContent($usr_xml);
239 $importParser->startParsing();
241 switch ($importParser->getErrorLevel()) {
254 $importParser->setXMLContent($usr_xml);
256 $importParser->startParsing();
258 $roles = $importParser->getCollectedRoles();
263 $permitted_roles = array();
264 foreach ($roles as $role_id => $role) {
265 if (!is_numeric($role_id)) {
269 if (is_numeric($internalId) && $internalId > 0) {
270 $role_id = $internalId;
271 $role_name = $role_id;
276 $permitted_roles[$role_id] = $role_id;
280 "Could not find role " . $role_name .
". Either you use an invalid/deleted role " .
281 "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.",
287 $global_roles = $rbacreview->getGlobalRoles();
291 foreach ($permitted_roles as $role_id => $role_name) {
292 if ($role_id !=
"") {
293 if (in_array($role_id, $global_roles)) {
306 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
311 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
312 if ($rbacreview->isDeleted($rolf[0])
313 || !$rbacsystem->checkAccess(
'write', $rolf[0])) {
315 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
326 $importParser->setSendMail($send_account_mail);
328 $importParser->setFolderId($folder_id);
329 $importParser->setXMLContent($usr_xml);
331 $importParser->setRoleAssignment($permitted_roles);
333 $importParser->startParsing();
343 static $checked_roles = array();
344 static $global_roles = null;
346 if (isset($checked_roles[$a_role])) {
347 return $checked_roles[$a_role];
352 $rbacsystem = $DIC[
'rbacsystem'];
353 $rbacreview = $DIC[
'rbacreview'];
355 $tree = $DIC[
'tree'];
356 $ilLog = $DIC[
'ilLog'];
358 $locations = $rbacreview->getFoldersAssignedToRole($a_role,
true);
363 $ilLog->write(__METHOD__ .
': Check global role');
367 $ilLog->write(__METHOD__ .
': ' . $a_folder);
368 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
370 $ilLog->write(__METHOD__ .
': No assignment allowed');
371 $checked_roles[$a_role] =
false;
377 $ilLog->write(__METHOD__ .
': Anonymous role chosen.');
378 $checked_roles[$a_role] =
false;
384 $ilLog->write(__METHOD__ .
': System role assignment forbidden.');
385 $checked_roles[$a_role] =
false;
390 $ilLog->write(__METHOD__ .
': Assignment allowed.');
391 $checked_roles[$a_role] =
true;
394 $ilLog->write(__METHOD__ .
': Check local role.');
397 $rolfs = $rbacreview->getFoldersAssignedToRole($a_role,
true);
404 if ($rbacreview->isDeleted($rolf)
405 || !$rbacsystem->checkAccess(
'edit_permission', $rolf)) {
406 $ilLog->write(__METHOD__ .
': Role deleted or no permission.');
407 $checked_roles[$a_role] =
false;
418 if ($a_folder !==
self::USER_FOLDER_ID && $a_folder !== 0 && !$tree->isGrandChild($a_folder, $rolf)) {
419 $ilLog->write(__METHOD__ .
': Not in path of category.');
420 $checked_roles[$a_role] =
false;
423 $ilLog->write(__METHOD__ .
': Assignment allowed.');
424 $checked_roles[$a_role] =
true;
444 $ilDB = $DIC[
'ilDB'];
445 $tree = $DIC[
'tree'];
446 $rbacreview = $DIC[
'rbacreview'];
447 $rbacsystem = $DIC[
'rbacsystem'];
448 $access = $DIC->access();
450 if ($ref_id === -1) {
458 return $this->
raiseError(
'Access denied',
"Client");
461 $object = $this->
checkObjectAccess($ref_id, array(
"crs",
"cat",
"grp",
"usrf",
"sess"),
"read",
true);
467 switch ($object->getType()) {
477 $roles = $object->__getLocalRoles();
479 foreach ($roles as $role_id) {
480 $data = array_merge($rbacreview->assignedUsers($role_id),
$data);
486 $member_ids = $object->getGroupMemberIds();
490 $course_ref_id = $tree->checkForParentType($ref_id,
'crs');
491 if (!$course_ref_id) {
492 return $this->
raiseError(
"No course for session",
"Client");
496 include_once
'Modules/Session/classes/class.ilEventParticipants.php';
498 $member_ids = array_keys($event_part->getParticipants());
503 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
506 $xmlWriter->setObjects(
$data);
507 $xmlWriter->setAttachRoles($attachRoles);
509 if ($xmlWriter->start()) {
510 return $xmlWriter->getXML();
519 public function getUserForRole(
string $sid,
int $role_id,
bool $attachRoles,
int $active)
528 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
531 $ilDB = $DIC[
'ilDB'];
532 $rbacreview = $DIC->rbac()->review();
533 $tree = $DIC->repositoryTree();
535 $access = $DIC->access();
537 $global_roles = $rbacreview->getGlobalRoles();
539 if (in_array($role_id, $global_roles,
true)) {
543 return $this->
raiseError(
"Role access not permitted. ($role_id)",
"Server");
547 $rolfs = $rbacreview->getFoldersAssignedToRole($role_id,
true);
548 $access_granted =
true;
549 foreach ($rolfs as $rolf) {
550 if ($tree->isDeleted($rolf)) {
551 $access_granted =
false;
557 if (!$access->checkAccess(
'manage_members',
'', $rolf)) {
558 $access_granted =
false;
562 if (!$access->checkAccess(
'edit_permission',
'', $rolf)) {
563 $access_granted =
false;
570 $access_granted =
false;
572 if (!$access_granted || !count($rolfs)) {
573 return $this->
raiseError(
'Role access not permitted. ' .
'(' . $role_id .
')',
'Server');
578 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
581 $xmlWriter->setAttachRoles($attachRoles);
583 $xmlWriter->setObjects(
$data);
585 if ($xmlWriter->start()) {
586 return $xmlWriter->getXML();
588 return $this->
raiseError(
'Error in getUsersForRole',
'Server');
596 include_once
'./webservice/soap/classes/class.ilXMLResultSet.php';
597 include_once
'./webservice/soap/classes/class.ilXMLResultSetWriter.php';
600 $xmlResultSet->addColumn(
"userid");
601 $xmlResultSet->addColumn(
"login");
602 $xmlResultSet->addColumn(
"action");
603 $xmlResultSet->addColumn(
"message");
605 foreach ($a_array as $username =>
$messages) {
608 $xmlRow->setValue(0, 0);
609 $xmlRow->setValue(1, $username);
610 $xmlRow->setValue(2,
"");
611 $xmlRow->setValue(3, $message);
613 $xmlResultSet->addRow($xmlRow);
619 if ($xml_writer->start()) {
620 return $xml_writer->getXML();
623 return $this->
raiseError(
'Error in __getImportProtocolAsXML',
'Server');
632 include_once
'./webservice/soap/classes/class.ilXMLResultSet.php';
633 include_once
'./webservice/soap/classes/class.ilXMLResultSetWriter.php';
636 $xmlResultSet->addColumn(
"userid");
637 $xmlResultSet->addColumn(
"login");
638 $xmlResultSet->addColumn(
"action");
639 $xmlResultSet->addColumn(
"message");
641 if (count($a_array)) {
642 foreach ($a_array as $username =>
$message) {
644 $xmlRow->setValue(0, $username);
645 $xmlRow->setValue(1,
$message[
"login"]);
646 $xmlRow->setValue(2,
$message[
"action"]);
647 $xmlRow->setValue(3,
$message[
"message"]);
649 $xmlResultSet->addRow($xmlRow);
655 if ($xml_writer->start()) {
656 return $xml_writer->getXML();
659 return $this->
raiseError(
'Error in __getUserMappingAsXML',
'Server');
675 string $query_operator,
689 $ilDB = $DIC[
'ilDB'];
690 $access = $DIC->access();
693 return $this->
raiseError(
'Check access failed.',
'Server');
695 if (!count($a_keyfields)) {
696 $this->
raiseError(
'At least one keyfield is needed',
'Client');
699 if (!count($a_keyvalues)) {
700 $this->
raiseError(
'At least one keyvalue is needed',
'Client');
703 if (strcasecmp($query_operator,
"and") !== 0 || strcasecmp($query_operator,
"or") !== 0) {
704 $this->
raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
709 $query =
"SELECT usr_data.*, usr_pref.value AS language 712 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = " .
713 $ilDB->quote(
"language",
"text") .
717 $query .=
" AND active = " .
$ilDB->quote($active);
720 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
728 while ($row =
$ilDB->fetchAssoc($r)) {
732 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
735 $xmlWriter->setAttachRoles($attach_roles);
737 $xmlWriter->setObjects(
$data);
739 if ($xmlWriter->start()) {
740 return $xmlWriter->getXML();
742 return $this->
raiseError(
'Error in searchUser',
'Server');
748 private function buildSearchQuery(array $a_keyfields,
string $queryOperator, array $a_keyvalues) : string
752 $ilDB = $DIC[
'ilDB'];
755 $allowed_fields = array(
"firstname",
766 foreach ($a_keyfields as $keyfield) {
767 $keyfield = strtolower($keyfield);
769 if (!in_array($keyfield, $allowed_fields)) {
773 $field_query = array();
774 foreach ($a_keyvalues as $keyvalue) {
775 if (strlen($keyvalue) >= 3) {
776 $field_query [] =
$ilDB->like(
$ilDB->quoteIdentifier($keyfield),
'text',
'%' . $keyvalue .
"%");
779 if (count($field_query)) {
780 $query [] = implode(
" " . strtoupper($queryOperator) .
" ", $field_query);
784 return count(
$query) ?
" AND ((" . implode(
") OR (",
$query) .
"))" :
"AND 0";
790 public function getUserXML(
string $sid, array $a_user_ids,
bool $attach_roles)
801 $rbacsystem = $DIC[
'rbacsystem'];
802 $access = $DIC->access();
804 $ilDB = $DIC[
'ilDB'];
808 if (count($a_user_ids) === 1) {
809 $usr_id = (
int) end($a_user_ids);
810 if ($usr_id ===
$ilUser->getId()) {
816 return $this->
raiseError(
'Check access failed.',
'Server');
821 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
823 $xmlWriter->setAttachRoles($attach_roles);
824 $xmlWriter->setObjects(
$data);
826 if ($xmlWriter->start()) {
827 return $xmlWriter->getXML();
830 return $this->
raiseError(
'User does not exist',
'Client');
863 $ilDB = $DIC[
'ilDB'];
865 $parts = explode(
'::', $sid);
866 $query =
"SELECT usr_id FROM usr_session " 867 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
871 if (!(
int)
$data[
'usr_id']) {
872 $this->
raiseError(
'User does not exist',
'Client');
874 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
Factory for auth frontend classes.
raiseError(string $a_message, $a_code)
isPermittedRole(int $a_folder, int $a_role)
Row Class for XMLResultSet.
const IL_EXTRACT_ROLES
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_FAIL_ON_CONFLICT
static _getUsersForGroup(array $a_mem_ids, int $active=-1)
return user data for group members
static _lookupObjId(int $ref_id)
static getUserIdByLogin(string $a_login)
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNewMailsData(ilObjUser $user, int $leftInterval=0)
static _lookupTitle(int $obj_id)
domxml_open_mem($str, $mode=0, &$error=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkSession(string $sid)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
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)
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
const IL_UPDATE_ON_CONFLICT
getImportProtocolAsXML(array $a_array)
Create XML ResultSet.
const DOMXML_LOAD_PARSING
const IL_IGNORE_ON_CONFLICT
getUserForRole(string $sid, int $role_id, bool $attachRoles, int $active)