add get all user and get all groups endpoints

This commit is contained in:
Arthur Lu 2023-12-22 04:20:31 +00:00
parent ad271d010e
commit 213cf4a8fd
2 changed files with 48 additions and 0 deletions

View File

@ -23,6 +23,18 @@ export default class LDAP {
};
}
async getAllUsers (bind) {
const bindResult = await this.#client.bind(bind.dn, bind.password);
if (!bindResult.ok) {
return bindResult;
}
const result = await this.#client.search(this.#peopledn, {
scope: "one"
});
result.users = result.entries;
return result;
}
async addUser (bind, uid, attrs) {
const logger = new LDAP_MULTIOP_LOGGER(`add ${uid}`);
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);
@ -110,6 +122,18 @@ export default class LDAP {
return logger;
}
async getAllGroups (bind) {
const bindResult = await this.#client.bind(bind.dn, bind.password);
if (!bindResult.ok) {
return bindResult;
}
const result = await this.#client.search(this.#groupsdn, {
scope: "one"
});
result.groups = result.entries;
return result;
}
async addGroup (bind, gid) {
const logger = new LDAP_MULTIOP_LOGGER(`add ${gid}`);
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);

View File

@ -50,6 +50,18 @@ app.get("/echo", (req, res) => {
res.status(200).send({ body: req.body, cookies: req.cookies });
});
app.get("/users", async (req, res) => {
const params = {
bind: ldap.createUserBind(req.body.binduser, req.body.bindpass)
};
const result = await ldap.getAllUsers(params.bind);
res.send({
ok: result.ok,
error: result.error,
users: result.users
});
});
/**
* POST - create a new user or modify existing user attributes
* request:
@ -140,6 +152,18 @@ app.delete("/users/:userid", async (req, res) => {
});
});
app.get("/groups", async (req, res) => {
const params = {
bind: ldap.createUserBind(req.body.binduser, req.body.bindpass)
};
const result = await ldap.getAllGroups(params.bind);
res.send({
ok: result.ok,
error: result.error,
groups: result.groups
});
});
/**
* POST - create a new group
* request: