19 declare(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
    93             case self::TYPE_PLUGIN:
    96             case self::TYPE_ATTRIBUTE:
   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) {
   118             case self::TYPE_GROUP:
   127         $pattern = str_replace(
'*', 
'.*?', $a_str1);
   130             $this->
logger->debug(
'Trying pattern to match attribute value:' . $pattern . 
' => ' . $a_str2);
   132             set_error_handler(
static function (
int $severity, 
string $message, 
string $file, 
int $line): never {
   133                 throw new ErrorException($message, $severity, $severity, $file, $line);
   137                 return preg_match($delimiter . 
"^" . $pattern . 
'$' . $delimiter . 
'i', $a_str2) === 1;
   139                 $this->
logger->warning(
'Error occurred in preg_match Ex.: ' . $ex->getMessage());
   141                 restore_error_handler();
   160             if (
$server->enabledEscapeDN()) {
   161                 $user_cmp = ldap_escape($a_user_data[
'dn'], 
"", LDAP_ESCAPE_FILTER);
   163                 $user_cmp = $a_user_data[
'dn'];
   166             $user_cmp = $a_user_data[
'ilExternalAccount'];
   172             $res = $query->query(
   182             return (
bool) 
$res->numRows();
   184             $this->
logger->warning(
': Caught Exception: ' . $e->getMessage());
   199         $ilDB = $DIC->database();
   203         $query = 
"SELECT rule_id FROM ldap_role_assignments " .
   204                 "WHERE server_id = " . 
$ilDB->quote($a_server_id, 
'integer');
   207             $rules[] = self::_getInstanceByRuleId((
int) $row->rule_id);
   220         $this->role_id = $a_role_id;
   244         $this->server_id = $a_id;
   260         $this->type = $a_type;
   274     public function setDN(
string $a_dn): void
   289         $this->member_attribute = $a_attribute;
   305         $this->member_is_dn = $a_status;
   321         $this->attribute_name = $a_name;
   337         $this->attribute_value = $a_value;
   350         $this->add_on_update = $a_status;
   360         $this->remove_on_update = $a_status;
   370         $this->plugin_id = $a_id;
   380         return $this->
getType() === self::TYPE_PLUGIN;
   386             case self::TYPE_PLUGIN:
   387                 return $this->
lng->txt(
'ldap_plugin_id') . 
': ' . $this->
getPluginId();
   389             case self::TYPE_GROUP:
   390                 $dn_arr = explode(
',', $this->
getDN());
   393             case self::TYPE_ATTRIBUTE:
   403         $next_id = $this->db->nextId(
'ldap_role_assignments');
   405         $query = 
"INSERT INTO ldap_role_assignments (server_id,rule_id,type,dn,attribute,isdn,att_name,att_value,role_id, " .
   406             "add_on_update, remove_on_update, plugin_id ) " .
   408             $this->db->quote($this->
getServerId(), 
'integer') . 
", " .
   409             $this->db->quote($next_id, 
'integer') . 
", " .
   410             $this->db->quote($this->
getType(), 
'integer') . 
", " .
   411             $this->db->quote($this->
getDN(), 
'text') . 
", " .
   416             $this->db->quote($this->
getRoleId(), 
'integer') . 
", " .
   419             $this->db->quote($this->
getPluginId(), 
'integer') . 
' ' .
   421         $this->db->manipulate($query);
   422         $this->rule_id = $next_id;
   429         $query = 
"UPDATE ldap_role_assignments " .
   430             "SET server_id = " . $this->db->quote($this->
getServerId(), 
'integer') . 
", " .
   431             "type = " . $this->db->quote($this->
getType(), 
'integer') . 
", " .
   432             "dn = " . $this->db->quote($this->
getDN(), 
'text') . 
", " .
   435             "att_name = " . $this->db->quote($this->
getAttributeName(), 
'text') . 
", " .
   437             "role_id = " . $this->db->quote($this->
getRoleId(), 
'integer') . 
", " .
   440             'plugin_id = ' . $this->db->quote($this->
getPluginId(), 
'integer') . 
' ' .
   441             "WHERE rule_id = " . $this->db->quote($this->
getRuleId(), 
'integer') . 
" ";
   442         $this->db->manipulate($query);
   449         $this->ilErr->setMessage(
'');
   452             $this->ilErr->setMessage(
'fill_out_all_required_fields');
   456             case self::TYPE_GROUP:
   458                     $this->ilErr->setMessage(
'fill_out_all_required_fields');
   462             case self::TYPE_ATTRIBUTE:
   464                     $this->ilErr->setMessage(
'fill_out_all_required_fields');
   469             case self::TYPE_PLUGIN:
   471                     $this->ilErr->setMessage(
'ldap_err_missing_plugin_id');
   477                 $this->ilErr->setMessage(
'ldap_no_type_given');
   484     public function delete(): 
bool   486         $query = 
"DELETE FROM ldap_role_assignments " .
   487             "WHERE rule_id = " . $this->db->quote($this->
getRuleId(), 
'integer') . 
" ";
   488         $this->db->manipulate($query);
   495         $query = 
"SELECT * FROM ldap_role_assignments " .
   496             "WHERE rule_id = " . $this->db->quote($this->
getRuleId(), 
'integer') . 
" ";
   498         $res = $this->db->query($query);
   501             $this->
setType((
int) $row->type);
   502             if (!is_null($row->dn)) {
   503                 $this->
setDN($row->dn);
   505             if (!is_null($row->attribute)) {
   509             if (!is_null($row->att_name)) {
   512             if (!is_null($row->att_value)) {
   516             if (!is_null($row->add_on_update)) {
   519             if (!is_null($row->remove_on_update)) {
   522             if (!is_null($row->plugin_id)) {
 
static hasRulesForUpdate()
Check if there any rule for updates. 
 
setType(int $a_type)
set type 
 
getMemberAttribute()
get attribute 
 
matches(array $a_user_data)
Check if a rule matches. 
 
setAttributeName(string $a_name)
set attribute name 
 
static getInstanceByServerId(int $a_server_id)
Get instance by server id. 
 
isMemberAttributeDN()
is member attribute dn 
 
isGroupMember(array $a_user_data)
Check if user is member of specific group. 
 
__construct(int $a_rule_id=0)
 
setServerId(int $a_id)
set server id 
 
static _getRules($a_server_id)
Get all rules. 
 
getServerId()
get server id 
 
getAttributeName()
get attribute name 
 
setAttributeValue(string $a_value)
set attribute value 
 
static _lookupTitle(int $obj_id)
 
isRemoveOnUpdateEnabled()
 
setMemberAttribute(string $a_attribute)
 
setRoleId(int $a_role_id)
set role id 
 
static _getInstanceByRuleId(int $a_rule_id)
 
setMemberIsDN(bool $a_status)
set member attribute is dn 
 
wildcardCompare(string $a_str1, string $a_str2)
 
enableRemoveOnUpdate(bool $a_status)
 
enableAddOnUpdate(bool $a_status)
 
getAttributeValue()
get atrtibute value 
 
setDN(string $a_dn)
set dn 
 
static callPlugin(int $a_plugin_id, array $a_user_data)
Call plugin check if the condition matches.