Skip to content

Commit

Permalink
feat: add DistributedEnforcer auto-configuration via useDistributedEn…
Browse files Browse the repository at this point in the history
…forcer
  • Loading branch information
jay-babu committed Jun 30, 2024
1 parent aef3b87 commit 82fed55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.casbin.annotation.CasbinDataSource;
import org.casbin.exception.CasbinAdapterException;
import org.casbin.exception.CasbinModelConfigNotFoundException;
import org.casbin.jcasbin.main.DistributedEnforcer;
import org.casbin.jcasbin.main.Enforcer;
import org.casbin.jcasbin.main.SyncedEnforcer;
import org.casbin.jcasbin.model.Model;
Expand Down Expand Up @@ -147,7 +148,10 @@ public Enforcer enforcer(CasbinProperties properties, Adapter adapter) {
model.addDef("m", "m", "g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act");
}
Enforcer enforcer;
if (properties.isUseSyncedEnforcer()) {
if (properties.isUseDistributedEnforcer()) {
enforcer = new DistributedEnforcer(model, adapter);
logger.info("Casbin use DistributedEnforcer");
} else if (properties.isUseSyncedEnforcer()) {
enforcer = new SyncedEnforcer(model, adapter);
logger.info("Casbin use SyncedEnforcer");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class CasbinProperties {
* Whether to use a synchronized Enforcer
*/
private boolean useSyncedEnforcer = false;
/**
* Whether to use a distributed Enforcer
*/
private boolean useDistributedEnforcer = false;
/**
* Local model file
*/
Expand Down Expand Up @@ -111,6 +115,14 @@ public void setUseSyncedEnforcer(boolean useSyncedEnforcer) {
this.useSyncedEnforcer = useSyncedEnforcer;
}

public boolean isUseDistributedEnforcer() {
return useDistributedEnforcer;
}

public void setUseDistributedEnforcer(boolean useDistributedEnforcer) {
this.useDistributedEnforcer = useDistributedEnforcer;
}

public String getModel() {
return model;
}
Expand Down

0 comments on commit 82fed55

Please sign in to comment.