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