From 144804efd01b1eb73729bfbbb84749b3a046d614 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Tue, 29 Nov 2022 15:14:57 +0800 Subject: [PATCH] add update node manager --- .../org/bdware/server/NodeCenterServer.java | 3 +- .../bdware/server/nodecenter/FileActions.java | 3 +- .../server/nodecenter/NCHttpHandler.java | 1 + .../server/nodecenter/NCManagerAction.java | 31 +++++++++++++++++-- .../server/nodecenter/NodeCenterActions.java | 4 +-- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/bdware/server/NodeCenterServer.java b/src/main/java/org/bdware/server/NodeCenterServer.java index 81c1a18..754c8f3 100644 --- a/src/main/java/org/bdware/server/NodeCenterServer.java +++ b/src/main/java/org/bdware/server/NodeCenterServer.java @@ -27,6 +27,7 @@ import org.bdware.sc.db.MultiIndexTimeRocksDBUtil; import org.bdware.sc.db.TimeDBUtil; import org.bdware.server.irp.LocalLHSProxy; import org.bdware.server.nodecenter.*; +import org.bdware.server.permission.Role; import org.bdware.server.ws.DelimiterCodec; import java.io.BufferedReader; @@ -143,7 +144,7 @@ public class NodeCenterServer { NCTables.ConfigDB.toString(), NCManagerAction.centerManger, pubKey); KeyValueDBUtil.instance.setValue( NCTables.ConfigDB.toString(), NCManagerAction.clusterName, "clusterName_" + pubKey.substring(0, 5)); - KeyValueDBUtil.instance.setValue(NCTables.NodeUser.toString(), pubKey, "NodeManager"); + KeyValueDBUtil.instance.setValue(NCTables.NodeUser.toString(), pubKey, Role.CenterManager.toString()); KeyValueDBUtil.instance.setValue( NCTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime())); LOGGER.info("set node manager from manager.key"); diff --git a/src/main/java/org/bdware/server/nodecenter/FileActions.java b/src/main/java/org/bdware/server/nodecenter/FileActions.java index c0ca4c3..10acf30 100644 --- a/src/main/java/org/bdware/server/nodecenter/FileActions.java +++ b/src/main/java/org/bdware/server/nodecenter/FileActions.java @@ -96,12 +96,11 @@ public class FileActions { String sign = transformedParam.get("sign"); boolean verify = SM2Util.plainStrVerify(pubkey, str, sign); - LOGGER.info("[CMHttpHandler] upload http请求验签结果 : " + verify); + LOGGER.info("[FileAction] upload http请求验签结果 : " + verify); if (verify) { // 查permission String ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubkey); - if (ret != null && ret.length() > 0) { permission = 0x86000d41L | Role.compoundValue(ret.split(",")); } else { diff --git a/src/main/java/org/bdware/server/nodecenter/NCHttpHandler.java b/src/main/java/org/bdware/server/nodecenter/NCHttpHandler.java index c3dd180..b9d3678 100644 --- a/src/main/java/org/bdware/server/nodecenter/NCHttpHandler.java +++ b/src/main/java/org/bdware/server/nodecenter/NCHttpHandler.java @@ -141,6 +141,7 @@ public class NCHttpHandler extends SimpleChannelInboundHandler { transformedParam.addProperty("permission", permission + ""); LOGGER.debug("[CMHttpHandler] http 请求查看用户权限为 : " + permission); } else { + transformedParam.remove("pubKey"); transformedParam.addProperty("permission", 0 + ""); } } diff --git a/src/main/java/org/bdware/server/nodecenter/NCManagerAction.java b/src/main/java/org/bdware/server/nodecenter/NCManagerAction.java index 7d62b06..a938680 100644 --- a/src/main/java/org/bdware/server/nodecenter/NCManagerAction.java +++ b/src/main/java/org/bdware/server/nodecenter/NCManagerAction.java @@ -122,7 +122,7 @@ public class NCManagerAction { String ret = KeyValueDBUtil.instance.getValue(NCTables.ConfigDB.toString(), centerManger); if (ret != null && ret.length() > 0) { - boolean isCenterManager = (ret.equals(pubKey)); // 表示此节点是否是平台管理员 + boolean isCenterManager = (ret.equals(pubKey)); //表示此节点是否是平台管理员 ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubKey); String role = ""; if (isCenterManager) { @@ -136,7 +136,8 @@ public class NCManagerAction { } else if (role.isEmpty()) { role = Role.Anonymous.name(); } - handler.setPermission(Role.compoundValue(role.split(","))); + if (handler != null) + handler.setPermission(Role.compoundValue(role.split(","))); simpleReply(resultCallback, "onLogin", role); } else { KeyValueDBUtil.instance.setValue( @@ -176,6 +177,32 @@ public class NCManagerAction { LOGGER.debug("time:" + (end - start)); } + @Action(userPermission = 0) + public void resetCenterManager(JsonObject json, ResultCallback resultCallback) { + getNodeRole(json, new ResultCallback() { + @Override + public void onResult(String str) { + if (str.contains(Role.CenterManager.toString())) { + if (json.has("newPubKey")) { + String newPubKey = json.get("newPubKey").getAsString(); + KeyValueDBUtil.instance.setValue(NCTables.ConfigDB.toString(), centerManger, newPubKey); + KeyValueDBUtil.instance.setValue( + NCTables.NodeUser.toString(), newPubKey, Role.CenterManager.toString()); + resultCallback.onResult("{\"action\":\"onResetCenterManager\",\"data\":\"success\",\"pubKey\":\"" + + newPubKey + "\"}"); + } else { + //just keep the same + resultCallback.onResult("{\"action\":\"onResetCenterManager\",\"data\":\"success\",\"pubKey\":\"" + + getPubKey(json) + "\"}"); + } + } else { + resultCallback.onResult("{\"action\":\"onResetCenterManager\",\"data\":\"failed, no permission\"}"); + } + + } + }); + } + @Action(userPermission = 0) public void applyRole(JsonObject json, ResultCallback resultCallback) { String pubKey = getPubKey(json); diff --git a/src/main/java/org/bdware/server/nodecenter/NodeCenterActions.java b/src/main/java/org/bdware/server/nodecenter/NodeCenterActions.java index b7ba3f9..9870bb7 100644 --- a/src/main/java/org/bdware/server/nodecenter/NodeCenterActions.java +++ b/src/main/java/org/bdware/server/nodecenter/NodeCenterActions.java @@ -199,10 +199,10 @@ public class NodeCenterActions { Long.toString(new Date().getTime())); return Role.Node.getValue(); */ + return Role.Anonymous.getValue(); // TODO fix permission bugs. - return Role.compoundValue(new String[]{"NodeManager"}); + // return Role.compoundValue(new String[]{"CenterManager"}); } else { - return (Role.compoundValue(ret.split(","))); } } catch (Exception e) {