Hi all, this is a followup back again - now with a different model and policies, but with the same result as #2 (sorry for not replying earlier, I had to move to different projects unexpectedly). The problem is possibly related to https://github.com/php-casbin/php-casbin/issues/61 ... When using the file adapter, i get i.e. 47 lines, when I use the database, I get 2013 lines. For example, with
[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
g2 = _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub, r.dom) && g2(r.dom, p.dom) && keyMatch2(r.obj, p.obj) && r.act == p.act
... During my testing of casbin, I first noted that I must envelope the addPolicy with a hasPolicy method, otherwise I get duplocate data.
if (!$m->hasPolicy('g', 'g2', $rule)) {
$m->addPolicy('g', 'g2', $rule);
$e->savePolicy();
}
I also noticed, that integers in the $rule array (where strings are expected, but not type-enforced) cause another set of duplication. Upon writing a wrapper function, that casts all $rule elements to string. the problem with duplicate data disappeared when using the file adapter, but remains with the database adapter.
Either there's a difference in how data are handled by the adapters before storing them, or its the difference between mysql and a textfile. The sql table uses varchar, so that should be fine, but it inherits from the database the default charset (in my case utf8mb4_0900_ai_ci) , which means accent and case insensitive. I can't imagine how numbers could be a problem, but there's a lot to consider.
I think php-casbin and the database-adapter need a stricter type checking and comparing to avoid these problems.
Hi all, this is a followup back again - now with a different model and policies, but with the same result as #2 (sorry for not replying earlier, I had to move to different projects unexpectedly). The problem is possibly related to https://github.com/php-casbin/php-casbin/issues/61 ... When using the file adapter, i get i.e. 47 lines, when I use the database, I get 2013 lines. For example, with
and model
... During my testing of casbin, I first noted that I must envelope the addPolicy with a hasPolicy method, otherwise I get duplocate data.
if (!$m->hasPolicy('g', 'g2', $rule)) { $m->addPolicy('g', 'g2', $rule);
$e->savePolicy(); }
I also noticed, that integers in the $rule array (where strings are expected, but not type-enforced) cause another set of duplication. Upon writing a wrapper function, that casts all $rule elements to string. the problem with duplicate data disappeared when using the file adapter, but remains with the database adapter.
Either there's a difference in how data are handled by the adapters before storing them, or its the difference between mysql and a textfile. The sql table uses varchar, so that should be fine, but it inherits from the database the default charset (in my case utf8mb4_0900_ai_ci) , which means accent and case insensitive. I can't imagine how numbers could be a problem, but there's a lot to consider.
I think php-casbin and the database-adapter need a stricter type checking and comparing to avoid these problems.