Add ability to manage the 'managedBy' attribute for AD objects

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 705f2157-ef97-4fbd-89e4-8c7f2ecaea90
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7ed01c5f-a82d-405a-b728-b2e3d127c60c/2b2008cc-a510-433c-9379-89ffac9ce6a0.jpg
This commit is contained in:
alphaeusmote
2025-04-09 11:38:35 +00:00
parent 00250d2904
commit 9e2d0ce81e
4 changed files with 471 additions and 1 deletions
+69
View File
@@ -196,6 +196,75 @@ class LdapClient extends EventEmitter {
});
});
}
// Get the managed by attribute for an object
async getManagedBy(connectionId: number, dn: string): Promise<string | null> {
const client = this.getClient(connectionId);
if (!client) throw new Error('LDAP connection not established');
return new Promise((resolve, reject) => {
client.search(dn, {
scope: 'base',
attributes: ['managedBy']
}, (err, res) => {
if (err) {
reject(err);
return;
}
let managedBy: string | null = null;
res.on('searchEntry', (entry) => {
const attrs = entry.attributes;
for (const attr of attrs) {
if (attr.type === 'managedBy' && attr.vals && attr.vals.length > 0) {
managedBy = attr.vals[0].toString();
}
}
});
res.on('error', (err) => {
reject(err);
});
res.on('end', (result) => {
if (result.status !== 0) {
reject(new Error(`LDAP search error: ${result.errorMessage}`));
return;
}
resolve(managedBy);
});
});
});
}
// Set the managed by attribute for an object
async setManagedBy(connectionId: number, dn: string, managerDn: string | null): Promise<boolean> {
const client = this.getClient(connectionId);
if (!client) throw new Error('LDAP connection not established');
const changes = [];
if (managerDn === null) {
// Remove the managedBy attribute
changes.push(new ldap.Change({
operation: 'delete',
modification: {
managedBy: []
}
}));
} else {
// Add or replace the managedBy attribute
changes.push(new ldap.Change({
operation: 'replace',
modification: {
managedBy: managerDn
}
}));
}
return this.updateEntry(connectionId, dn, changes);
}
}
export const ldapClient = new LdapClient();