19 declare(strict_types=1);
47 $this->db = $DIC->database();
48 $this->
lng = $DIC->language();
49 $this->rbacreview = $DIC->rbac()->review();
50 $this->ilErr = $DIC[
'ilErr'];
51 $this->ilObjDataCache = $DIC[
'ilObjDataCache'];
52 $this->server_id = $a_server_id;
61 if (array_key_exists($a_server_id, self::$instances) && is_object(self::$instances[$a_server_id])) {
62 return self::$instances[$a_server_id];
73 $query =
"DELETE FROM ldap_rg_mapping " .
74 "WHERE role = " .
$ilDB->quote($a_role_id,
'integer');
75 $ilDB->manipulate($query);
86 $query =
"DELETE FROM ldap_rg_mapping " .
87 "WHERE server_id = " .
$ilDB->quote($a_server_id,
'integer');
88 $ilDB->manipulate($query);
93 public static function _getAllActiveMappings(): array
99 $rbacreview = $DIC[
'rbacreview'];
101 $query =
"SELECT rgm.* FROM ldap_rg_mapping rgm JOIN ldap_server_settings lss " .
102 "ON rgm.server_id = lss.server_id " .
103 "WHERE lss.active = 1 " .
104 "AND lss.role_sync_active = 1 ";
107 while ($row =
$ilDB->fetchObject(
$res)) {
108 $data[
'server_id'] = $row->server_id;
109 $data[
'url'] = $row->url;
110 $data[
'mapping_id'] = $row->mapping_id;
111 $data[
'dn'] = $row->dn;
112 $data[
'member'] = $row->member_attribute;
113 $data[
'isdn'] = $row->member_isdn;
114 $data[
'info'] = $row->mapping_info;
115 $data[
'info_type'] = $row->mapping_info_type;
119 $active[$row->role][] =
$data;
143 $this->mappings = [];
144 foreach ($a_mappings as $mapping_id =>
$data) {
145 if ($mapping_id === 0 && !
$data[
'dn'] && !
$data[
'member'] && !
$data[
'memberisdn'] && !
$data[
'role']) {
167 $this->ilErr->setMessage(
'');
168 $found_missing =
false;
169 foreach ($this->mappings as
$data) {
171 if ($data[
'dn'] ===
'' || $data[
'member_attribute'] ===
'' || $data[
'role_name'] ===
'') {
172 if (!$found_missing) {
173 $found_missing =
true;
174 $this->ilErr->appendMessage($this->
lng->txt(
'fill_out_all_required_fields'));
178 if ($data[
'role_name'] !==
'' && !$this->rbacreview->roleExists($data[
'role_name'])) {
179 $this->ilErr->appendMessage($this->
lng->txt(
'ldap_role_not_exists') .
' ' . $data[
'role_name']);
183 return $this->ilErr->getMessage() ===
'';
195 foreach ($this->mappings as $mapping_id =>
$data) {
197 $next_id = $this->db->nextId(
'ldap_rg_mapping');
198 $query =
"INSERT INTO ldap_rg_mapping (mapping_id,server_id,url,dn,member_attribute,member_isdn,role,mapping_info,mapping_info_type) " .
200 $this->db->quote($next_id,
'integer') .
", " .
201 $this->db->quote($this->
getServerId(),
'integer') .
", " .
202 $this->db->quote(
$data[
'url'],
'text') .
", " .
203 $this->db->quote(
$data[
'dn'],
'text') .
", " .
204 $this->db->quote(
$data[
'member_attribute'],
'text') .
", " .
205 $this->db->quote(
$data[
'member_isdn'],
'integer') .
", " .
206 $this->db->quote(
$data[
'role'],
'integer') .
", " .
207 $this->db->quote(
$data[
'info'],
'text') .
", " .
208 $this->db->quote(
$data[
'info_type'],
'integer') .
211 $query =
"UPDATE ldap_rg_mapping " .
212 "SET server_id = " . $this->db->quote($this->
getServerId(),
'integer') .
", " .
213 "url = " . $this->db->quote(
$data[
'url'],
'text') .
", " .
214 "dn =" . $this->db->quote(
$data[
'dn'],
'text') .
", " .
215 "member_attribute = " . $this->db->quote(
$data[
'member_attribute'],
'text') .
", " .
216 "member_isdn = " . $this->db->quote(
$data[
'member_isdn'],
'integer') .
", " .
217 "role = " . $this->db->quote(
$data[
'role'],
'integer') .
", " .
218 "mapping_info = " . $this->db->quote(
$data[
'info'],
'text') .
", " .
219 "mapping_info_type = " . $this->db->quote(
$data[
'info_type'],
'integer') .
" " .
220 "WHERE mapping_id = " . $this->db->quote($mapping_id,
'integer');
222 $this->db->manipulate($query);
234 public function delete($a_mapping_id):
void 236 $query =
"DELETE FROM ldap_rg_mapping " .
237 "WHERE server_id = " . $this->db->quote($this->
getServerId(),
'integer') .
" " .
238 "AND mapping_id = " . $this->db->quote($a_mapping_id,
'integer');
239 $this->db->manipulate($query);
252 $dn_parts = explode(
',', $this->mappings[$a_mapping_id][
'dn']);
254 return $dn_parts ? $dn_parts[0] :
"''";
263 $this->mappings = array();
264 $query =
"SELECT * FROM ldap_rg_mapping LEFT JOIN object_data " .
265 "ON role = obj_id " .
266 "WHERE server_id =" . $this->db->quote($this->
getServerId(),
'integer') .
' ' .
269 $res = $this->db->query($query);
271 $this->mappings[$row->mapping_id][
'mapping_id'] = $row->mapping_id;
272 $this->mappings[$row->mapping_id][
'dn'] = $row->dn;
273 $this->mappings[$row->mapping_id][
'url'] = $row->url;
274 $this->mappings[$row->mapping_id][
'member_attribute'] = $row->member_attribute;
275 $this->mappings[$row->mapping_id][
'member_isdn'] = $row->member_isdn;
276 $this->mappings[$row->mapping_id][
'role'] = $row->role;
277 $this->mappings[$row->mapping_id][
'info'] = $row->mapping_info;
278 $this->mappings[$row->mapping_id][
'info_type'] = $row->mapping_info_type;
279 if ($this->ilObjDataCache->lookupType((
int) $row->role) ===
'role') {
280 $this->mappings[$row->mapping_id][
'role_name'] = $this->ilObjDataCache->lookupTitle((
int) $row->role);
282 $this->mappings[$row->mapping_id][
'role_name'] = $row->role;
const MAPPING_INFO_INFO_ONLY
getMappings()
Get already configured mappings.
static _deleteByRole(int $a_role_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static _deleteByServerId(int $a_server_id)
getMappingInfoString(int $a_mapping_id)
Create an info string for a role group mapping.
validate()
Validate mappings.
static _getInstanceByServerId(int $a_server_id)
Get instance of class.
ilObjectDataCache $ilObjDataCache
loadFromPost(array $a_mappings)
__construct($a_server_id)
Private constructor (Singleton for each server_id)
getObjectOfRole(int $a_role_id)
Get object id of objects a role is assigned to.