mirror of
https://gitee.com/BDWare/cp.git
synced 2026-01-29 01:29:27 +00:00
merge newest origin/master
This commit is contained in:
@@ -132,7 +132,8 @@ public class YJSCompiler {
|
||||
if (czb.containsPath(str)) {
|
||||
continue;
|
||||
}
|
||||
ZipEntry entry = zf.getEntry("/" + str);
|
||||
|
||||
ZipEntry entry = zf.getEntry(str.startsWith("/") ? str : "/" + str);
|
||||
if (null == entry) {
|
||||
throw new IllegalStateException("missing import:" + str);
|
||||
}
|
||||
|
||||
@@ -153,15 +153,15 @@ public class JSONTool {
|
||||
return JsonUtil.fromJson(JsonUtil.toJson(obj), JsonObject.class);
|
||||
}else if (obj instanceof Number) {
|
||||
return new JsonPrimitive((Number) obj);
|
||||
|
||||
} else if (obj instanceof String) {
|
||||
return new JsonPrimitive((String) obj);
|
||||
|
||||
} else if (obj instanceof Character) {
|
||||
return new JsonPrimitive((Character) obj);
|
||||
}
|
||||
if (obj instanceof Boolean) {
|
||||
} else if (obj instanceof Boolean) {
|
||||
return new JsonPrimitive((Boolean) obj);
|
||||
} else if (obj.getClass() == Boolean.TYPE) {
|
||||
return new JsonPrimitive((boolean) obj);
|
||||
|
||||
}
|
||||
return JsonNull.INSTANCE;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package org.bdware.sc.engine.hook;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bdware.sc.JSEngine;
|
||||
import org.bdware.sc.bean.ContractRequest;
|
||||
import org.bdware.sc.boundry.ScriptReturnException;
|
||||
@@ -12,13 +14,12 @@ import org.bdware.sc.node.AnnotationHook;
|
||||
import org.bdware.sc.node.AnnotationNode;
|
||||
import org.bdware.sc.node.ArgPacks;
|
||||
import org.bdware.sc.node.FunctionNode;
|
||||
import wrp.jdk.nashorn.internal.objects.Global;
|
||||
import wrp.jdk.nashorn.internal.runtime.Context;
|
||||
import wrp.jdk.nashorn.internal.runtime.PropertyMap;
|
||||
import wrp.jdk.nashorn.internal.scripts.JO;
|
||||
|
||||
@YJSAnnotation(name = "Access")
|
||||
public class AccessHandler implements AnnotationHook {
|
||||
static Logger LOGGER = LogManager.getLogger(AccessHandler.class);
|
||||
public String acFunction;
|
||||
public boolean requireSign;
|
||||
|
||||
@@ -46,15 +47,18 @@ public class AccessHandler implements AnnotationHook {
|
||||
}
|
||||
return argPacks;
|
||||
}
|
||||
if (!argPacks.request.verifySignature()) {
|
||||
LOGGER.info("verify failed! clear requester," + argPacks.request.getContentStr() +
|
||||
" -> " + argPacks.request.getPublicKey() + "sign:" + argPacks.request.getSignature());
|
||||
//TODO
|
||||
//FIXME here!
|
||||
// argPacks.request.setRequester(null);
|
||||
} else
|
||||
LOGGER.info("verify success!" + argPacks.request.getRequester());
|
||||
if (acFunction == null) return argPacks;
|
||||
DesktopEngine de = (DesktopEngine) desktopEngine;
|
||||
Global oldGlobal = Context.getGlobal();
|
||||
Global newGlobal = de.getDesktopGlobal();
|
||||
boolean globalChanged = (oldGlobal != newGlobal);
|
||||
|
||||
try {
|
||||
if (globalChanged) {
|
||||
Context.setGlobal(newGlobal);
|
||||
}
|
||||
ContractRequest input = argPacks.request;
|
||||
JO jo = new JO(PropertyMap.newMap());
|
||||
jo.put("requester", input.getRequester(), false);
|
||||
@@ -69,9 +73,6 @@ public class AccessHandler implements AnnotationHook {
|
||||
jo.addProperty("code", "401");
|
||||
jo.addProperty("msg", "access check meets exception! " + e);
|
||||
throw new ScriptReturnException(jo);
|
||||
} finally {
|
||||
if (globalChanged) Context.setGlobal(oldGlobal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user