Browse Source

Pull request #6063: REPORT-59919 && REPORT-59921 && REPORT-59922

Merge in DESIGN/design from ~HENRY.WANG/design:release/11.0 to release/11.0

* commit '162108f4f0c79f705d6e7fec8cd3ffacbd42b667':
  REPORT-59919 && REPORT-59921 && REPORT-59922
  REPORT-59919 && REPORT-59921 && REPORT-59922
bugfix/11.0
Henry.Wang 3 years ago
parent
commit
7dbe84f30d
  1. 90
      designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java
  2. 24
      designer-base/src/main/java/com/fr/design/mainframe/authority/JTemplateAuthorityChecker.java

90
designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java

@ -1,27 +1,97 @@
package com.fr.design.mainframe.authority;
import com.fr.base.Formula;
import com.fr.general.ComparatorUtils;
import com.fr.parser.FunctionCall;
import com.fr.parser.StringLiteral;
import com.fr.script.Calculator;
import com.fr.stable.script.Node;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FormulaAuthorityChecker extends ElementAuthorityChecker<Formula> {
private static final Pattern FORMULA_PATTERN = Pattern.compile("^=SQL\\(\"(.+?)\",");
private static final Set<FormulaParser> CONNECTION_NAME_FORMULA_PARSER = new HashSet<>();
private static final Set<FormulaParser> DATASET_NAME_FORMULA_PARSER = new HashSet<>();
static {
CONNECTION_NAME_FORMULA_PARSER.add(new FormulaParser("SQL", 0));
DATASET_NAME_FORMULA_PARSER.add(new FormulaParser("VALUE", 0));
}
@Override
@Nullable
public Set<String> getNoAuthConnectionNames(Formula formula, Set<String> authConnectionNames) {
String content = formula.getContent();
Matcher matcher = FORMULA_PATTERN.matcher(content);
if (matcher.find()) {
if (!authConnectionNames.contains(matcher.group(1))) {
return new HashSet<>(Arrays.asList(matcher.group(1)));
return getNoAuthNames(formula, CONNECTION_NAME_FORMULA_PARSER, authConnectionNames);
}
@Override
@Nullable
Set<String> getNoAuthDatasetNames(Formula formula, Set<String> authDatasetNames) {
return getNoAuthNames(formula, DATASET_NAME_FORMULA_PARSER, authDatasetNames);
}
private Set<String> getNoAuthNames(Formula formula, Set<FormulaParser> formulaParsers, Set<String> authNames) {
Set<String> noAuthNames = new HashSet<>();
try {
FunctionCall functionCall = (FunctionCall) Calculator.createCalculator().parse(formula.getContent()).getConditionalExpression();
handleNoAuthNames(functionCall, formulaParsers, authNames, noAuthNames);
} catch (Exception ignore) {
} finally {
return noAuthNames;
}
}
private void handleNoAuthNames(FunctionCall functionCall, Set<FormulaParser> formulaParsers, Set<String> authNames, Set<String> noAuthNames) {
for (FormulaParser formulaPattern : formulaParsers) {
String noAuthName = formulaPattern.getNoAuthName(functionCall, authNames);
if (noAuthName != null) {
noAuthNames.add(noAuthName);
}
}
return null;
Node[] nodes = functionCall.getArguments();
if (nodes != null) {
for (int i = 0; i < nodes.length; i++) {
Node node = nodes[i];
if (node instanceof FunctionCall) {
handleNoAuthNames((FunctionCall) node, formulaParsers, authNames, noAuthNames);
}
}
}
}
static class FormulaParser {
//函数的名称
public String name;
//要检测的位置
public int index;
FormulaParser(String name, int index) {
this.name = name;
this.index = index;
}
String getNoAuthName(FunctionCall functionCall, Set<String> authNames) {
if (functionCall.getName() != null && ComparatorUtils.equals(functionCall.getName().toUpperCase(), name)) {
Node node = functionCall.getArguments()[index];
if (node instanceof StringLiteral) {
String stringLiteral = node.toString();
if (stringLiteral.length() > 2) {
String value = stringLiteral.substring(1, stringLiteral.length() - 1);
if (!authNames.contains(value)) {
return value;
}
}
}
}
return null;
}
}
}

24
designer-base/src/main/java/com/fr/design/mainframe/authority/JTemplateAuthorityChecker.java

@ -7,11 +7,11 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mod.ModClassFilter;
import com.fr.file.ConnectionConfig;
import com.fr.file.TableDataConfig;
import com.fr.invoke.ClassHelper;
import com.fr.log.FineLoggerFactory;
import com.fr.rpc.ExceptionHandler;
import com.fr.rpc.RPCInvokerExceptionInfo;
import com.fr.stable.Filter;
import com.fr.workspace.WorkContext;
import com.fr.workspace.server.authority.user.UserAuthority;
@ -19,7 +19,6 @@ import com.fr.workspace.server.authority.user.UserAuthority;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@ -29,7 +28,9 @@ import static javax.swing.JOptionPane.WARNING_MESSAGE;
public class JTemplateAuthorityChecker {
JTemplate<?, ?> jTemplate;
Set<String> allConnectionNames;
Set<String> authConnectionNames;
Set<String> allDatasetNames;
Set<String> authDatasetNames;
Map<String, ElementAuthorityChecker> checkerMap = new HashMap<>();
Set<String> authFailConnectionNames = new HashSet<>();
@ -45,18 +46,20 @@ public class JTemplateAuthorityChecker {
}
private void initAuthNames() {
allDatasetNames = new HashSet<>();
for (String authServerDataSetName : TableDataConfig.getInstance().getTableDatas().keySet()) {
allDatasetNames.add(authServerDataSetName);
}
allConnectionNames = ConnectionConfig.getInstance().getConnections().keySet();
UserAuthority templateAuthority = WorkContext.getCurrent().get(UserAuthority.class);
Map<String, Set<String>> authNamesMap = templateAuthority.getAuthServerDataSetAndConnectionNames();
if (authNamesMap != null) {
//有权限的数据连接名称
authConnectionNames = authNamesMap.get(UserAuthority.AUTH_CONNECTION_NAMES);
//有权限的数据集名称(模板数据集和服务器数据集)
//有权限的数据集名称
authDatasetNames = authNamesMap.get(UserAuthority.AUTH_SERVER_DATASET_NAMES);
Iterator<String> iterator = jTemplate.getTarget().getTableDataNameIterator();
while (iterator.hasNext()) {
String datasetName = iterator.next();
authDatasetNames.add(datasetName);
}
}
}
@ -95,7 +98,8 @@ public class JTemplateAuthorityChecker {
}
}
}
authFailConnectionNames.retainAll(allConnectionNames);
authFailDatasetNames.retainAll(allDatasetNames);
FineLoggerFactory.getLogger().info("JTemplateAuthorityChecker check time consume:" + (System.currentTimeMillis() - s));
return authFailConnectionNames.size() == 0 && authFailDatasetNames.size() == 0;
}

Loading…
Cancel
Save