Merged in bugfix/PMCORE-2487 (pull request #7573)

PMCORE-2487 Multiple groups are created with the same name when setting up ldap group synchronization

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Roly Rudy Gutierrez Pinto
2021-01-25 14:07:32 +00:00
committed by Julio Cesar Laura Avendaño
5 changed files with 97 additions and 40 deletions

View File

@@ -1,8 +1,10 @@
<?php <?php
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use ProcessMaker\BusinessModel\User; use ProcessMaker\BusinessModel\User;
use ProcessMaker\Model\Groupwf;
/** /**
* class.ldapAdvanced.php * class.ldapAdvanced.php
@@ -2498,6 +2500,47 @@ class LdapAdvanced
} }
} }
/**
* Get group Uid by title.
* @param string $title
* @return string
*/
public function getGroupUidByTitle(string $title): string
{
try {
$groupWf = Groupwf::query()
->where('GRP_STATUS', '=', 'ACTIVE')
->where('GRP_TITLE', '=', $title)
->orderBy('GRP_ID', 'ASC')
->get()
->first();
if (!empty($groupWf)) {
return $groupWf->GRP_UID;
}
} catch (Exception $e) {
$message = $e->getMessage();
Log::channel(':ldapSynchronizeGroups')->error($message, Bootstrap::context());
}
return "";
}
/**
* Check duplicate titles in GROUPWF table.
* @return bool
*/
public function checkDuplicateTitles(): bool
{
$sql = ""
. "select GRP_TITLE,count(GRP_TITLE) "
. "from GROUPWF "
. "group by GRP_TITLE having count(GRP_TITLE)>1";
$results = DB::select(DB::raw($sql));
if (empty($results)) {
return false;
}
return true;
}
/** /**
* Get number of Users in each Group from the Database * Get number of Users in each Group from the Database
* *

View File

@@ -10775,6 +10775,12 @@ msgstr "is not registered!"
msgid "is required" msgid "is required"
msgstr "is required" msgstr "is required"
# TRANSLATION
# LABEL/ID_IT_WAS_IDENTIFIED_DUPLICATED_GROUPS_PLEASE_REMOVE_THESE_GROUPS
#: LABEL/ID_IT_WAS_IDENTIFIED_DUPLICATED_GROUPS_PLEASE_REMOVE_THESE_GROUPS
msgid "It was identified in the workspace duplicated groups, please remove manually these groups."
msgstr "It was identified in the workspace duplicated groups, please remove manually these groups."
# TRANSLATION # TRANSLATION
# LABEL/ID_IUD # LABEL/ID_IUD
#: LABEL/ID_IUD #: LABEL/ID_IUD

View File

@@ -58652,6 +58652,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_ISSUED_TO','en','Issued to','2014-09-18') , ( 'LABEL','ID_ISSUED_TO','en','Issued to','2014-09-18') ,
( 'LABEL','ID_IS_NOT_REGISTERED','en','is not registered!','2014-01-15') , ( 'LABEL','ID_IS_NOT_REGISTERED','en','is not registered!','2014-01-15') ,
( 'LABEL','ID_IS_REQUIRED','en','is required','2014-01-15') , ( 'LABEL','ID_IS_REQUIRED','en','is required','2014-01-15') ,
( 'LABEL','ID_IT_WAS_IDENTIFIED_DUPLICATED_GROUPS_PLEASE_REMOVE_THESE_GROUPS','en','It was identified in the workspace duplicated groups, please remove manually these groups.','2020-12-02') ,
( 'LABEL','ID_IUD','en','#','2014-01-15') , ( 'LABEL','ID_IUD','en','#','2014-01-15') ,
( 'LABEL','ID_JAVASCRIPTS','en','JavaScripts','2014-01-15') , ( 'LABEL','ID_JAVASCRIPTS','en','JavaScripts','2014-01-15') ,
( 'LABEL','ID_JAVASCRIPT_CACHE','en','Javascript cache','2014-01-15') , ( 'LABEL','ID_JAVASCRIPT_CACHE','en','Javascript cache','2014-01-15') ,

View File

@@ -164,63 +164,58 @@ try {
$ldapAdvanced = getLDAPAdvanceInstance($_REQUEST["authUid"]); $ldapAdvanced = getLDAPAdvanceInstance($_REQUEST["authUid"]);
foreach ($groupsToCheck as $groupDN) { foreach ($groupsToCheck as $groupDN) {
//$baseDN = str_replace($authenticationSource["AUTH_SOURCE_BASE_DN"], "", $groupDN);
$ous = custom_ldap_explode_dn($groupDN); $ous = custom_ldap_explode_dn($groupDN);
$currentGroup = array_shift($ous); $currentGroup = array_shift($ous);
//$parentDN = implode(",", $ous);
//$ous = custom_ldap_explode_dn($baseDN);
//$currentGroup = array_shift($ous);
foreach ($ous as $key => $val) {
$aux = explode("=", $val);
if (isset($aux[0]) && strtolower(trim($aux[0]) != "ou")) {
unset($ous[$key]);
}
}
$groupAux = explode("=", $currentGroup); $groupAux = explode("=", $currentGroup);
$groupTitle = isset($groupAux[1]) ? trim($groupAux[1]) : ""; $groupTitle = isset($groupAux[1]) ? trim($groupAux[1]) : "";
$groupUID = $ldapAdvanced->getGrpUidIfExistsDN($groupDN); $groupTitle = stripslashes($groupTitle);
if (empty($groupTitle)) {
if ($groupUID == "") { continue;
$group = new Groupwf(); }
$row["GRP_TITLE"] = stripslashes($groupTitle); $groupUid = $ldapAdvanced->getGroupUidByTitle($groupTitle);
$row["GRP_LDAP_DN"] = $groupDN; $groupwf = new Groupwf();
$groupUID = $group->create($row); if ($groupUid === "") {
$group = [
if ($groupUID == false) { "GRP_TITLE" => $groupTitle,
$response = new stdclass(); "GRP_LDAP_DN" => $groupDN
$response->status = "ERROR"; ];
$response->message = "Error creating group"; $groupwf->create($group);
die($json->encode($response)); } else {
} $group = $groupwf->Load($groupUid);
$group["GRP_LDAP_DN"] = $groupDN;
$groupwf->update($group);
} }
} }
if (count($groupsToUncheck) > 0) { if (count($groupsToUncheck) > 0) {
foreach ($groupsToUncheck as $groupDN) { foreach ($groupsToUncheck as $groupDN) {
$groupUID = $ldapAdvanced->getGrpUidIfExistsDN($groupDN); $ous = custom_ldap_explode_dn($groupDN);
$currentGroup = array_shift($ous);
if ($groupUID != "") { $groupAux = explode("=", $currentGroup);
$group = new Groupwf(); $groupTitle = isset($groupAux[1]) ? trim($groupAux[1]) : "";
$groupInfo = $group->Load($groupUID); $groupTitle = stripslashes($groupTitle);
$groupInfo["GRP_LDAP_DN"] = ""; if (empty($groupTitle)) {
$group->update($groupInfo); continue;
}
$groupUid = $ldapAdvanced->getGroupUidByTitle($groupTitle);
if ($groupUid != "") {
$groupwf = new Groupwf();
$group = $groupwf->Load($groupUid);
$group["GRP_LDAP_DN"] = "";
$groupwf->update($group);
if (!isset($authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"])) { if (!isset($authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"])) {
$authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"] = array(); $authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"] = array();
} }
$authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"][] = $groupUid;
$authenticationSource["AUTH_SOURCE_DATA"]["GROUPS_TO_UNASSIGN"][] = $groupUID;
} }
} }
$RBAC->authSourcesObj->update($authenticationSource); $RBAC->authSourcesObj->update($authenticationSource);
} }
$response = new stdclass(); $response = new stdclass();
$response->status = "OK"; $response->status = "OK";
if ($ldapAdvanced->checkDuplicateTitles()) {
$response->warning = G::LoadTranslation("ID_IT_WAS_IDENTIFIED_DUPLICATED_GROUPS_PLEASE_REMOVE_THESE_GROUPS");
}
die($json->encode($response)); die($json->encode($response));
break; break;
} }

View File

@@ -143,6 +143,7 @@ Ext.onReady(function() {
var response = Ext.util.JSON.decode(r.responseText); var response = Ext.util.JSON.decode(r.responseText);
if (response.status == 'OK') { if (response.status == 'OK') {
treeGroups.getLoader().load(treeGroups.root); treeGroups.getLoader().load(treeGroups.root);
treeGroups.responseMessage = response;
} }
else { else {
alert(response.message); alert(response.message);
@@ -164,7 +165,18 @@ Ext.onReady(function() {
msg: 'All changes have been saved.', msg: 'All changes have been saved.',
icon: Ext.Msg.INFO, icon: Ext.Msg.INFO,
minWidth: 200, minWidth: 200,
buttons: Ext.Msg.OK buttons: Ext.Msg.OK,
fn: function (btn) {
if (btn == 'ok' && treeGroups.responseMessage && treeGroups.responseMessage.warning) {
Ext.Msg.show({
title: _('ID_WARNING'),
msg: treeGroups.responseMessage.warning,
icon: Ext.Msg.INFO,
minWidth: 200,
buttons: Ext.Msg.OK
});
}
}
}); });
} }
}); });