Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用自己的验证模型一直无法通过验证 #1

Closed
tyson239 opened this issue Aug 27, 2019 · 9 comments
Closed

使用自己的验证模型一直无法通过验证 #1

tyson239 opened this issue Aug 27, 2019 · 9 comments
Labels
question Further information is requested

Comments

@tyson239
Copy link

tyson239 commented Aug 27, 2019

使用自己的验证模型,一直无法通过验证,但是数据库中记录是存在的。
image
使用

Enforcer::getPolicy();

也能打印出内容。

代码中执行:

    public function index(){
        print_r(Enforcer::getPolicy());
        $haspermission = Enforcer::enforce('backend', '31', '32', '/auth/login', '*');
        var_dump($haspermission);
        //返回了bool(false)
    }

手动添加一条规则再执行enforce,则能够返回true,但下一次请求又会变成false。

Enforcer::addPolicy('backend', '31', '32', '/auth/login', '*');

模型conf文件:

[request_definition]
r = end, school_id, user_id, path, method

[policy_definition]
p = end, school_id, user_id, path, method

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

[matchers]
m = r.end == p.end && r.school_id == p.school_id && r.user_id == p.user_id && keyMatch(r.path, p.path) && keyMatch(r.method, p.method)
@tyson239
Copy link
Author

好像找到了问题,获取Policy列表,所有的最后一个参数,末尾都有一个,
image

@leeqvip
Copy link
Member

leeqvip commented Aug 28, 2019

还有问题吗

@leeqvip leeqvip added the question Further information is requested label Aug 28, 2019
@tyson239
Copy link
Author

有,现在的问题就是Policy最后一个字段的末尾会多出一个,号,使用enforce时也要加上一个,号才能判断正确,但是在数据库中是没有这个,号的。

@leeqvip
Copy link
Member

leeqvip commented Aug 28, 2019

完整的rules表截个图

@tyson239
Copy link
Author

image
规则都是一样的,只是v1、v2不同。

@leeqvip
Copy link
Member

leeqvip commented Aug 28, 2019

没看到 v4=GET的呢

@tyson239
Copy link
Author

我是出了上面那个问题后,觉得可能是通配符问题才改成GET试试的,一样会有,的问题。

        $haspermission = Enforcer::getFilteredPolicy(0, 'backend', '2', '3');
        var_dump($haspermission);
  | array(1) {
-- | --
  | [0]=>
  | array(5) {
  | [0]=>
  | string(7) "backend"
  | [1]=>
  | string(1) "2"
  | [2]=>
  | string(1) "3"
  | [3]=>
  | string(11) "/auth/login"
  | [4]=>
  | string(2) "*,"
  | }
  | }
  |  

@leeqvip
Copy link
Member

leeqvip commented Aug 28, 2019

更新到最新开发版:

composer update casbin/think-authz:dev-master

@tyson239
Copy link
Author

好的,刚发现是composer镜像没有同步,前几天更新过也没发现。
更新后测试正常了,辛苦了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants