184184 * @param rm the role manager.
185185]]
186186function CoreEnforcer :setRoleManager (rm )
187- self .rm = rm
187+ self .rmMap [ " g " ] = rm
188188end
189189
190190--[[
305305]]
306306function 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
429432end
430433
431- function CoreEnforcer :setAutoNotifyWatcher ()
434+ function CoreEnforcer :setAutoNotifyWatcher (autoNotifyWatcher )
432435 self .autoNotifyWatcher = autoNotifyWatcher
433436end
434437
@@ -440,4 +443,33 @@ function CoreEnforcer:setAutoNotifyDispatcher(autoNotifyDispatcher)
440443 self .autoNotifyDispatcher = autoNotifyDispatcher
441444end
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+
443475return CoreEnforcer
0 commit comments