mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 01:44:08 +00:00
support access annotation with DOOP
This commit is contained in:
parent
46b67d200e
commit
79cd1d1781
@ -8,7 +8,7 @@ plugins {
|
|||||||
apply from: '../spotless.gradle'
|
apply from: '../spotless.gradle'
|
||||||
|
|
||||||
group = "org.bdware.sc"
|
group = "org.bdware.sc"
|
||||||
version = "1.9.91"
|
version = "1.9.95"
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
// options.compilerArgs << '-Xlint:none'
|
// options.compilerArgs << '-Xlint:none'
|
||||||
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
// options.compilerArgs << '-Xlint:deprecation' << "-Werror"
|
||||||
|
@ -10,6 +10,7 @@ import org.bdware.sc.bean.ContractRequest;
|
|||||||
import org.bdware.sc.boundry.ScriptReturnException;
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
import org.bdware.sc.engine.DesktopEngine;
|
import org.bdware.sc.engine.DesktopEngine;
|
||||||
import org.bdware.sc.engine.JSONTool;
|
import org.bdware.sc.engine.JSONTool;
|
||||||
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.AnnotationHook;
|
import org.bdware.sc.node.AnnotationHook;
|
||||||
import org.bdware.sc.node.AnnotationNode;
|
import org.bdware.sc.node.AnnotationNode;
|
||||||
import org.bdware.sc.node.ArgPacks;
|
import org.bdware.sc.node.ArgPacks;
|
||||||
@ -42,19 +43,17 @@ public class AccessHandler implements AnnotationHook {
|
|||||||
@Override
|
@Override
|
||||||
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
public ArgPacks handle(JSEngine desktopEngine, ArgPacks argPacks) {
|
||||||
if (requireSign) {
|
if (requireSign) {
|
||||||
if (!argPacks.request.verifySignature()) {
|
if (!verifyRequest(argPacks)) {
|
||||||
throw new ScriptReturnException(
|
throw new ScriptReturnException(
|
||||||
JsonParser.parseString("{\"code\":400,\"msg\":\"permission denied\"}"));
|
JsonParser.parseString("{\"code\":400,\"msg\":\"permission denied\"}"));
|
||||||
}
|
}
|
||||||
return argPacks;
|
return argPacks;
|
||||||
}
|
}
|
||||||
if (!argPacks.request.verifySignature()) {
|
if (!verifyRequest(argPacks)) {
|
||||||
LOGGER.info("verify failed! clear requester," + argPacks.request.getContentStr()
|
LOGGER.info("verify failed! clear requester," + argPacks.request.getContentStr()
|
||||||
+ " -> " + argPacks.request.getPublicKey() + "sign:"
|
+ " -> " + argPacks.request.getPublicKey() + "sign:"
|
||||||
+ argPacks.request.getSignature());
|
+ argPacks.request.getSignature());
|
||||||
// TODO
|
argPacks.request.setRequester(null);
|
||||||
// FIXME here!
|
|
||||||
// argPacks.request.setRequester(null);
|
|
||||||
} else
|
} else
|
||||||
LOGGER.info("verify success!" + argPacks.request.getRequester());
|
LOGGER.info("verify success!" + argPacks.request.getRequester());
|
||||||
if (acFunction == null)
|
if (acFunction == null)
|
||||||
@ -78,4 +77,11 @@ public class AccessHandler implements AnnotationHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean verifyRequest(ArgPacks argPacks) {
|
||||||
|
if (argPacks.arg != null && argPacks.arg instanceof DoipMessagePacker) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return argPacks.request.verifySignature();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import org.bdware.doip.endpoint.server.NettyServerHandler;
|
|||||||
import org.bdware.sc.ContractProcess;
|
import org.bdware.sc.ContractProcess;
|
||||||
import org.bdware.sc.bean.ContractRequest;
|
import org.bdware.sc.bean.ContractRequest;
|
||||||
import org.bdware.sc.boundry.JavaScriptEntry;
|
import org.bdware.sc.boundry.JavaScriptEntry;
|
||||||
|
import org.bdware.sc.boundry.ScriptReturnException;
|
||||||
import org.bdware.sc.crdt.SharableVarManager;
|
import org.bdware.sc.crdt.SharableVarManager;
|
||||||
import org.bdware.sc.entity.DoipMessagePacker;
|
import org.bdware.sc.entity.DoipMessagePacker;
|
||||||
import org.bdware.sc.node.FunctionNode;
|
import org.bdware.sc.node.FunctionNode;
|
||||||
@ -22,6 +23,7 @@ import org.bdware.sc.util.JsonUtil;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -79,6 +81,14 @@ public class DOOPRequestHandler implements DoipRequestHandler {
|
|||||||
finalDoipMsg.header.parameters.attributes.addProperty("nodeID",
|
finalDoipMsg.header.parameters.attributes.addProperty("nodeID",
|
||||||
String.valueOf(JavaScriptEntry.shardingID));
|
String.valueOf(JavaScriptEntry.shardingID));
|
||||||
return finalDoipMsg;
|
return finalDoipMsg;
|
||||||
|
} catch (ScriptReturnException e) {
|
||||||
|
DoipMessageFactory.DoipMessageBuilder builder =
|
||||||
|
new DoipMessageFactory.DoipMessageBuilder();
|
||||||
|
builder.createResponse(DoipResponseCode.Declined, msg);
|
||||||
|
builder.setBody(e.message.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
logger.error(
|
||||||
|
"buildRequestAndInvokeEngine catch ScriptReturnException");
|
||||||
|
return builder.create();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
ByteArrayOutputStream bo = new ByteArrayOutputStream();
|
||||||
e.printStackTrace(new PrintStream(bo));
|
e.printStackTrace(new PrintStream(bo));
|
||||||
|
Loading…
Reference in New Issue
Block a user