This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Subject.doAs(MY_USER, (PrivilegedAction<Void>) () -> { | |
cache.put("key", "value"); | |
} |
We also provided an implementation which, instead of relying on enabling the SecurityManager, could use a lighter and faster ThreadLocal for storing the Subject:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Security.doAs(MY_USER, (PrivilegedAction<Void>) () -> { | |
cache.put("key", "value"); | |
} |
While this solves the performance issue, it still leads to unreadable code.
This is why, in Infinispan 9.1 we have introduced a new way to perform authorization on caches:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cache.withSubject(MY_USER).put("key", "value"); |
Obviously, for multiple invocations, you can hold on to the "impersonated" cache and reuse it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cache<String, String> myUserCache = cache.withSubject(MY_USER); | |
myUserCache.put("key", "value"); | |
myUserCache.put("anotherkey", "anothervalue"); |
We hope this will make your life simpler and your code more readable !
No comments:
Post a Comment