add valid user cookie check to checkAuth,
add admin flag in user data
This commit is contained in:
parent
afecfcafd0
commit
34f2669ab9
11
src/utils.js
11
src/utils.js
@ -16,9 +16,13 @@ export async function checkAuth (cookies, res, vmpath = null) {
|
|||||||
let auth = false;
|
let auth = false;
|
||||||
|
|
||||||
const userObj = getUserObjFromUsername(cookies.username);
|
const userObj = getUserObjFromUsername(cookies.username);
|
||||||
|
if (!userObj) {
|
||||||
|
res.status(401).send({ auth, path: vmpath ? `${vmpath}/config` : "/version", error: "Username was missing or invalid." });
|
||||||
|
res.end()
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((await global.userManager.getUser(userObj)) === null) {
|
if ((await global.userManager.getUser(userObj)) === null) {
|
||||||
auth = false;
|
|
||||||
res.status(401).send({ auth, path: vmpath ? `${vmpath}/config` : "/version", error: `User ${cookies.username} not found in localdb.` });
|
res.status(401).send({ auth, path: vmpath ? `${vmpath}/config` : "/version", error: `User ${cookies.username} not found in localdb.` });
|
||||||
res.end();
|
res.end();
|
||||||
return false;
|
return false;
|
||||||
@ -363,8 +367,13 @@ export function readJSONFile (path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export function getUserObjFromUsername (username) {
|
export function getUserObjFromUsername (username) {
|
||||||
|
if (username) {
|
||||||
const userRealm = username.split("@").at(-1);
|
const userRealm = username.split("@").at(-1);
|
||||||
const userID = username.replace(`@${userRealm}`, "");
|
const userID = username.replace(`@${userRealm}`, "");
|
||||||
const userObj = { id: userID, realm: userRealm };
|
const userObj = { id: userID, realm: userRealm };
|
||||||
return userObj;
|
return userObj;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -72,6 +72,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cluster": {
|
"cluster": {
|
||||||
|
"admin": false,
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"example-node-0": true,
|
"example-node-0": true,
|
||||||
"example-node-1": true,
|
"example-node-1": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user