casbin / jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
https://casbin.org
Apache License 2.0
2.38k stars 461 forks source link

ABAC roles #13

Closed ondesPositives closed 5 years ago

ondesPositives commented 5 years ago

Hi. I want to use the abac part of jcasbin. The problem is that I couldn't find where to define the attributes variables , example (r_obj.owner, r.sub.branch).

For this example that already exists:

[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) || r.sub == r.obj.owner) && r.obj == p.obj && r.act == p.act
I got this: Exception in thread "main" com.googlecode.aviator.exception.ExpressionRuntimeException: Could not find variable r_obj.owner
    at com.googlecode.aviator.runtime.type.AviatorJavaType.getProperty(AviatorJavaType.java:301)
    at com.googlecode.aviator.runtime.type.AviatorJavaType.getValue(AviatorJavaType.java:251)
    at com.googlecode.aviator.runtime.type.AviatorJavaType.compare(AviatorJavaType.java:381)
    at Script_1551791355988_0/1869997857.execute0(Unknown Source)
    at com.googlecode.aviator.ClassExpression.execute(ClassExpression.java:72)
    at org.casbin.jcasbin.main.CoreEnforcer.enforce(CoreEnforcer.java:345)
    at Server.main(Server.java:131)
.....

Would you please help me! Thanks

hsluoyz commented 5 years ago

@ondesPositives see: https://casbin.org/docs/en/abac

hsluoyz commented 5 years ago

Closed as solved.

ondesPositives commented 5 years ago

Thank you for your help

w-k-s commented 3 years ago

Can you please provide an example of how to do this in Java. The documentation is thread-bare

hsluoyz commented 3 years ago

@w-k-s see:

https://github.com/casbin/jcasbin/blob/dc122cd5aadddfa79c2538fd11d3129b571c8125/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java#L312-L345