From 694288b23d191bed1a7cbce113dd263b97df5dfe Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Tue, 28 Sep 2021 15:43:34 +0800 Subject: [PATCH] REPORT-59919 && REPORT-59921 && REPORT-59922 --- .../authority/FormulaAuthorityChecker.java | 66 +++++++++++++++++-- .../authority/JTemplateAuthorityChecker.java | 24 ++++--- 2 files changed, 74 insertions(+), 16 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java b/designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java index d108c18d4..5121f03c4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/authority/FormulaAuthorityChecker.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.authority; import com.fr.base.Formula; +import com.fr.stable.StringUtils; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -10,18 +11,71 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public class FormulaAuthorityChecker extends ElementAuthorityChecker { - private static final Pattern FORMULA_PATTERN = Pattern.compile("^=SQL\\(\"(.+?)\","); + private static final Set CONNECTION_NAME_FORMULA_PATTERN = new HashSet<>(); + private static final Set DATASET_NAME_FORMULA_PATTERN = new HashSet<>(); + + static { + CONNECTION_NAME_FORMULA_PATTERN.add(new FormulaPattern("^=SQL\\(\"(.+?)\",", 1)); + DATASET_NAME_FORMULA_PATTERN.add(new FormulaPattern("^=VALUE\\(\"(.+?)\",", 1)); + } @Override @Nullable public Set getNoAuthConnectionNames(Formula formula, Set 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_PATTERN, authConnectionNames); + } + + @Override + @Nullable + Set getNoAuthDatasetNames(Formula formula, Set authDatasetNames) { + return getNoAuthNames(formula, DATASET_NAME_FORMULA_PATTERN, authDatasetNames); + } + + private Set getNoAuthNames(Formula formula, Set formulaPatterns, Set authNames) { + Set noAuthNames = new HashSet<>(); + for (FormulaPattern formulaPattern : formulaPatterns) { + String noAuthName = getNoAuthName(formula, formulaPattern, authNames); + if (noAuthName != null) { + noAuthNames.add(noAuthName); } } + return noAuthNames; + } + + private String getNoAuthName(Formula formula, FormulaPattern formulaPattern, Set authNames) { + String parameter = getFormulaParameter(formula, formulaPattern); + if (!authNames.contains(parameter)) { + return parameter; + } return null; } + + private String getFormulaParameter(Formula formula, FormulaPattern formulaPattern) { + String content = transformFormulaContent(formula.getContent()); + Matcher matcher = formulaPattern.pattern.matcher(content); + if (matcher.find()) { + return matcher.group(formulaPattern.index); + } + return null; + } + + private String transformFormulaContent(String content) { + int index = content.indexOf('('); + if (index > 0) { + return content.substring(0, index).toUpperCase() + content.substring(index); + } else { + return StringUtils.EMPTY; + } + } + + static class FormulaPattern { + public Pattern pattern; + public int index; + + FormulaPattern(String regex, int index) { + this.pattern = Pattern.compile(regex); + this.index = index; + } + } + } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/authority/JTemplateAuthorityChecker.java b/designer-base/src/main/java/com/fr/design/mainframe/authority/JTemplateAuthorityChecker.java index f8b2c8ce6..d76031f65 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/authority/JTemplateAuthorityChecker.java +++ b/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 allConnectionNames; Set authConnectionNames; + Set allDatasetNames; Set authDatasetNames; Map checkerMap = new HashMap<>(); Set 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> authNamesMap = templateAuthority.getAuthServerDataSetAndConnectionNames(); if (authNamesMap != null) { //有权限的数据连接名称 authConnectionNames = authNamesMap.get(UserAuthority.AUTH_CONNECTION_NAMES); - //有权限的数据集名称(模板数据集和服务器数据集) + //有权限的数据集名称 authDatasetNames = authNamesMap.get(UserAuthority.AUTH_SERVER_DATASET_NAMES); - Iterator 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; }