Skip to content

Commit e355189

Browse files
authored
Merge pull request #53 from rushitote/master
feat: Added RBAC API
2 parents e902bbe + 2f97653 commit e355189

File tree

8 files changed

+1066
-4
lines changed

8 files changed

+1066
-4
lines changed

src/main/CoreEnforcer.lua

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ end
184184
* @param rm the role manager.
185185
]]
186186
function CoreEnforcer:setRoleManager(rm)
187-
self.rm = rm
187+
self.rmMap["g"] = rm
188188
end
189189

190190
--[[
@@ -305,6 +305,9 @@ end
305305
]]
306306
function CoreEnforcer:enforce(...)
307307
local rvals = {...}
308+
if type(rvals[1]) == "table" and #rvals == 1 then
309+
rvals = rvals[1]
310+
end
308311

309312
if not self.enabled then
310313
return false
@@ -335,7 +338,7 @@ function CoreEnforcer:enforce(...)
335338
end
336339

337340
local expString = self.model.model["m"]["m"].value
338-
-- TODO: hasEval
341+
339342
local policyLen = #self.model.model["p"]["p"].policy
340343

341344
local policyEffects = {}
@@ -428,7 +431,7 @@ function CoreEnforcer:isAutoNotifyWatcher()
428431
return self.autoNotifyWatcher
429432
end
430433

431-
function CoreEnforcer:setAutoNotifyWatcher()
434+
function CoreEnforcer:setAutoNotifyWatcher(autoNotifyWatcher)
432435
self.autoNotifyWatcher = autoNotifyWatcher
433436
end
434437

@@ -440,4 +443,33 @@ function CoreEnforcer:setAutoNotifyDispatcher(autoNotifyDispatcher)
440443
self.autoNotifyDispatcher = autoNotifyDispatcher
441444
end
442445

446+
-- BatchEnforce enforce in batches and returns table of results
447+
function CoreEnforcer:BatchEnforce(requests)
448+
local results = {}
449+
for _, request in pairs(requests) do
450+
local res = self:enforce(request)
451+
table.insert(results, res)
452+
end
453+
454+
return results
455+
end
456+
457+
-- AddNamedMatchingFunc add MatchingFunc by ptype RoleManager
458+
function CoreEnforcer:AddNamedMatchingFunc(ptype, fn)
459+
if self.rmMap[ptype] then
460+
self.rmMap[ptype].matchingFunc = fn
461+
return true
462+
end
463+
return false
464+
end
465+
466+
-- AddNamedDomainMatchingFunc add MatchingFunc by ptype to RoleManager
467+
function CoreEnforcer:AddNamedDomainMatchingFunc(ptype, fn)
468+
if self.rmMap[ptype] then
469+
self.rmMap[ptype].domainMatchingFunc = fn
470+
return true
471+
end
472+
return false
473+
end
474+
443475
return CoreEnforcer

0 commit comments

Comments
 (0)