Skip to main content
Version: 3.10

OverriddenLogic 覆写逻辑

1. 结构声明

class OverriddenLogic extends BaseNode {
overriddenModule: string;
name: string = '';
description: string;
triggerType?: string;
cron?: string;
transactional?: Transactional;
typeParams?: Array<TypeParam>;
params: Array<Param>;
returns: Array<Return>;
variables: Array<Variable>;
body: Array<LogicItem>;
playground: Array<LogicItem>;
}

2. 节点示例

(1) 示例

AST 如下:

{
"concept": "OverriddenLogic",
"overriddenModule": "lcap_permission",
"name": "checkPermission",
"description": "校验用户访问资源的权限",
"triggerType": "",
"cron": "",
"transactional": {
"concept": "Transactional",
"enabled": false
},
"params": [
{
"concept": "Param",
"name": "userId",
"description": "用户唯一标识",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "resourceValue",
"description": "资源值(通常为浏览器上的访问路径)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "resourceType",
"description": "资源的类型(表示当前资源是页面还是组件)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
},
{
"concept": "Param",
"name": "clientType",
"description": "资源所属的端标识(多端场景下存在重名资源)",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
}
}
],
"returns": [
{
"concept": "Return",
"name": "result",
"description": "用户是否能访问指定资源",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Boolean",
"inferred": false,
"ruleMap": {}
},
"defaultValue": {
"concept": "DefaultValue",
"expression": {
"concept": "BooleanLiteral",
"value": "false"
},
"playground": []
}
}
],
"variables": [],
"body": [
{
"concept": "Start",
"label": "开始"
},
{
"concept": "IfStatement",
"test": {
"concept": "BinaryExpression",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "resourceValue"
},
"right": {
"concept": "StringLiteral",
"value": "/index"
},
"operator": "=="
},
"consequent": [
{
"concept": "Assignment",
"left": {
"concept": "Identifier",
"namespace": "",
"name": "result"
},
"right": {
"concept": "BooleanLiteral",
"value": "true"
}
}
],
"alternate": [],
"label": "条件分支"
},
{
"concept": "End",
"label": "结束"
}
],
"playground": []
}

对应的代码如下:

@override(lcap_permission)
logic checkPermission(userId: String, resourceValue: String, resourceType: String, clientType: String) => result: Boolean {
if (resourceValue == '/index') {
result = true
} else {
}
end
}