Comments (11)
Thanks for pointing this out. My initial plan is using a RWMutex, Enforcer.Enforce()
will be protected with read lock and functions like Enforcer.AddRoleForUser()
will be protected with write lock, what do you think?
from casbin.
For my use case this is workable. If anyone else has performance concerns and does not have the use case of dynamic policies etc. this could be made as a thin wrapper.
from casbin.
I have added a wrapper here: 9251d5d
from casbin.
This looks great and it dropped in without issues, after a bit of testing I'll go ahead and close this thread. Thanks!
from casbin.
The Safe variants of methods (ones that return an error instead of panic) aren't thread safe at the moment because they are not wrapped.
from casbin.
@e-nikolov , we have "Safe" methods and "Synced" enforcer. These are two different things. "Safe" methods return error instead of causing panic. "Synced" enforcer will provide thread safe. You should use this: https://github.com/casbin/casbin/blob/master/enforcer_synced.go
from casbin.
@hsluoyz I know that, but the safe methods are also available from the synced enforcer, however they are not thread safe because they are not wrapped with mutexes the way the non-safe methods are.
from casbin.
OK. So you need both safe methods and synced enforcer at the same time, right? We can add the enforcer_safe_synced.go
file to implement those functions.
Can you send a PR for it? I can also do it but it may take several days.
from casbin.
BTW, you can also propose a new issue to claim this problem, as this issue has already been closed for long time.
from casbin.
I could make a PR. I am only thinking that in the current model, there are enforcer, enforcer_synced, enforcer_safe, enforcer_cached
. So every time that a new combination of those is needed, methods would sort of have to be duplicated. Is it an option to use something like Functional Options, and be able to do this: casbin.NewEnforcer(casbin.Synced(), casbin.Cached())
?
from casbin.
casbin.NewEnforcer(casbin.Synced(), casbin.Cached())
will make the constructor even complicated. Do we have a non-intrusive way to specify synced or cached? e.g., enforcer.enableCache(), enforcer.enableSync()
?
from casbin.
Related Issues (20)
- [Bug] RoleManager's MatchingFunc Lost After Calling (*SyncedEnforcer).LoadPolicyFast HOT 2
- [Bug] json request does not support arrays HOT 3
- [Bug] Whenever I use the GetRolesForUser method, I always receive an error stating "invalid memory address or nil pointer dereference." HOT 6
- [Feature] GetImplicitPermissionsForUser optimize 99% latency by avoid using roleManager.hasLinkHelper HOT 1
- [Feature] Adapter supports ctx HOT 3
- [Question] RBAC matcher function isn't called with inherited roles HOT 1
- [Question] Condition Role Manager can support pattern domain For user -> role link HOT 3
- Error encountered when creating an Enforcer based on the ABAC model: extraneous or missing "in quoted field" HOT 2
- [Feature] support return err in GetPermissionsForUser HOT 3
- [Question] - How can I enforce hierarchy check for request to match both domain and tenant? HOT 1
- [Question] How to get permissions while using resource roles HOT 2
- [Question] How to delete role in domain HOT 2
- [Question] HOT 2
- [Question] Why doesn't DeleteRole delete role completely from the policies? HOT 1
- Issue with non-functional Chinese language switch feature on GitHub documentation HOT 1
- [Question] Why CachedEnforcer uses sync.RWMutex just like sync.Mutex? HOT 6
- [Question] Is it expected that keyMatch3 handles `*` pattern? HOT 3
- [Bug]`GetRolesForUser("userId")` will raise nil error when using RBAC with conditions. HOT 5
- [Bug] nil pointer panic when calling role related functions with no role definition model HOT 2
- [Question] Implement row-level and column-level authorization for data in DB HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from casbin.