Skip to content

Commit 4ecff15

Browse files
Copilothsluoyz
andcommitted
fix(core): add synchronization to addLink to prevent race conditions
Add synchronized keyword to addLink method to ensure thread safety. The method now performs compound operations (check -> add -> check -> rollback) which could lead to race conditions without proper synchronization. This aligns with the existing synchronized hasLink method. Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
1 parent 53da062 commit 4ecff15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/java/org/casbin/jcasbin/rbac/DefaultRoleManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void clear() {
168168
* inherits role: name2. domain is a prefix to the roles.
169169
*/
170170
@Override
171-
public void addLink(String name1, String name2, String... domain) {
171+
public synchronized void addLink(String name1, String name2, String... domain) {
172172
Role user = getRole(name1);
173173
Role role = getRole(name2);
174174

0 commit comments

Comments
 (0)