RBACC
Simple RBAC with custom user resources and Redis backend .
Install
npm install rbacc -save
Prerequisites
Examples
let rbacc=new Rbacc({
cacheTTL:3600000,
debug:false,
client:{
host:"localhost",
port:6379,
prefix:"rbacc:"
}
})
rbacc.addRoles({
roles:{
admin:{
"*":"*"
},
user:{
"/files/public":"read",
"/blog/post":["read","write"],
"/files/userDir/*":["read","write"],
},
guest:{
"/files/public":"read",
"/blog/post":"read"
}
},
cb:(err,res)=>{
if (err) {
return console.log(err);
}
console.log("added roles:",res);
}
})
rbacc.addUserResources({
userId:"userId",
roles:["user"],
resources:{
"/files/myFiles":["read","write"],
"/files/otherFiles":"read",
},
cb:(err,res)=>{
if (err) {
return console.log(err)
}
console.log("added resources to user:",res)
}
})
rbacc.isAllowed({
userId:"userId",
resource:"/files/userDir/584ds215fe812/data",
premision:"read",
cb:(err,res)=>{
if (err) {
return console.log(err);
}
console.log("/files/userDir/584ds215fe812/data:read - ",res);
}
})
rbacc.isAllowed({
userId:"userId",
resource:"/files/otherFiles",
premision:"read",
cb:(err,res)=>{
if (err) {
return console.log(err);
}
console.log("/files/otherFiles:read - ",res);
}
})