19declare(strict_types=1);
48 private string $dn =
'';
55 $this->db =
$DIC->database();
56 $this->
logger = $DIC->logger()->auth();
57 $this->ilErr =
$DIC[
'ilErr'];
58 $this->
lng = $DIC->language();
60 $this->rule_id = $a_rule_id;
78 $query =
'SELECT COUNT(*) num FROM ldap_role_assignments ' .
79 'WHERE add_on_update = 1 ' .
80 'OR remove_on_update = 1 ';
90 public function matches(array $a_user_data): bool
100 if (!isset($a_user_data[$attn])) {
104 if (!is_array($a_user_data[$attn])) {
105 $attribute_val = array(0 => $a_user_data[$attn]);
107 $attribute_val = $a_user_data[$attn];
110 foreach ($attribute_val as $value) {
127 $pattern = str_replace(
'*',
'.*?', $a_str1);
131 $this->
logger->debug(
'Trying pattern to match attribute value:' . $pattern .
' => ' . $a_str2);
133 set_error_handler(
static function (
int $severity,
string $message,
string $file,
int $line): never {
134 throw new ErrorException(
$message, $severity, $severity, $file, $line);
137 $regex = $delimiter .
"^" . $pattern .
'$' . $delimiter .
'i';
139 return preg_match($regex, $a_str2) === 1;
140 }
catch (Exception
$e) {
141 $exception[] =
'RegEx: ' . $regex .
' -> Message: ' .
$e->getMessage();
143 restore_error_handler();
147 if ($exception !== []) {
148 $this->
logger->warning(
'Trying the RegEx delimiter chain results in the following problems: ' . implode(
', ', $exception));
166 if (
$server->enabledEscapeDN()) {
167 $user_cmp = ldap_escape($a_user_data[
'dn'],
"", LDAP_ESCAPE_FILTER);
169 $user_cmp = $a_user_data[
'dn'];
172 $user_cmp = $a_user_data[
'ilExternalAccount'];
178 $res = $query->query(
188 return (
bool)
$res->numRows();
190 $this->
logger->warning(
': Caught Exception: ' . $e->getMessage());
209 $query =
"SELECT rule_id FROM ldap_role_assignments " .
210 "WHERE server_id = " .
$ilDB->quote($a_server_id,
'integer');
226 $this->role_id = $a_role_id;
250 $this->server_id = $a_id;
266 $this->type = $a_type;
280 public function setDN(
string $a_dn): void
295 $this->member_attribute = $a_attribute;
311 $this->member_is_dn = $a_status;
327 $this->attribute_name = $a_name;
343 $this->attribute_value = $a_value;
356 $this->add_on_update = $a_status;
366 $this->remove_on_update = $a_status;
376 $this->plugin_id = $a_id;
393 return $this->
lng->txt(
'ldap_plugin_id') .
': ' . $this->
getPluginId();
396 $dn_arr = explode(
',', $this->
getDN());
403 throw new RuntimeException(sprintf(
'Unknown type: %s', var_export($this->
getType(),
true)));
409 $next_id = $this->db->nextId(
'ldap_role_assignments');
411 $query =
"INSERT INTO ldap_role_assignments (server_id,rule_id,type,dn,attribute,isdn,att_name,att_value,role_id, " .
412 "add_on_update, remove_on_update, plugin_id ) " .
414 $this->db->quote($this->
getServerId(),
'integer') .
", " .
415 $this->db->quote($next_id,
'integer') .
", " .
416 $this->db->quote($this->
getType(),
'integer') .
", " .
417 $this->db->quote($this->
getDN(),
'text') .
", " .
422 $this->db->quote($this->
getRoleId(),
'integer') .
", " .
425 $this->db->quote($this->
getPluginId(),
'integer') .
' ' .
427 $this->db->manipulate($query);
428 $this->rule_id = $next_id;
435 $query =
"UPDATE ldap_role_assignments " .
436 "SET server_id = " . $this->db->quote($this->
getServerId(),
'integer') .
", " .
437 "type = " . $this->db->quote($this->
getType(),
'integer') .
", " .
438 "dn = " . $this->db->quote($this->
getDN(),
'text') .
", " .
441 "att_name = " . $this->db->quote($this->
getAttributeName(),
'text') .
", " .
443 "role_id = " . $this->db->quote($this->
getRoleId(),
'integer') .
", " .
446 'plugin_id = ' . $this->db->quote($this->
getPluginId(),
'integer') .
' ' .
447 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
448 $this->db->manipulate($query);
455 $this->ilErr->setMessage(
'');
458 $this->ilErr->setMessage(
'fill_out_all_required_fields');
464 $this->ilErr->setMessage(
'fill_out_all_required_fields');
470 $this->ilErr->setMessage(
'fill_out_all_required_fields');
477 $this->ilErr->setMessage(
'ldap_err_missing_plugin_id');
483 $this->ilErr->setMessage(
'ldap_no_type_given');
490 public function delete():
bool
492 $query =
"DELETE FROM ldap_role_assignments " .
493 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
494 $this->db->manipulate($query);
501 $query =
"SELECT * FROM ldap_role_assignments " .
502 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
504 $res = $this->db->query($query);
507 $this->
setType((
int) $row->type);
508 if (!is_null($row->dn)) {
509 $this->
setDN($row->dn);
511 if (!is_null($row->attribute)) {
515 if (!is_null($row->att_name)) {
518 if (!is_null($row->att_value)) {
522 if (!is_null($row->add_on_update)) {
525 if (!is_null($row->remove_on_update)) {
528 if (!is_null($row->plugin_id)) {
const array REGEX_DELIMITERS
Error Handling & global info handling.
getServerId()
get server id
static _getRules($a_server_id)
Get all rules.
isGroupMember(array $a_user_data)
Check if user is member of specific group.
setAttributeName(string $a_name)
set attribute name
setMemberAttribute(string $a_attribute)
getAttributeValue()
get atrtibute value
getAttributeName()
get attribute name
isMemberAttributeDN()
is member attribute dn
isRemoveOnUpdateEnabled()
static hasRulesForUpdate()
Check if there any rule for updates.
wildcardCompare(string $a_str1, string $a_str2)
setMemberIsDN(bool $a_status)
set member attribute is dn
setServerId(int $a_id)
set server id
getMemberAttribute()
get attribute
enableAddOnUpdate(bool $a_status)
setAttributeValue(string $a_value)
set attribute value
setType(int $a_type)
set type
setRoleId(int $a_role_id)
set role id
__construct(int $a_rule_id=0)
setDN(string $a_dn)
set dn
enableRemoveOnUpdate(bool $a_status)
matches(array $a_user_data)
Check if a rule matches.
static _getInstanceByRuleId(int $a_rule_id)
static callPlugin(int $a_plugin_id, array $a_user_data)
Call plugin check if the condition matches.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
Component logger with individual log levels by component id.
static _lookupTitle(int $obj_id)