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?
read docs first: https://casbin.org/docs/abac
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
no worries, thanks anyway
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
yeah that's what I'll do, thanks 👍
AI is your friend too, casbin doc is not the best tou
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.
I mean specifically the evaluation of expressions that are stored in policies e.g. p, policyName, 1 == 1 using the eval function described here: https://casbin.org/docs/abac/#scaling-the-model-for-complex-and-large-numbers-of-abac-rules
For example, the === operator seems to be supported in Node-Casbin due to the use of expression-eval for expression evaluation but not in jCasbin
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.
there's already a test in code, you missed it https://github.com/casbin/jcasbin/blob/8c50f922224b45b8788cd977eac1f107705afc0b/src/test/java/org/casbin/jcasbin/main/ModelUnitTest.java#L313
Well done mate!
I saw but wasn't sure if it must be a java bean or if public attributes will also work
Join the conversation
Sign up to reply, like and follow topics.
Suggested Topics
Want to read more? Browse other topics in Casbin or view latest topics.
