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) {
128 $pattern = str_replace(
'*',
'.*?', $a_str1);
129 $this->
logger->debug(
': Replace pattern:' . $pattern .
' => ' . $a_str2);
130 return preg_match(
'/^' . $pattern .
'$/i', $a_str2) === 1;
144 if (
$server->enabledEscapeDN()) {
145 $user_cmp = ldap_escape($a_user_data[
'dn'],
"", LDAP_ESCAPE_FILTER);
147 $user_cmp = $a_user_data[
'dn'];
150 $user_cmp = $a_user_data[
'ilExternalAccount'];
166 return (
bool)
$res->numRows();
168 $this->
logger->warning(
': Caught Exception: ' . $e->getMessage());
187 $query =
"SELECT rule_id FROM ldap_role_assignments " .
188 "WHERE server_id = " .
$ilDB->quote($a_server_id,
'integer');
204 $this->role_id = $a_role_id;
228 $this->server_id = $a_id;
244 $this->type = $a_type;
258 public function setDN(
string $a_dn): void
273 $this->member_attribute = $a_attribute;
289 $this->member_is_dn = $a_status;
305 $this->attribute_name = $a_name;
321 $this->attribute_value = $a_value;
334 $this->add_on_update = $a_status;
339 return $this->add_on_update;
344 $this->remove_on_update = $a_status;
349 return $this->remove_on_update;
354 $this->plugin_id = $a_id;
371 return $this->
lng->txt(
'ldap_plugin_id') .
': ' . $this->
getPluginId();
374 $dn_arr = explode(
',', $this->
getDN());
381 throw new RuntimeException(sprintf(
'Unknown type: %s', var_export($this->
getType(),
true)));
387 $next_id = $this->db->nextId(
'ldap_role_assignments');
389 $query =
"INSERT INTO ldap_role_assignments (server_id,rule_id,type,dn,attribute,isdn,att_name,att_value,role_id, " .
390 "add_on_update, remove_on_update, plugin_id ) " .
392 $this->db->quote($this->
getServerId(),
'integer') .
", " .
393 $this->db->quote($next_id,
'integer') .
", " .
394 $this->db->quote($this->
getType(),
'integer') .
", " .
395 $this->db->quote($this->
getDN(),
'text') .
", " .
400 $this->db->quote($this->
getRoleId(),
'integer') .
", " .
403 $this->db->quote($this->
getPluginId(),
'integer') .
' ' .
405 $this->db->manipulate(
$query);
406 $this->rule_id = $next_id;
413 $query =
"UPDATE ldap_role_assignments " .
414 "SET server_id = " . $this->db->quote($this->
getServerId(),
'integer') .
", " .
415 "type = " . $this->db->quote($this->
getType(),
'integer') .
", " .
416 "dn = " . $this->db->quote($this->
getDN(),
'text') .
", " .
419 "att_name = " . $this->db->quote($this->
getAttributeName(),
'text') .
", " .
421 "role_id = " . $this->db->quote($this->
getRoleId(),
'integer') .
", " .
424 'plugin_id = ' . $this->db->quote($this->
getPluginId(),
'integer') .
' ' .
425 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
426 $this->db->manipulate(
$query);
433 $this->ilErr->setMessage(
'');
436 $this->ilErr->setMessage(
'fill_out_all_required_fields');
442 $this->ilErr->setMessage(
'fill_out_all_required_fields');
448 $this->ilErr->setMessage(
'fill_out_all_required_fields');
455 $this->ilErr->setMessage(
'ldap_err_missing_plugin_id');
461 $this->ilErr->setMessage(
'ldap_no_type_given');
468 public function delete():
bool
470 $query =
"DELETE FROM ldap_role_assignments " .
471 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
472 $this->db->manipulate(
$query);
479 $query =
"SELECT * FROM ldap_role_assignments " .
480 "WHERE rule_id = " . $this->db->quote($this->
getRuleId(),
'integer') .
" ";
485 $this->
setType((
int) $row->type);
486 if (!is_null($row->dn)) {
487 $this->
setDN($row->dn);
489 if (!is_null($row->attribute)) {
493 if (!is_null($row->att_name)) {
496 if (!is_null($row->att_value)) {
500 if (!is_null($row->add_on_update)) {
503 if (!is_null($row->remove_on_update)) {
506 if (!is_null($row->plugin_id)) {
Error Handling & global info handling uses PEAR error class.
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)