Casbin Forum runs on Casnode, the open-source Discourse-style forum. Try the Casnode demo →
Casbin Forum

I'm using JCasbin with the ABAC model. What structure should an object that's being passed into the enforce method have? Let's say my policy rule is sub.balance > 1000, does that mean the object that I pass in must have a public attribute balance?

6views
3users
2 minread

I've read the doc but it doesn't specify the structure of the class you should pass in, specifically for JCasbin, it simply mentions: Pass in the struct or class instance for the element as an argument to Casbin's Enforce() function.

Provide more details. I've been struggling lately with Casbin but that situation has helped me to reach understanding. Gpt4 is no the best on Casbin but helps.

I am using JCasbin with the ABAC model. Suppose I have a policy authTransaction, r.user.balance > 1000, I now need to pass in a user object into the enforce method to determine if a user can perform a transaction. I want to know what structure the user object that is being passed into enforce should have, should it just be a regular java object with a single public attribute balance?

My matcher uses the eval function to evaluate the policy rule

Can you send a casbin editor to see how matcher, policies and enforcement requests look like?. Your question is specific to Java Library or core Casbin functionality? If the later, we can help with the a editor instance

sure give me one second

my question is specific to the java version of casbin, JCasbin

with NodeCasbin this process is pretty straightforward

Oh sorry, I use casbin with python, where the enforcement is just as you do in the editor, you send the enforcement requests literals as they are defined in model.p

UserId, resource, action, balance

Balance not necessarily if you save their balance on a g policy user vs balance

I recommend you to make a github search for java projects using keywords that matches with casbin and enforcement keywords

From my understanding the model syntax is standardised between different distributions of casbin but the expression syntax is not due to the use of different expressions evaluators on different platforms (e.g. aviatorscript on jCasbin and expression-eval on Node-Casbin), is this correct?

Shouldn't be IMO... It should be agnostic, enforcement request is via literals defined in model p line. Your app defines the values to be passed to the enforcer, if there is a layer between your app and the enforcer, then it is a middleware, middleware receives objects from the app and passes enforcement request as plain text to casbin. That's my current understanding and I dont use middlewares I go directly to the enforcer like enforce(user-11, video-123, watch, 10-credits). But I know Java might be "easier" because everything should be mapped with something, easier not simpler.

Oh ok. Sorry for the misunderstanding, yes that maybe is advanced casbin, me just learning that crazy stuff

For anyone who might come across this in the future, it must be a java bean for its attributes to be accessed correctly in any expression evaluated using eval based on a mix of my testing and GPT4. Hence if you want to access an attribute called balance, the class must have a public getter method called getBalance.

I saw but wasn't sure if it must be a java bean or if public attributes will also work

1 / 20
Aug 2023