HOR-3221
This commit is contained in:
@@ -41,21 +41,17 @@ class LdapAdvanced
|
|||||||
* @var Object
|
* @var Object
|
||||||
*/
|
*/
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
private $arrayObjectClassFilter = array(
|
private $arrayObjectClassFilter = array(
|
||||||
"user" => "|(objectclass=inetorgperson)(objectclass=organizationalperson)(objectclass=person)(objectclass=user)",
|
"user" => "|(objectclass=inetorgperson)(objectclass=organizationalperson)(objectclass=person)(objectclass=user)",
|
||||||
"group" => "|(objectclass=posixgroup)(objectclass=group)(objectclass=groupofuniquenames)",
|
"group" => "|(objectclass=posixgroup)(objectclass=group)(objectclass=groupofuniquenames)",
|
||||||
"department" => "|(objectclass=organizationalunit)"
|
"department" => "|(objectclass=organizationalunit)"
|
||||||
);
|
);
|
||||||
|
|
||||||
private $arrayAttributes = array(
|
private $arrayAttributes = array(
|
||||||
"ldap" => array("uid" => "uid", "member" => "memberuid"), //OpenLDAP
|
"ldap" => array("uid" => "uid", "member" => "memberuid"), //OpenLDAP
|
||||||
"ad" => array("uid" => "samaccountname", "member" => "member"), //Active Directory
|
"ad" => array("uid" => "samaccountname", "member" => "member"), //Active Directory
|
||||||
"ds" => array("uid" => "uid", "member" => "uniquemember") //389 DS
|
"ds" => array("uid" => "uid", "member" => "uniquemember") //389 DS
|
||||||
);
|
);
|
||||||
|
|
||||||
private $arrayAttributesForUser = array("dn", "uid", "samaccountname", "givenname", "sn", "cn", "mail", "userprincipalname", "useraccountcontrol", "accountexpires", "manager");
|
private $arrayAttributesForUser = array("dn", "uid", "samaccountname", "givenname", "sn", "cn", "mail", "userprincipalname", "useraccountcontrol", "accountexpires", "manager");
|
||||||
|
|
||||||
private $frontEnd = false;
|
private $frontEnd = false;
|
||||||
private $debug = false;
|
private $debug = false;
|
||||||
public $arrayAuthenticationSourceUsersByUid = array();
|
public $arrayAuthenticationSourceUsersByUid = array();
|
||||||
@@ -64,7 +60,6 @@ class LdapAdvanced
|
|||||||
public $arrayDepartmentUsersByUsername = array();
|
public $arrayDepartmentUsersByUsername = array();
|
||||||
public $arrayGroupUsersByUid = array();
|
public $arrayGroupUsersByUid = array();
|
||||||
public $arrayGroupUsersByUsername = array();
|
public $arrayGroupUsersByUsername = array();
|
||||||
|
|
||||||
private $arrayDepartmentUserSynchronizedChecked = array();
|
private $arrayDepartmentUserSynchronizedChecked = array();
|
||||||
private $arrayUserUpdateChecked = array();
|
private $arrayUserUpdateChecked = array();
|
||||||
|
|
||||||
@@ -73,6 +68,7 @@ class LdapAdvanced
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -371,7 +367,6 @@ class LdapAdvanced
|
|||||||
unset($arrayCharacter[124]); //|
|
unset($arrayCharacter[124]); //|
|
||||||
unset($arrayCharacter[126]); //~
|
unset($arrayCharacter[126]); //~
|
||||||
unset($arrayCharacter[127]); //DEL
|
unset($arrayCharacter[127]); //DEL
|
||||||
|
|
||||||
//Return
|
//Return
|
||||||
return array_unique($arrayCharacter);
|
return array_unique($arrayCharacter);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@@ -805,13 +800,9 @@ class LdapAdvanced
|
|||||||
* @return array Return array data
|
* @return array Return array data
|
||||||
*/
|
*/
|
||||||
private function __ldapGroupSynchronizeMembers(
|
private function __ldapGroupSynchronizeMembers(
|
||||||
$ldapcnn,
|
$ldapcnn, array $arrayAuthSourceData, $groupUid, array $arrayGroupLdap, $memberAttribute, array $arrayData = []
|
||||||
array $arrayAuthSourceData,
|
)
|
||||||
$groupUid,
|
{
|
||||||
array $arrayGroupLdap,
|
|
||||||
$memberAttribute,
|
|
||||||
array $arrayData = []
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
unset($arrayData['countMembers']);
|
unset($arrayData['countMembers']);
|
||||||
|
|
||||||
@@ -862,8 +853,7 @@ class LdapAdvanced
|
|||||||
|
|
||||||
//Progress bar
|
//Progress bar
|
||||||
$this->frontEndShow(
|
$this->frontEndShow(
|
||||||
'BAR',
|
'BAR', 'Groups: ' . $arrayData['i'] . '/' . $arrayData['n'] . ' ' .
|
||||||
'Groups: ' . $arrayData['i'] . '/' . $arrayData['n'] . ' ' .
|
|
||||||
$this->progressBar($arrayData['totalUser'], $arrayData['countUser'])
|
$this->progressBar($arrayData['totalUser'], $arrayData['countUser'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -954,12 +944,7 @@ class LdapAdvanced
|
|||||||
}
|
}
|
||||||
|
|
||||||
$arrayData = $this->__ldapGroupSynchronizeMembers(
|
$arrayData = $this->__ldapGroupSynchronizeMembers(
|
||||||
$ldapcnn,
|
$ldapcnn, $arrayAuthenticationSourceData, $arrayGroupData['GRP_UID'], $arrayGroupLdap, $memberAttribute2, array_merge($arrayData, ['totalUser' => $totalUser, 'countUser' => $countUser])
|
||||||
$arrayAuthenticationSourceData,
|
|
||||||
$arrayGroupData['GRP_UID'],
|
|
||||||
$arrayGroupLdap,
|
|
||||||
$memberAttribute2,
|
|
||||||
array_merge($arrayData, ['totalUser' => $totalUser, 'countUser' => $countUser])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$totalUser = $arrayData['totalUser'];
|
$totalUser = $arrayData['totalUser'];
|
||||||
@@ -992,12 +977,7 @@ class LdapAdvanced
|
|||||||
}
|
}
|
||||||
|
|
||||||
$arrayData = $this->__ldapGroupSynchronizeMembers(
|
$arrayData = $this->__ldapGroupSynchronizeMembers(
|
||||||
$ldapcnn,
|
$ldapcnn, $arrayAuthenticationSourceData, $arrayGroupData['GRP_UID'], $arrayGroupLdap, $memberAttribute2, array_merge($arrayData, ['totalUser' => $totalUser, 'countUser' => $countUser])
|
||||||
$arrayAuthenticationSourceData,
|
|
||||||
$arrayGroupData['GRP_UID'],
|
|
||||||
$arrayGroupLdap,
|
|
||||||
$memberAttribute2,
|
|
||||||
array_merge($arrayData, ['totalUser' => $totalUser, 'countUser' => $countUser])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$totalUser = $arrayData['totalUser'];
|
$totalUser = $arrayData['totalUser'];
|
||||||
@@ -1098,19 +1078,16 @@ class LdapAdvanced
|
|||||||
$usrName = $row["USR_USERNAME"];
|
$usrName = $row["USR_USERNAME"];
|
||||||
$usrUid = $row["USR_UID"];
|
$usrUid = $row["USR_UID"];
|
||||||
|
|
||||||
|
$userDn = $strUser;
|
||||||
|
|
||||||
//Get the AuthSource properties
|
//Get the AuthSource properties
|
||||||
//Check if the dn in the database record matches with the dn for the ldap account
|
//Check if the dn in the database record matches with the dn for the ldap account
|
||||||
$verifiedUser = $this->searchUserByUid(
|
try {
|
||||||
$usrName,
|
$verifiedUser = $this->searchUserByUid($usrName, $arrayAuthSource["AUTH_SOURCE_DATA"]["AUTH_SOURCE_IDENTIFIER_FOR_USER"]);
|
||||||
$arrayAuthSource["AUTH_SOURCE_DATA"]["AUTH_SOURCE_IDENTIFIER_FOR_USER"]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (empty($verifiedUser) || trim($verifiedUser["sDN"]) == null) {
|
if (empty($verifiedUser) || trim($verifiedUser["sDN"]) == null) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$userDn = $strUser;
|
|
||||||
|
|
||||||
if ($verifiedUser["sDN"] != $strUser || $setAttributes == 1) {
|
if ($verifiedUser["sDN"] != $strUser || $setAttributes == 1) {
|
||||||
$userDn = $verifiedUser['sDN'];
|
$userDn = $verifiedUser['sDN'];
|
||||||
|
|
||||||
@@ -1134,6 +1111,12 @@ class LdapAdvanced
|
|||||||
|
|
||||||
BasePeer::doUpdate($c1, $c2, $con);
|
BasePeer::doUpdate($c1, $c2, $con);
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$context = Bootstrap::getDefaultContextLog();
|
||||||
|
$context["action"] = "ldapSynchronize";
|
||||||
|
$context["authSource"] = $arrayAuthSource;
|
||||||
|
Bootstrap::registerMonolog("ldapSynchronize", 400, $e->getMessage(), $context, $context["workspace"], "processmaker.log");
|
||||||
|
}
|
||||||
|
|
||||||
//Check ldap connection for user
|
//Check ldap connection for user
|
||||||
$arrayAuthSource["AUTH_ANONYMOUS"] = "0";
|
$arrayAuthSource["AUTH_ANONYMOUS"] = "0";
|
||||||
@@ -1169,7 +1152,7 @@ class LdapAdvanced
|
|||||||
$c1->add(RbacUsersPeer::USR_AUTH_USER_DN, $strUser);
|
$c1->add(RbacUsersPeer::USR_AUTH_USER_DN, $strUser);
|
||||||
// update set
|
// update set
|
||||||
$c2 = new Criteria("rbac");
|
$c2 = new Criteria("rbac");
|
||||||
$c2->add(RbacUsersPeer::USR_AUTH_USER_DN, $verifiedUser["sDN"]);
|
$c2->add(RbacUsersPeer::USR_AUTH_USER_DN, $userDn);
|
||||||
$c2->add(RbacUsersPeer::USR_STATUS, $statusRbac);
|
$c2->add(RbacUsersPeer::USR_STATUS, $statusRbac);
|
||||||
BasePeer::doUpdate($c1, $c2, $con);
|
BasePeer::doUpdate($c1, $c2, $con);
|
||||||
$columnsWf = array();
|
$columnsWf = array();
|
||||||
@@ -1186,7 +1169,7 @@ class LdapAdvanced
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Check if the user is in the terminated organizational unit
|
//Check if the user is in the terminated organizational unit
|
||||||
if ($this->userIsTerminated($usrName, $attributes["AUTH_SOURCE_RETIRED_OU"])) {
|
if (!empty($verifiedUser) && $this->userIsTerminated($usrName, $attributes["AUTH_SOURCE_RETIRED_OU"])) {
|
||||||
$this->deactivateUser($usrName);
|
$this->deactivateUser($usrName);
|
||||||
$this->log($ldapcnn, "user $strUser is member of Remove OU, deactivating this user.");
|
$this->log($ldapcnn, "user $strUser is member of Remove OU, deactivating this user.");
|
||||||
|
|
||||||
@@ -1261,8 +1244,7 @@ class LdapAdvanced
|
|||||||
$attributeUserSet = array();
|
$attributeUserSet = array();
|
||||||
$attributeSetAdd = array();
|
$attributeSetAdd = array();
|
||||||
|
|
||||||
if (isset($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
if (isset($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"]) && !empty($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
||||||
&& !empty($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
|
||||||
) {
|
) {
|
||||||
foreach ($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"] as $value) {
|
foreach ($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"] as $value) {
|
||||||
$attributeSetAdd[] = $value['attributeLdap'];
|
$attributeSetAdd[] = $value['attributeLdap'];
|
||||||
@@ -1442,8 +1424,7 @@ class LdapAdvanced
|
|||||||
$attributeUserSet = array();
|
$attributeUserSet = array();
|
||||||
$attributeSetAdd = array();
|
$attributeSetAdd = array();
|
||||||
|
|
||||||
if (isset($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
if (isset($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"]) && !empty($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
||||||
&& !empty($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"])
|
|
||||||
) {
|
) {
|
||||||
foreach ($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"] as $value) {
|
foreach ($arrayAuthenticationSourceData["AUTH_SOURCE_DATA"]["AUTH_SOURCE_GRID_ATTRIBUTE"] as $value) {
|
||||||
$attributeSetAdd[] = $value["attributeLdap"];
|
$attributeSetAdd[] = $value["attributeLdap"];
|
||||||
@@ -1842,7 +1823,6 @@ class LdapAdvanced
|
|||||||
|
|
||||||
return $terminated;
|
return $terminated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* activate an user previously deactivated
|
/* activate an user previously deactivated
|
||||||
if user is now in another department, we need the second parameter, the depUid
|
if user is now in another department, we need the second parameter, the depUid
|
||||||
|
|
||||||
@@ -1850,6 +1830,7 @@ class LdapAdvanced
|
|||||||
@param string optional department DN
|
@param string optional department DN
|
||||||
@param string optional DepUid
|
@param string optional DepUid
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function activateUser($userUid, $userDn = null, $depUid = null)
|
public function activateUser($userUid, $userDn = null, $depUid = null)
|
||||||
{
|
{
|
||||||
if (!class_exists('RbacUsers')) {
|
if (!class_exists('RbacUsers')) {
|
||||||
@@ -2357,7 +2338,6 @@ class LdapAdvanced
|
|||||||
* @param <type> $currentDN
|
* @param <type> $currentDN
|
||||||
* @return <type>
|
* @return <type>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getGrpUidIfExistsDN($currentDN)
|
public function getGrpUidIfExistsDN($currentDN)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@@ -2539,7 +2519,6 @@ class LdapAdvanced
|
|||||||
//If user DO NOT exists in this department.. do:
|
//If user DO NOT exists in this department.. do:
|
||||||
//If exists with another AuthSource -> impossible
|
//If exists with another AuthSource -> impossible
|
||||||
//If exists in another department, but in PM and for this authsource, we need to move it
|
//If exists in another department, but in PM and for this authsource, we need to move it
|
||||||
|
|
||||||
//$arrayNewUserData = $this->searchUserByUid($arrayUserLdap["sUsername"]);
|
//$arrayNewUserData = $this->searchUserByUid($arrayUserLdap["sUsername"]);
|
||||||
$arrayNewUserData = $arrayUserLdap;
|
$arrayNewUserData = $arrayUserLdap;
|
||||||
|
|
||||||
@@ -2646,7 +2625,6 @@ class LdapAdvanced
|
|||||||
//If user DO NOT exists in this group.. do:
|
//If user DO NOT exists in this group.. do:
|
||||||
//If exists with another AuthSource -> impossible
|
//If exists with another AuthSource -> impossible
|
||||||
//If exists in another group, but in PM and for this authsource, we need to move it
|
//If exists in another group, but in PM and for this authsource, we need to move it
|
||||||
|
|
||||||
//$arrayNewUserData = $this->searchUserByUid($arrayUserLdap["sUsername"]);
|
//$arrayNewUserData = $this->searchUserByUid($arrayUserLdap["sUsername"]);
|
||||||
$arrayNewUserData = $arrayUserLdap;
|
$arrayNewUserData = $arrayUserLdap;
|
||||||
|
|
||||||
@@ -2815,8 +2793,7 @@ class LdapAdvanced
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->log(
|
$this->log(
|
||||||
$ldapcnn,
|
$ldapcnn, 'User is repeated: Username "' . $username . '", DN "' . $arrayUserLdap['dn'] . '"'
|
||||||
'User is repeated: Username "' . $username .'", DN "' . $arrayUserLdap['dn'] . '"'
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2845,12 +2822,9 @@ class LdapAdvanced
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function __ldapUsersUpdateData(
|
private function __ldapUsersUpdateData(
|
||||||
$ldapcnn,
|
$ldapcnn, array $arrayAuthSourceData, $filterUsers, array $arrayUserUid, array $arrayData
|
||||||
array $arrayAuthSourceData,
|
)
|
||||||
$filterUsers,
|
{
|
||||||
array $arrayUserUid,
|
|
||||||
array $arrayData
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
$totalUser = $arrayData['totalUser'];
|
$totalUser = $arrayData['totalUser'];
|
||||||
$countUser = $arrayData['countUser'];
|
$countUser = $arrayData['countUser'];
|
||||||
@@ -2894,8 +2868,7 @@ class LdapAdvanced
|
|||||||
|
|
||||||
//Progress bar
|
//Progress bar
|
||||||
$this->frontEndShow(
|
$this->frontEndShow(
|
||||||
'BAR',
|
'BAR', 'Update Users data: ' . $countUser . '/' . $totalUser . ' ' . $this->progressBar($totalUser, $countUser)
|
||||||
'Update Users data: ' . $countUser . '/' . $totalUser . ' ' . $this->progressBar($totalUser, $countUser)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} while ($entry = ldap_next_entry($ldapcnn, $entry));
|
} while ($entry = ldap_next_entry($ldapcnn, $entry));
|
||||||
|
|||||||
Reference in New Issue
Block a user