31 public function login(
string $client,
string $username,
string $password)
39 return $this->
raiseError($e->getMessage(),
'Server');
44 $credentials->setUsername($username);
45 $credentials->setPassword($password);
48 $providers = $provider_factory->getProviders($credentials);
54 $frontend = $frontend_factory->getFrontend(
61 $frontend->authenticate();
63 switch ($status->getStatus()) {
90 $GLOBALS[
'DIC'][
'ilAuthSession']->logout();
97 public function lookupUser(
string $sid,
string $user_name)
106 $user_name = trim($user_name);
108 if ($user_name ===
'') {
109 return $this->
raiseError(
'No username given. Aborting',
'Client');
114 $ilUser = $DIC->user();
115 $access = $DIC->access();
118 strcasecmp($ilUser->getLogin(), $user_name) !== 0 &&
119 !$access->checkAccess(
136 public function importUsers(
string $sid,
int $folder_id,
string $usr_xml,
int $conflict_rule,
bool $send_account_mail)
147 $rbacreview = $DIC[
'rbacreview'];
148 $rbacsystem = $DIC[
'rbacsystem'];
149 $access = $DIC->access();
150 $tree = $DIC[
'tree'];
152 $ilUser = $DIC[
'ilUser'];
153 $ilLog = $DIC[
'ilLog'];
159 @domxml_open_mem($usr_xml, DOMXML_LOAD_PARSING, $error);
162 if (is_array($error)) {
163 foreach ($error as $err) {
164 $msg [] =
"(" . $err[
"line"] .
"," . $err[
"col"] .
"): " . $err[
"errormessage"];
169 $msg = implode(
"\n", $msg);
173 switch ($conflict_rule) {
185 'Missing permission for creating/modifying users accounts' .
self::USER_FOLDER_ID .
' ' . $ilUser->getId(),
192 if ($folder_id !== 0) {
194 if ($folder_id === -1) {
201 if (!$import_folder) {
202 return $this->
raiseError(
'Wrong reference id.',
'Server');
206 if ($import_folder->getType() !==
"usrf" && $import_folder->getType() !==
"cat") {
207 return $this->
raiseError(
'Folder must be a usr folder or a category.',
'Server');
211 if (!$rbacsystem->checkAccess(
'create_usr', $folder_id)) {
213 'Missing permission for creating users within ' . $import_folder->getTitle(),
222 $importParser->setXMLContent($usr_xml);
223 $importParser->startParsing();
225 switch ($importParser->getErrorLevel()) {
238 $importParser->setXMLContent($usr_xml);
240 $importParser->startParsing();
242 $roles = $importParser->getCollectedRoles();
247 $permitted_roles = array();
248 foreach ($roles as $role_id => $role) {
249 if (!is_numeric($role_id)) {
253 if (is_numeric($internalId) && $internalId > 0) {
254 $role_id = $internalId;
255 $role_name = $role_id;
260 $permitted_roles[$role_id] = $role_id;
264 "Could not find role " . $role_name .
". Either you use an invalid/deleted role " .
265 "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.",
271 $global_roles = $rbacreview->getGlobalRoles();
275 foreach ($permitted_roles as $role_id => $role_name) {
276 if ($role_id !=
"") {
277 if (in_array($role_id, $global_roles)) {
286 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)
290 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
295 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
296 if ($rbacreview->isDeleted($rolf[0])
297 || !$rbacsystem->checkAccess(
'write', $rolf[0])) {
299 $lng->txt(
"usrimport_with_specified_role_not_permitted") .
" $role_name ($role_id)",
310 $importParser->setSendMail($send_account_mail);
312 $importParser->setFolderId($folder_id);
313 $importParser->setXMLContent($usr_xml);
315 $importParser->setRoleAssignment($permitted_roles);
317 $importParser->startParsing();
327 static $checked_roles = array();
328 static $global_roles =
null;
330 if (isset($checked_roles[$a_role])) {
331 return $checked_roles[$a_role];
336 $rbacsystem = $DIC[
'rbacsystem'];
337 $rbacreview = $DIC[
'rbacreview'];
338 $ilUser = $DIC[
'ilUser'];
339 $tree = $DIC[
'tree'];
340 $ilLog = $DIC[
'ilLog'];
342 $locations = $rbacreview->getFoldersAssignedToRole($a_role,
true);
347 $ilLog->write(__METHOD__ .
': Check global role');
351 $ilLog->write(__METHOD__ .
': ' . $a_folder);
353 $ilLog->write(__METHOD__ .
': No assignment allowed');
354 $checked_roles[$a_role] =
false;
360 $ilLog->write(__METHOD__ .
': Anonymous role chosen.');
361 $checked_roles[$a_role] =
false;
366 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
367 $ilLog->write(__METHOD__ .
': System role assignment forbidden.');
368 $checked_roles[$a_role] =
false;
373 $ilLog->write(__METHOD__ .
': Assignment allowed.');
374 $checked_roles[$a_role] =
true;
377 $ilLog->write(__METHOD__ .
': Check local role.');
380 $rolfs = $rbacreview->getFoldersAssignedToRole($a_role,
true);
387 if ($rbacreview->isDeleted($rolf)
388 || !$rbacsystem->checkAccess(
'edit_permission', $rolf)) {
389 $ilLog->write(__METHOD__ .
': Role deleted or no permission.');
390 $checked_roles[$a_role] =
false;
401 if ($a_folder !==
self::USER_FOLDER_ID && $a_folder !== 0 && !$tree->isGrandChild($a_folder, $rolf)) {
402 $ilLog->write(__METHOD__ .
': Not in path of category.');
403 $checked_roles[$a_role] =
false;
406 $ilLog->write(__METHOD__ .
': Assignment allowed.');
407 $checked_roles[$a_role] =
true;
427 $ilDB = $DIC[
'ilDB'];
428 $tree = $DIC[
'tree'];
429 $rbacreview = $DIC[
'rbacreview'];
430 $rbacsystem = $DIC[
'rbacsystem'];
431 $access = $DIC->access();
433 if ($ref_id === -1) {
441 return $this->
raiseError(
'Access denied',
"Client");
444 $object = $this->
checkObjectAccess($ref_id, array(
"crs",
"cat",
"grp",
"usrf",
"sess"),
"read",
true);
450 switch ($object->getType()) {
460 $roles = $object->__getLocalRoles();
462 foreach ($roles as $role_id) {
463 $data = array_merge($rbacreview->assignedUsers($role_id),
$data);
469 $member_ids = $object->getGroupMemberIds();
473 $course_ref_id = $tree->checkForParentType($ref_id,
'crs');
474 if (!$course_ref_id) {
475 return $this->
raiseError(
"No course for session",
"Client");
480 $member_ids = array_keys($event_part->getParticipants());
486 $xmlWriter->setObjects(
$data);
487 $xmlWriter->setAttachRoles($attachRoles);
489 if ($xmlWriter->start()) {
490 return $xmlWriter->getXML();
499 public function getUserForRole(
string $sid,
int $role_id,
bool $attachRoles,
int $active)
510 $ilDB = $DIC[
'ilDB'];
511 $rbacreview = $DIC->rbac()->review();
512 $tree = $DIC->repositoryTree();
513 $ilUser = $DIC->user();
514 $access = $DIC->access();
516 $global_roles = $rbacreview->getGlobalRoles();
518 if (in_array($role_id, $global_roles,
true)) {
521 !in_array(
SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()),
true)) {
522 return $this->
raiseError(
"Role access not permitted. ($role_id)",
"Server");
526 $rolfs = $rbacreview->getFoldersAssignedToRole($role_id,
true);
527 $access_granted =
true;
528 foreach ($rolfs as $rolf) {
529 if ($tree->isDeleted($rolf)) {
530 $access_granted =
false;
536 if (!$access->checkAccess(
'manage_members',
'', $rolf)) {
537 $access_granted =
false;
541 if (!$access->checkAccess(
'edit_permission',
'', $rolf)) {
542 $access_granted =
false;
549 $access_granted =
false;
551 if (!$access_granted || !count($rolfs)) {
552 return $this->
raiseError(
'Role access not permitted. ' .
'(' . $role_id .
')',
'Server');
559 $xmlWriter->setAttachRoles($attachRoles);
561 $xmlWriter->setObjects(
$data);
563 if ($xmlWriter->start()) {
564 return $xmlWriter->getXML();
566 return $this->
raiseError(
'Error in getUsersForRole',
'Server');
575 $xmlResultSet->addColumn(
"userid");
576 $xmlResultSet->addColumn(
"login");
577 $xmlResultSet->addColumn(
"action");
578 $xmlResultSet->addColumn(
"message");
580 foreach ($a_array as $username =>
$messages) {
583 $xmlRow->setValue(0, 0);
584 $xmlRow->setValue(1, $username);
585 $xmlRow->setValue(2,
"");
586 $xmlRow->setValue(3, $message);
588 $xmlResultSet->addRow($xmlRow);
594 if ($xml_writer->start()) {
595 return $xml_writer->getXML();
598 return $this->
raiseError(
'Error in __getImportProtocolAsXML',
'Server');
608 $xmlResultSet->addColumn(
"userid");
609 $xmlResultSet->addColumn(
"login");
610 $xmlResultSet->addColumn(
"action");
611 $xmlResultSet->addColumn(
"message");
613 if (count($a_array)) {
614 foreach ($a_array as $username =>
$message) {
616 $xmlRow->setValue(0, $username);
617 $xmlRow->setValue(1,
$message[
"login"]);
618 $xmlRow->setValue(2,
$message[
"action"]);
619 $xmlRow->setValue(3,
$message[
"message"]);
621 $xmlResultSet->addRow($xmlRow);
627 if ($xml_writer->start()) {
628 return $xml_writer->getXML();
631 return $this->
raiseError(
'Error in __getUserMappingAsXML',
'Server');
647 string $query_operator,
661 $ilDB = $DIC[
'ilDB'];
662 $access = $DIC->access();
665 return $this->
raiseError(
'Check access failed.',
'Server');
667 if (!count($a_keyfields)) {
668 $this->
raiseError(
'At least one keyfield is needed',
'Client');
671 if (!count($a_keyvalues)) {
672 $this->
raiseError(
'At least one keyvalue is needed',
'Client');
675 if (strcasecmp($query_operator,
"and") !== 0 || strcasecmp($query_operator,
"or") !== 0) {
676 $this->
raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
679 $query = $this->
buildSearchQuery($a_keyfields, $query_operator, $a_keyvalues);
681 $query =
"SELECT usr_data.*, usr_pref.value AS language 684 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = " .
685 $ilDB->quote(
"language",
"text") .
686 " WHERE 1 = 1 " . $query;
689 $query .=
" AND active = " .
$ilDB->quote($active);
692 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
700 while ($row =
$ilDB->fetchAssoc(
$r)) {
705 $xmlWriter->setAttachRoles($attach_roles);
707 $xmlWriter->setObjects(
$data);
709 if ($xmlWriter->start()) {
710 return $xmlWriter->getXML();
712 return $this->
raiseError(
'Error in searchUser',
'Server');
718 private function buildSearchQuery(array $a_keyfields,
string $queryOperator, array $a_keyvalues): string
722 $ilDB = $DIC[
'ilDB'];
725 $allowed_fields = array(
"firstname",
736 foreach ($a_keyfields as $keyfield) {
737 $keyfield = strtolower($keyfield);
739 if (!in_array($keyfield, $allowed_fields)) {
743 $field_query = array();
744 foreach ($a_keyvalues as $keyvalue) {
745 if (strlen($keyvalue) >= 3) {
746 $field_query [] =
$ilDB->like(
$ilDB->quoteIdentifier($keyfield),
'text',
'%' . $keyvalue .
"%");
749 if (count($field_query)) {
750 $query [] = implode(
" " . strtoupper($queryOperator) .
" ", $field_query);
754 return count($query) ?
" AND ((" . implode(
") OR (", $query) .
"))" :
"AND 0";
760 public function getUserXML(
string $sid, array $a_user_ids,
bool $attach_roles)
771 $rbacsystem = $DIC[
'rbacsystem'];
772 $access = $DIC->access();
773 $ilUser = $DIC[
'ilUser'];
774 $ilDB = $DIC[
'ilDB'];
778 if (count($a_user_ids) === 1) {
779 $usr_id = (
int) end($a_user_ids);
780 if ($usr_id === $ilUser->getId()) {
786 return $this->
raiseError(
'Check access failed.',
'Server');
792 $xmlWriter->setAttachRoles($attach_roles);
793 $xmlWriter->setObjects(
$data);
795 if ($xmlWriter->start()) {
796 return $xmlWriter->getXML();
799 return $this->
raiseError(
'User does not exist',
'Client');
813 $ilUser = $DIC[
'ilUser'];
832 $ilDB = $DIC[
'ilDB'];
834 $parts = explode(
'::', $sid);
835 $query =
"SELECT usr_id FROM usr_session " 836 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
840 if (!(
int)
$data[
'usr_id']) {
841 $this->
raiseError(
'User does not exist',
'Client');
843 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
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.
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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)
class ilEventParticipants
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)