add get all user and get all groups endpoints
This commit is contained in:
parent
ad271d010e
commit
213cf4a8fd
24
src/ldap.js
24
src/ldap.js
@ -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) {
|
async addUser (bind, uid, attrs) {
|
||||||
const logger = new LDAP_MULTIOP_LOGGER(`add ${uid}`);
|
const logger = new LDAP_MULTIOP_LOGGER(`add ${uid}`);
|
||||||
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);
|
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);
|
||||||
@ -110,6 +122,18 @@ export default class LDAP {
|
|||||||
return logger;
|
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) {
|
async addGroup (bind, gid) {
|
||||||
const logger = new LDAP_MULTIOP_LOGGER(`add ${gid}`);
|
const logger = new LDAP_MULTIOP_LOGGER(`add ${gid}`);
|
||||||
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);
|
const bindResult = await this.#client.bind(bind.dn, bind.password, logger);
|
||||||
|
24
src/main.js
24
src/main.js
@ -50,6 +50,18 @@ app.get("/echo", (req, res) => {
|
|||||||
res.status(200).send({ body: req.body, cookies: req.cookies });
|
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
|
* POST - create a new user or modify existing user attributes
|
||||||
* request:
|
* 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
|
* POST - create a new group
|
||||||
* request:
|
* request:
|
||||||
|
Loading…
Reference in New Issue
Block a user