From c0204990a6e085347b1c462e70083a68e052dc9f Mon Sep 17 00:00:00 2001 From: luxurong Date: Tue, 6 Sep 2022 13:52:20 +0800 Subject: [PATCH] 1 --- .../quickmsg/core/acl/JCasBinAclManager.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/smqtt-core/src/main/java/io/github/quickmsg/core/acl/JCasBinAclManager.java b/smqtt-core/src/main/java/io/github/quickmsg/core/acl/JCasBinAclManager.java index 99f72f3d..ad0ee49e 100644 --- a/smqtt-core/src/main/java/io/github/quickmsg/core/acl/JCasBinAclManager.java +++ b/smqtt-core/src/main/java/io/github/quickmsg/core/acl/JCasBinAclManager.java @@ -48,25 +48,31 @@ public class JCasBinAclManager implements AclManager { try { enforcer = new Enforcer(model, new JDBCAdapter(jdbcAclConfig.getDriver(), jdbcAclConfig.getUrl(), jdbcAclConfig.getUsername(), jdbcAclConfig.getPassword())); + this.loadAclCache(); } catch (Exception e) { log.error("init acl jdbc error {}", aclConfig, e); } } else if (aclConfig.getAclPolicy() == AclPolicy.FILE) { enforcer = new Enforcer(model, new FileAdapter(aclConfig.getFilePath())); + this.loadAclCache(); } else { + isOpen = false; enforcer = new Enforcer(); } - enforcer.addFunction("filter", new AclFunction()); - List objects = enforcer.getAllObjects(); - List actions = enforcer.getAllActions(); - for (int i = 0; i < objects.size(); i++) { - Set allObjects = filterAclTopicActions.computeIfAbsent(actions.get(i), a -> new HashSet<>()); - allObjects.add(objects.get(i)); - } - isOpen = true; } } + private void loadAclCache() { + enforcer.addFunction("filter", new AclFunction()); + List objects = enforcer.getAllObjects(); + List actions = enforcer.getAllActions(); + for (int i = 0; i < objects.size(); i++) { + Set allObjects = filterAclTopicActions.computeIfAbsent(actions.get(i), a -> new HashSet<>()); + allObjects.add(objects.get(i)); + } + isOpen = true; + } + @Override public boolean check(MqttChannel mqttChannel, String source, AclAction action) { try { -- Gitee