lua-casbin icon indicating copy to clipboard operation
lua-casbin copied to clipboard

enforce error

Open transtone opened this issue 1 year ago • 2 comments

there is a error when use keymatch4 in model.conf

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && keyMatch4(r.obj, p.obj) && regexMatch(r.act, p.act)
local Enforcer = require("casbin")

local e = Enforcer:new("/opt/openresty/nginx/conf/lua/casbin/rbac_model.conf", "/opt/openresty/nginx/conf/lua/casbin/examples/rbac_policy.csv")

local cjson = require "cjson"
local response = {}

local sub = "alice" -- the user that wants to access a resource.
local obj = "data1" -- the resource that is going to be accessed.
local act = "read" -- the operation that the user performs on the resource.

if e:enforce(sub, obj, act) then
  response['code'] = 200
  response['result'] = true
  response['msg'] = e:GetPolicy()
  ngx.say(cjson.encode(response))
end

2023/12/12 18:42:33 [error] 208585#0: *4 lua entry thread aborted: runtime error: 
...openresty/luajit/share/lua/5.1/src/main/CoreEnforcer.lua:449: attempt to concatenate field 'message' (a nil value)
stack traceback:
coroutine 0:
        ...openresty/luajit/share/lua/5.1/src/main/CoreEnforcer.lua: in function 'enforceEx'
        ...openresty/luajit/share/lua/5.1/src/main/CoreEnforcer.lua:534: in function 'enforce'

transtone avatar Dec 12 '23 10:12 transtone

@Edmond-J-A @rushitote @techoner

casbin-bot avatar Dec 12 '23 10:12 casbin-bot

@transtone it seems that your error doesn't match with your source code, the error shows enforceEx and a field called message, but your code never mentioned those. So why is that?

hsluoyz avatar Dec 20 '23 12:12 hsluoyz