add update node manager

This commit is contained in:
CaiHQ 2022-11-29 15:14:57 +08:00
parent 6030bdf2ad
commit 144804efd0
5 changed files with 35 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import org.bdware.sc.db.MultiIndexTimeRocksDBUtil;
import org.bdware.sc.db.TimeDBUtil; import org.bdware.sc.db.TimeDBUtil;
import org.bdware.server.irp.LocalLHSProxy; import org.bdware.server.irp.LocalLHSProxy;
import org.bdware.server.nodecenter.*; import org.bdware.server.nodecenter.*;
import org.bdware.server.permission.Role;
import org.bdware.server.ws.DelimiterCodec; import org.bdware.server.ws.DelimiterCodec;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -143,7 +144,7 @@ public class NodeCenterServer {
NCTables.ConfigDB.toString(), NCManagerAction.centerManger, pubKey); NCTables.ConfigDB.toString(), NCManagerAction.centerManger, pubKey);
KeyValueDBUtil.instance.setValue( KeyValueDBUtil.instance.setValue(
NCTables.ConfigDB.toString(), NCManagerAction.clusterName, "clusterName_" + pubKey.substring(0, 5)); 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( KeyValueDBUtil.instance.setValue(
NCTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime())); NCTables.NodeTime.toString(), pubKey, Long.toString(new Date().getTime()));
LOGGER.info("set node manager from manager.key"); LOGGER.info("set node manager from manager.key");

View File

@ -96,12 +96,11 @@ public class FileActions {
String sign = transformedParam.get("sign"); String sign = transformedParam.get("sign");
boolean verify = SM2Util.plainStrVerify(pubkey, str, sign); boolean verify = SM2Util.plainStrVerify(pubkey, str, sign);
LOGGER.info("[CMHttpHandler] upload http请求验签结果 : " + verify); LOGGER.info("[FileAction] upload http请求验签结果 : " + verify);
if (verify) { if (verify) {
// 查permission // 查permission
String ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubkey); String ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubkey);
if (ret != null && ret.length() > 0) { if (ret != null && ret.length() > 0) {
permission = 0x86000d41L | Role.compoundValue(ret.split(",")); permission = 0x86000d41L | Role.compoundValue(ret.split(","));
} else { } else {

View File

@ -141,6 +141,7 @@ public class NCHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
transformedParam.addProperty("permission", permission + ""); transformedParam.addProperty("permission", permission + "");
LOGGER.debug("[CMHttpHandler] http 请求查看用户权限为 : " + permission); LOGGER.debug("[CMHttpHandler] http 请求查看用户权限为 : " + permission);
} else { } else {
transformedParam.remove("pubKey");
transformedParam.addProperty("permission", 0 + ""); transformedParam.addProperty("permission", 0 + "");
} }
} }

View File

@ -122,7 +122,7 @@ public class NCManagerAction {
String ret = String ret =
KeyValueDBUtil.instance.getValue(NCTables.ConfigDB.toString(), centerManger); KeyValueDBUtil.instance.getValue(NCTables.ConfigDB.toString(), centerManger);
if (ret != null && ret.length() > 0) { if (ret != null && ret.length() > 0) {
boolean isCenterManager = (ret.equals(pubKey)); // 表示此节点是否是平台管理员 boolean isCenterManager = (ret.equals(pubKey)); //表示此节点是否是平台管理员
ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubKey); ret = KeyValueDBUtil.instance.getValue(NCTables.NodeUser.toString(), pubKey);
String role = ""; String role = "";
if (isCenterManager) { if (isCenterManager) {
@ -136,6 +136,7 @@ public class NCManagerAction {
} else if (role.isEmpty()) { } else if (role.isEmpty()) {
role = Role.Anonymous.name(); role = Role.Anonymous.name();
} }
if (handler != null)
handler.setPermission(Role.compoundValue(role.split(","))); handler.setPermission(Role.compoundValue(role.split(",")));
simpleReply(resultCallback, "onLogin", role); simpleReply(resultCallback, "onLogin", role);
} else { } else {
@ -176,6 +177,32 @@ public class NCManagerAction {
LOGGER.debug("time:" + (end - start)); 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) @Action(userPermission = 0)
public void applyRole(JsonObject json, ResultCallback resultCallback) { public void applyRole(JsonObject json, ResultCallback resultCallback) {
String pubKey = getPubKey(json); String pubKey = getPubKey(json);

View File

@ -199,10 +199,10 @@ public class NodeCenterActions {
Long.toString(new Date().getTime())); Long.toString(new Date().getTime()));
return Role.Node.getValue(); return Role.Node.getValue();
*/ */
return Role.Anonymous.getValue();
// TODO fix permission bugs. // TODO fix permission bugs.
return Role.compoundValue(new String[]{"NodeManager"}); // return Role.compoundValue(new String[]{"CenterManager"});
} else { } else {
return (Role.compoundValue(ret.split(","))); return (Role.compoundValue(ret.split(",")));
} }
} catch (Exception e) { } catch (Exception e) {