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

能否讲解一下JWT与Casbin在本项目的使用? #14

Closed
ahua772 opened this issue Apr 3, 2020 · 2 comments
Closed

能否讲解一下JWT与Casbin在本项目的使用? #14

ahua772 opened this issue Apr 3, 2020 · 2 comments

Comments

@ahua772
Copy link

ahua772 commented Apr 3, 2020

首先非常感谢作者的开源,该项目是一个非常好的项目,但是在jwt与casbin部分并不是很懂,不知是否可以讲解本项目在这块是怎么使用的,大致思路即可

@wenjianzhang
Copy link
Member

wenjianzhang commented Apr 3, 2020

  • jwt只是验证用户是否有权访问
  • casbin是验证有权限的角色能够访问哪些资源

casbin 在项目中的使用:

首先需要制定自己的策略配置,什么是策略配置呢?

例如:

p,common,/api/v1/menulist,GET

这就是一组用户角色映射关系

common 角色能够访问资源 /api/v1/menulistGET 方式。

规则:

[policy_definition]
p = sub, obj, act

[matchers]

m = r.sub == p.sub && (keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj)) && (r.act == p.act || p.act == "*")

p = sub, obj, act >> p,common,/api/v1/menulist,GET

keyMatch2(r.obj, p.obj) || keyMatch(r.obj, p.obj) 资源匹配规则内置提供的有一些匹配函数,因为我们项目中使用到了path参数,所以这里做了两种匹配的或计算。

以上内容是配置文件规则的简单说明,在程序里边只不过是按照上述规则进行动态的计算罢了。

另外就是使用顺序,JWT 在前,Casbin在后,这个知道为什么吗?如果想知道请留言吧。

@W-Jie
Copy link

W-Jie commented Jul 29, 2020

另外就是使用顺序,JWT 在前,Casbin在后,这个知道为什么吗?如果想知道请留言吧。

想知道,望解答,谢谢

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

No branches or pull requests

3 participants