mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
merge newest origin/master
This commit is contained in:
commit
14e5fffe1d
@ -6,7 +6,11 @@ plugins {
|
||||
}
|
||||
|
||||
group = "org.bdware.sc"
|
||||
<<<<<<< HEAD
|
||||
version = "2.0.0"
|
||||
=======
|
||||
version = "1.7.2"
|
||||
>>>>>>> origin/master
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
@ -61,7 +65,7 @@ jar {
|
||||
// uncomment this when publish,
|
||||
//while develop at local use "false"
|
||||
configurations.runtimeClasspath.filter {
|
||||
// it.getAbsolutePath().contains("/lib/")
|
||||
// it.getAbsolutePath().contains("/lib/")
|
||||
false
|
||||
}.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
|
@ -63,7 +63,8 @@ public class DebugMain {
|
||||
= new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(String str) {
|
||||
LOGGER.debug(str);
|
||||
|
||||
LOGGER.info("[PrintCB] " + str);
|
||||
}
|
||||
};
|
||||
ContractProcess.instance.handler.setDBInfo(wrap("", config.dbPath), printCallback);
|
||||
@ -80,7 +81,7 @@ public class DebugMain {
|
||||
Map<String, Object> resp = HttpUtil.httpGet(url);
|
||||
|
||||
String data = (String) resp.get("response");
|
||||
// LOGGER.info(JsonUtil.toPrettyJson(JsonUtil.parseStringAsJsonObject(data)));
|
||||
LOGGER.info(JsonUtil.toPrettyJson(JsonUtil.parseStringAsJsonObject(data)));
|
||||
LOGGER.info("start done!");
|
||||
}
|
||||
|
||||
|
@ -554,7 +554,6 @@ public class ContractProcess {
|
||||
if (fun.isConfidential()) {
|
||||
fun.appendBeforeInvokeHandler(new ConfidentialHandler(fun));
|
||||
}
|
||||
|
||||
ArgSchemaHandler argSchemaHandler = createHandlerIfExist(fun, fun.annotations, ArgSchemaHandler.class);
|
||||
if (argSchemaHandler != null) {
|
||||
fun.appendBeforeInvokeHandler(argSchemaHandler);
|
||||
@ -566,6 +565,10 @@ public class ContractProcess {
|
||||
|
||||
if (fun.isExport()) {
|
||||
//if(fun.annotations...)
|
||||
AccessHandler accessHandler = createHandlerIfExist(fun,fun.annotations,AccessHandler.class);
|
||||
if (accessHandler != null) {
|
||||
fun.appendBeforeInvokeHandler(accessHandler);
|
||||
}
|
||||
fun.appendAfterInvokeHandler(new ObjToJsonHandler());
|
||||
// fun.appendBeforeInvokeHandler(new ReadMeHandler());
|
||||
// Mask是用于返回真正结果之后,做一些偏移,以保护数据隐私。
|
||||
|
@ -3,13 +3,14 @@ package org.bdware.sc.compiler.ap;
|
||||
import org.bdware.sc.compiler.AnnotationProcessor;
|
||||
import org.bdware.sc.node.AnnotationNode;
|
||||
import org.bdware.sc.node.ContractNode;
|
||||
import org.bdware.sc.node.FunctionNode;
|
||||
|
||||
public class Access extends AnnotationProcessor {
|
||||
@Override
|
||||
public void processContract(AnnotationNode anno, ContractNode contractNode) {
|
||||
contractNode.sigRequired = false;
|
||||
if (anno != null) {
|
||||
contractNode.sigRequired = "\"verified\"".equals(anno.getArgs().get(0));
|
||||
for (FunctionNode fn : contractNode.getFunctions()) {
|
||||
fn.addAnnotation(anno);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -608,33 +608,32 @@ public class DesktopEngine extends JSEngine {
|
||||
|
||||
public Object executeWithoutLock(FunctionNode fun, ContractRequest input, Object injectedArg) throws ScriptException, NoSuchMethodException {
|
||||
// long start = System.currentTimeMillis();
|
||||
ArgPacks argPack = new ArgPacks(input, input.getArg(), null);
|
||||
ArgPacks argPacks = new ArgPacks(input, input.getArg(), null);
|
||||
if(injectedArg != null) {
|
||||
argPack.arg = injectedArg;
|
||||
argPacks.arg = injectedArg;
|
||||
}
|
||||
for (AnnotationHook handler : fun.beforeExecutionAnnotations()) {
|
||||
argPack = handler.handle(this, argPack);
|
||||
argPacks = handler.handle(this, argPacks);
|
||||
}
|
||||
|
||||
// actually invoke!
|
||||
// todo 这里invoke应该如何调用,改了一行代码正确吗?input.getArg() -> argPack.arg
|
||||
if (argPack.ret == null) {
|
||||
argPack.ret =
|
||||
if (argPacks.ret == null) {
|
||||
argPacks.ret =
|
||||
engine.invokeFunction(
|
||||
input.getAction(),
|
||||
(fun.isHandler()
|
||||
? JsonUtil.fromJson(input.getArg(), Event.class)
|
||||
: JSONTool.convertJsonElementToMirror(argPack.arg)),
|
||||
: JSONTool.convertJsonElementToMirror(argPacks.arg)),
|
||||
input.getRequester(),
|
||||
input.getRequesterDOI());
|
||||
}
|
||||
|
||||
for (AnnotationHook handler : fun.afterExecutionAnnotations()) {
|
||||
//Mask在after裏面
|
||||
//System.out.println("afterHook"+contract.Mask);
|
||||
|
||||
argPack = handler.handle(this, argPack);
|
||||
argPacks = handler.handle(this, argPacks);
|
||||
}
|
||||
return argPack.ret;
|
||||
return argPacks.ret;
|
||||
}
|
||||
|
||||
private String extractException(String msg, List<String> stack) {
|
||||
|
78
src/main/java/org/bdware/sc/engine/hook/AccessHandler.java
Normal file
78
src/main/java/org/bdware/sc/engine/hook/AccessHandler.java
Normal file
@ -0,0 +1,78 @@
|
||||
package org.bdware.sc.engine.hook;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bdware.sc.JSEngine;
|
||||
import org.bdware.sc.bean.ContractRequest;
|
||||
import org.bdware.sc.boundry.ScriptReturnException;
|
||||
import org.bdware.sc.engine.DesktopEngine;
|
||||
import org.bdware.sc.engine.JSONTool;
|
||||
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 {
|
||||
public String acFunction;
|
||||
public boolean requireSign;
|
||||
|
||||
public AccessHandler(AnnotationNode annoNode) {
|
||||
requireSign = false;
|
||||
String content = annoNode.getArgs().get(0);
|
||||
JsonElement je = JsonParser.parseString(content);
|
||||
if (je.isJsonPrimitive() && je.getAsJsonPrimitive().getAsString().equals("verified")) {
|
||||
requireSign = true;
|
||||
}
|
||||
if (je.isJsonObject()) {
|
||||
acFunction = je.getAsJsonObject().get("ACFunction").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
public static AccessHandler fromAnnotationNode(FunctionNode funNode, AnnotationNode annoNode) {
|
||||
return new AccessHandler(annoNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||
if (requireSign) {
|
||||
if (!argPacks.request.verifySignature()) {
|
||||
throw new ScriptReturnException(JsonParser.parseString("{\"code\":400,\"msg\":\"permission denied\"}"));
|
||||
}
|
||||
return argPacks;
|
||||
}
|
||||
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);
|
||||
jo.put("action", input.getAction(), false);
|
||||
jo.put("arg", JSONTool.convertJsonElementToMirror(input.getArg()), false);
|
||||
de.engine.invokeFunction(acFunction, jo);
|
||||
return argPacks;
|
||||
} catch (ScriptReturnException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
JsonObject jo = new JsonObject();
|
||||
jo.addProperty("code", "401");
|
||||
jo.addProperty("msg", "access check meets exception! " + e);
|
||||
throw new ScriptReturnException(jo);
|
||||
} finally {
|
||||
if (globalChanged) Context.setGlobal(oldGlobal);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -29,7 +29,6 @@ public class ArgSchemaHandler implements AnnotationHook {
|
||||
}
|
||||
|
||||
public static ArgSchemaHandler fromAnnotationNode(FunctionNode funNode, AnnotationNode annoNode) {
|
||||
//a= annoNode;
|
||||
return new ArgSchemaHandler(annoNode);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user