Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ msgstr "Record is not eligible for provisioning"
msgid "result.prov.updated"
msgstr "Record updated"

msgid "No DN on record; nothing removed from LDAP"
msgstr "No DN on record; nothing removed from LDAP"

msgid "result.resync.ok"
msgstr "Data Synced"

Expand Down
111 changes: 79 additions & 32 deletions app/plugins/LdapConnector/src/Model/Table/LdapProvisionersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,23 +544,39 @@ protected function provisionPeople(

// Guard: Deleted -> best-effort delete in LDAP, do not attempt DN assignment.
if ($eligibilityValue === ProvisioningEligibilityEnum::Deleted) {
if (!empty($oldDn)) {
$cxn = $CoreLdapServers->getLdapConnection($serverId);
// The DN mapping may already have been soft deleted by the delete cascade
$oldDn = $this->fetchProvisionedDn(
provisioningTarget: $provisioningTarget,
groupId: null,
personId: $personId,
includeDeleted: true
);

$this->applyProvisioningPlan(
$CoreLdapServers,
$cxn,
oldDn: (string)$oldDn,
newDn: null,
baseDn: $peopleBaseDn,
attributes: [],
options: [
'delete' => true,
'ignoreNoSuchObjectOnDelete' => true,
]
if (empty($oldDn)) {
$this->llog('debug', "No DN on record for person_id=" . $personId . ", nothing removed from LDAP");

return $result(
ProvisioningStatusEnum::NotProvisioned,
__d('ldap_connector', 'No DN on record; nothing removed from LDAP'),
null
);
}

$cxn = $CoreLdapServers->getLdapConnection($serverId);

$this->applyProvisioningPlan(
$CoreLdapServers,
$cxn,
oldDn: (string)$oldDn,
newDn: null,
baseDn: $peopleBaseDn,
attributes: [],
options: [
'delete' => true,
'ignoreNoSuchObjectOnDelete' => true,
]
);

return $result(
ProvisioningStatusEnum::NotProvisioned,
__d('ldap_connector', 'Record removed from LDAP'),
Expand Down Expand Up @@ -763,23 +779,39 @@ protected function provisionGroups(

// Guard: Deleted -> best-effort delete in LDAP, do not attempt DN assignment.
if ($eligibilityValue === ProvisioningEligibilityEnum::Deleted || $eligibilityValue === 'Deleted') {
if (!empty($oldDn)) {
$cxn = $CoreLdapServers->getLdapConnection($serverId);
// The DN mapping may already have been soft deleted by the delete cascade
$oldDn = $this->fetchProvisionedDn(
provisioningTarget: $provisioningTarget,
groupId: $groupId,
personId: null,
includeDeleted: true
);

$this->applyProvisioningPlan(
$CoreLdapServers,
$cxn,
oldDn: (string)$oldDn,
newDn: null,
baseDn: $groupBaseDn,
attributes: [],
options: [
'delete' => true,
'ignoreNoSuchObjectOnDelete' => true,
]
if (empty($oldDn)) {
$this->llog('debug', "No DN on record for group_id=" . $groupId . ", nothing removed from LDAP");

return $result(
ProvisioningStatusEnum::NotProvisioned,
__d('ldap_connector', 'No DN on record; nothing removed from LDAP'),
null
);
}

$cxn = $CoreLdapServers->getLdapConnection($serverId);

$this->applyProvisioningPlan(
$CoreLdapServers,
$cxn,
oldDn: (string)$oldDn,
newDn: null,
baseDn: $groupBaseDn,
attributes: [],
options: [
'delete' => true,
'ignoreNoSuchObjectOnDelete' => true,
]
);

return $result(
ProvisioningStatusEnum::NotProvisioned,
__d('ldap_connector', 'Record removed from LDAP'),
Expand Down Expand Up @@ -1017,14 +1049,17 @@ public function status(
* @param ProvisioningTarget $provisioningTarget Provisioning target (contains ldap_provisioner).
* @param int|null $groupId Group ID (if checking group provisioning status).
* @param int|null $personId Person ID (if checking person provisioning status).
* @param bool $includeDeleted If true, also consider (current, non-archive) mappings marked deleted,
* eg because the delete cascade already ran before deprovisioning.
* @return string|null DN if on file, else null.
* @throws \Throwable
* @since COmanage Registry v5.3.0
*/
protected function fetchProvisionedDn(
ProvisioningTarget $provisioningTarget,
?int $groupId,
?int $personId
?int $personId,
bool $includeDeleted = false
): ?string {
if (empty($personId) && empty($groupId)) {
return null;
Expand All @@ -1048,11 +1083,23 @@ protected function fetchProvisionedDn(
$where['LdapProvisionerDns.group_id'] = (int)$groupId;
}

$dnRecord = $LdapProvisionerDns->find()
->select(['dn'])
->where($where)
->enableHydration(false)
->first();
if ($includeDeleted) {
// Bypass Changelog filtering, but restrict to current (non-archive) rows.
$where[] = 'LdapProvisionerDns.ldap_provisioner_dn_id IS NULL';

$dnRecord = $LdapProvisionerDns->find('all', archived: true)
->select(['dn'])
->where($where)
->orderBy(['LdapProvisionerDns.id' => 'DESC'])
->enableHydration(false)
->first();
} else {
$dnRecord = $LdapProvisionerDns->find()
->select(['dn'])
->where($where)
->enableHydration(false)
->first();
}

return !empty($dnRecord['dn']) ? (string)$dnRecord['dn'] : null;
}
Expand Down
65 changes: 64 additions & 1 deletion app/src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class GroupsTable extends Table {
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\ProvisionableTrait;
use \App\Lib\Traits\ProvisionableTrait {
requestProvisioning as traitRequestProvisioning;
}
use \App\Lib\Traits\QueryModificationTrait;
use \App\Lib\Traits\SearchFilterTrait;
use \App\Lib\Traits\TableMetaTrait;
Expand All @@ -65,6 +67,10 @@ class GroupsTable extends Table {
}
use \App\Lib\Traits\ValidationTrait;

// Person IDs of the members of soft deleted Groups, keyed on Group ID, captured
// before the Changelog cascade removes the Group Memberships
protected array $deletedGroupMemberPersonIds = [];

/**
* Perform Cake Model initialization.
*
Expand Down Expand Up @@ -504,6 +510,19 @@ public function beforeDelete(EventInterface $event, $entity, \ArrayObject $optio
// to look at the archived data.
}

if(empty($options['useHardDelete'])) {
// The Group Memberships will be removed by the Changelog cascade, which does not
// request provisioning for the members. Note who they are so requestProvisioning()
// can reprovision them once the Group is deleted.
$this->deletedGroupMemberPersonIds[$entity->id] = $this->GroupMembers->find()
->select(['person_id'])
->distinct(['person_id'])
->where(['group_id' => $entity->id])
->all()
->extract('person_id')
->toList();
}

$event->setResult(true);
}

Expand Down Expand Up @@ -1477,6 +1496,50 @@ protected function reconcileNestedMemberships(
return true;
}

/**
* Request provisioning. When a soft deleted Group is provisioned, its former members
* (whose Group Memberships were removed by the delete cascade) are also reprovisioned.
*
* @since COmanage Registry v5.4.0
* @param int $id This table's entity ID to provision
* @param string $context Context in which provisioning is being requested
* @param int|null $provisioningTargetId If set, the Provisioning Target ID to request provisioning for (otherwise all)
* @param Job|null $job If called from a Job, the current Job entity
* @param array|null $passThroughData Additional data to merge into the marshalled provisioning data
*/

public function requestProvisioning(
int $id,
string $context,
?int $provisioningTargetId=null,
?Job $job=null,
?array $passThroughData=null
): void {
$this->traitRequestProvisioning(
id: $id,
context: $context,
provisioningTargetId: $provisioningTargetId,
job: $job,
passThroughData: $passThroughData
);

if(!empty($this->deletedGroupMemberPersonIds[$id])) {
$personIds = $this->deletedGroupMemberPersonIds[$id];
unset($this->deletedGroupMemberPersonIds[$id]);

foreach($personIds as $personId) {
$this->llog('rule', "Requesting provisioning for Person $personId following deletion of Group $id");

$this->GroupMembers->People->requestProvisioning(
id: (int)$personId,
context: $context,
provisioningTargetId: $provisioningTargetId,
job: $job
);
}
}
}

/**
* Application Rule to determine if both the Parent and Child are Standard Groups.
*
Expand Down
64 changes: 63 additions & 1 deletion app/src/Model/Table/PeopleTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

namespace App\Model\Table;

use App\Model\Entity\Job;
use App\Model\Entity\Person;
use Cake\Datasource\EntityInterface;
use Cake\ORM\Query;
Expand Down Expand Up @@ -56,12 +57,18 @@ class PeopleTable extends Table {
use \App\Lib\Traits\LabeledLogTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PrimaryLinkTrait;
use \App\Lib\Traits\ProvisionableTrait;
use \App\Lib\Traits\ProvisionableTrait {
requestProvisioning as traitRequestProvisioning;
}
use \App\Lib\Traits\QueryModificationTrait;
use \App\Lib\Traits\SearchFilterTrait;
use \App\Lib\Traits\TableMetaTrait;
use \App\Lib\Traits\ValidationTrait;

// Group IDs of the memberships of soft deleted People, keyed on Person ID, captured
// before the Group Memberships are removed
protected array $deletedPersonGroupIds = [];

/**
* Perform Cake Model initialization.
*
Expand Down Expand Up @@ -373,6 +380,17 @@ public function beforeDelete(\Cake\Event\Event $event, $entity, \ArrayObject $op
if(isset($options['useHardDelete']) && $options['useHardDelete']) {
$this->prepareHardDelete($entity);
} else {
// The Group Memberships will be removed (by prepareSoftDelete and the Changelog
// cascade) without requesting provisioning for the Groups. Note which Groups so
// requestProvisioning() can reprovision them once the Person is deleted.
$this->deletedPersonGroupIds[$entity->id] = $this->GroupMembers->find()
->select(['group_id'])
->distinct(['group_id'])
->where(['person_id' => $entity->id])
->all()
->extract('group_id')
->toList();

$this->prepareSoftDelete($entity);
}
}
Expand Down Expand Up @@ -1345,6 +1363,50 @@ public function reconcileCoMembersGroupMemberships(
}
}
}

/**
* Request provisioning. When a soft deleted Person is provisioned, the Groups they were
* a member of (whose Group Memberships were removed by the delete) are also reprovisioned.
*
* @param int $id This table's entity ID to provision
* @param string $context Context in which provisioning is being requested
* @param int|null $provisioningTargetId If set, the Provisioning Target ID to request provisioning for (otherwise all)
* @param Job|null $job If called from a Job, the current Job entity
* @param array|null $passThroughData Additional data to merge into the marshalled provisioning data
* @since COmanage Registry v5.4.0
*/

public function requestProvisioning(
int $id,
string $context,
?int $provisioningTargetId=null,
?\App\Model\Entity\Job $job=null,
?array $passThroughData=null
): void {
$this->traitRequestProvisioning(
id: $id,
context: $context,
provisioningTargetId: $provisioningTargetId,
job: $job,
passThroughData: $passThroughData
);

if(!empty($this->deletedPersonGroupIds[$id])) {
$groupIds = $this->deletedPersonGroupIds[$id];
unset($this->deletedPersonGroupIds[$id]);

foreach($groupIds as $groupId) {
$this->llog('rule', "Requesting provisioning for Group $groupId following deletion of Person $id");

$this->GroupMembers->Groups->requestProvisioning(
id: (int)$groupId,
context: $context,
provisioningTargetId: $provisioningTargetId,
job: $job
);
}
}
}

/**
* Set validation rules.
Expand Down