Merge branch 'dev' into pr@dev_memory_component

This commit is contained in:
dataeaseShu 2023-02-06 17:11:48 +08:00
commit c66e2bde39
12 changed files with 125 additions and 30 deletions

View File

@ -528,16 +528,21 @@
<repository>
<id>pentaho-public</id>
<name>Pentaho Public</name>
<url>https://nexus.pentaho.org/content/groups/omni</url>
<url>https://repo.orl.eng.hitachivantara.com/artifactory/pnt-mvn/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<updatePolicy>daily</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<updatePolicy>interval:15</updatePolicy>
</snapshots>
</repository>
<repository>
<id>clojars</id>
<url>https://repo.clojars.org/</url>
</repository>
</repositories>
</project>

View File

@ -11,6 +11,7 @@ import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.BeanUtils;
import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.TokenCacheUtils;
import io.dataease.listener.util.CacheUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
@ -83,6 +84,9 @@ public class F2CRealm extends AuthorizingRealm {
token = (String) auth.getCredentials();
// 解密获得username用于和数据库进行对比
tokenInfo = JWTUtils.tokenInfoByToken(token);
if (!TokenCacheUtils.validate(token)) {
throw new AuthenticationException("token invalid");
}
} catch (Exception e) {
throw new AuthenticationException(e);
}

View File

@ -10,6 +10,7 @@ import io.dataease.auth.service.AuthUserService;
import io.dataease.auth.util.JWTUtils;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.LogUtil;
import io.dataease.commons.utils.TokenCacheUtils;
import io.dataease.exception.DataEaseException;
import io.dataease.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
@ -65,6 +66,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
if (StringUtils.startsWith(authorization, "Basic")) {
return false;
}
if (!TokenCacheUtils.validate(authorization)) {
throw new AuthenticationException(expireMessage);
}
// 当没有出现登录超时 且需要刷新token 则执行刷新token
if (JWTUtils.loginExpire(authorization)) {
throw new AuthenticationException(expireMessage);

View File

@ -234,6 +234,7 @@ public class AuthServer implements AuthApi {
if (StringUtils.isBlank(result)) {
result = "success";
}
TokenCacheUtils.remove(token);
} catch (Exception e) {
LogUtil.error(e);
if (StringUtils.isBlank(result)) {
@ -287,6 +288,7 @@ public class AuthServer implements AuthApi {
if (StringUtils.isBlank(result)) {
result = "success";
}
TokenCacheUtils.remove(token);
} catch (Exception e) {
LogUtil.error(e);
if (StringUtils.isBlank(result)) {

View File

@ -10,6 +10,7 @@ import com.auth0.jwt.interfaces.Verification;
import io.dataease.auth.entity.TokenInfo;
import io.dataease.auth.entity.TokenInfo.TokenInfoBuilder;
import io.dataease.commons.utils.CommonBeanFactory;
import io.dataease.commons.utils.TokenCacheUtils;
import io.dataease.exception.DataEaseException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -117,7 +118,9 @@ public class JWTUtils {
Builder builder = JWT.create()
.withClaim("username", tokenInfo.getUsername())
.withClaim("userId", tokenInfo.getUserId());
return builder.withExpiresAt(date).sign(algorithm);
String sign = builder.withExpiresAt(date).sign(algorithm);
TokenCacheUtils.add(sign, tokenInfo.getUserId());
return sign;
} catch (Exception e) {
return null;

View File

@ -0,0 +1,28 @@
package io.dataease.commons.utils;
import io.dataease.listener.util.CacheUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
public class TokenCacheUtils {
private static final String KEY = "sys_token_store";
public static void add(String token, Long userId) {
CacheUtils.put(KEY, token, userId, null, null);
}
public static void remove(String token) {
CacheUtils.remove(KEY, token);
}
public static boolean validate(String token) {
Object sys_token_store = CacheUtils.get(KEY, token);
return ObjectUtils.isNotEmpty(sys_token_store) && StringUtils.isNotBlank(sys_token_store.toString());
}
public static boolean validate(String token, Long userId) {
Object sys_token_store = CacheUtils.get(KEY, token);
return ObjectUtils.isNotEmpty(sys_token_store) && StringUtils.isNotBlank(sys_token_store.toString()) && userId == Long.parseLong(sys_token_store.toString());
}
}

View File

@ -26,5 +26,7 @@ public class ApiDefinition {
private boolean useJsonPath;
private String jsonPath;
private boolean showApiStructure;
private boolean reName = false;
private String orgName;
}

View File

@ -266,13 +266,11 @@ public class ApiProvider extends Provider {
for (String s : jsonObject.keySet()) {
String value = jsonObject.getString(s);
if (StringUtils.isNotEmpty(value) && value.startsWith("[")) {
JSONObject o = new JSONObject();
try {
JSONArray jsonArray = jsonObject.getJSONArray(s);
List<JSONObject> childrenField = new ArrayList<>();
for (Object object : jsonArray) {
JSONObject.parseObject(object.toString());
handleStr(apiDefinition, JSON.toJSONString(object, SerializerFeature.WriteMapNullValue), childrenField, rootPath + "." + s + "[*]");
}
o.put("children", childrenField);
@ -289,15 +287,28 @@ public class ApiProvider extends Provider {
fields.add(o);
}
} else if (StringUtils.isNotEmpty(value) && value.startsWith("{")) {
List<JSONObject> children = new ArrayList<>();
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
JSONObject o = new JSONObject();
o.put("children", children);
o.put("childrenDataType", "OBJECT");
o.put("jsonPath", rootPath + "." + s);
setProperty(apiDefinition, o, s);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
try {
JSONObject.parseObject(jsonStr);
List<JSONObject> children = new ArrayList<>();
handleStr(apiDefinition, jsonObject.getString(s), children, rootPath + "." + String.format(path, s));
JSONObject o = new JSONObject();
o.put("children", children);
o.put("childrenDataType", "OBJECT");
o.put("jsonPath", rootPath + "." + s);
setProperty(apiDefinition, o, s);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
}
}catch (Exception e){
JSONObject o = new JSONObject();
o.put("jsonPath", rootPath + "." + String.format(path, s));
setProperty(apiDefinition, o, s);
JSONArray array = new JSONArray();
array.add(StringUtils.isNotEmpty(jsonObject.getString(s)) ? jsonObject.getString(s) : "");
o.put("value", array);
if (!hasItem(apiDefinition, fields, o)) {
fields.add(o);
}
}
} else {
JSONObject o = new JSONObject();
@ -325,13 +336,13 @@ public class ApiProvider extends Provider {
o.put("deType", 0);
o.put("extField", 0);
o.put("checked", false);
for (DatasetTableFieldDTO fieldDTO : apiDefinition.getFields()) {
if (StringUtils.isNotEmpty(o.getString("jsonPath")) && StringUtils.isNotEmpty(fieldDTO.getJsonPath()) && fieldDTO.getJsonPath().equals(o.getString("jsonPath"))) {
o.put("checked", true);
o.put("deExtractType", fieldDTO.getDeExtractType());
o.put("name", fieldDTO.getName());
}
}
// for (DatasetTableFieldDTO fieldDTO : apiDefinition.getFields()) {
// if (StringUtils.isNotEmpty(o.getString("jsonPath")) && StringUtils.isNotEmpty(fieldDTO.getJsonPath()) && fieldDTO.getJsonPath().equals(o.getString("jsonPath"))) {
// o.put("checked", true);
// o.put("deExtractType", fieldDTO.getDeExtractType());
// o.put("name", fieldDTO.getName());
// }
// }
}

View File

@ -284,7 +284,6 @@ public class DatasourceService {
datasource.setUpdateTime(System.currentTimeMillis());
Provider datasourceProvider = ProviderFactory.getProvider(updataDsRequest.getType());
datasourceProvider.checkConfiguration(datasource);
checkAndUpdateDatasourceStatus(datasource);
updateDatasource(updataDsRequest.getId(), datasource);
}
@ -295,6 +294,28 @@ public class DatasourceService {
checkAndUpdateDatasourceStatus(datasource);
datasourceMapper.updateByExampleSelective(datasource, example);
handleConnectionPool(id);
if (datasource.getType().equalsIgnoreCase("api")) {
DatasetTableExample datasetTableExample = new DatasetTableExample();
datasetTableExample.createCriteria().andDataSourceIdEqualTo(id);
List<DatasetTable> datasetTables = datasetTableMapper.selectByExample(datasetTableExample);
List<ApiDefinition> apiDefinitionList = new Gson().fromJson(datasource.getConfiguration(), new TypeToken<List<ApiDefinition>>() {}.getType());
apiDefinitionList.forEach(apiDefinition -> {
if(apiDefinition.isReName()){
datasetTables.forEach(datasetTable -> {
if(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getTable().equals(apiDefinition.getOrgName())){
DatasetTable record = new DatasetTable();
DataTableInfoDTO dataTableInfoDTO = new DataTableInfoDTO();
dataTableInfoDTO.setTable(apiDefinition.getName());
record.setInfo(new Gson().toJson(dataTableInfoDTO));
datasetTableExample.clear();
datasetTableExample.createCriteria().andIdEqualTo(datasetTable.getId());
datasetTableMapper.updateByExampleSelective(record, datasetTableExample);
}
});
}
});
}
}
private void handleConnectionPool(String datasourceId) {
@ -340,6 +361,7 @@ public class DatasourceService {
datasourceDTO.setApiConfiguration(apiDefinitionListWithStatus);
if (success == apiDefinitionList.size()) {
datasource.setStatus(datasourceStatus);
return ResultHolder.success(datasourceDTO);
}
if (success > 0 && success < apiDefinitionList.size()) {

View File

@ -3,6 +3,10 @@ SET `version` = '1.18.2'
where `plugin_id` > 0
and `version` = '1.18.1';
UPDATE sys_menu
SET i_frame = 1
WHERE menu_id = 800;
UPDATE `panel_subject`
SET `details` = '{\"width\":1600,\"height\":900,\"scale\":100,\"scaleWidth\":100,\"scaleHeight\":100,\"selfAdaption\":true,\"auxiliaryMatrix\":true,\"openCommonStyle\":true,\"panel\":{\"themeColor\":\"light\",\"color\":\"#F1F3F5\",\"imageUrl\":{},\"backgroundType\":\"color\",\"gap\":\"yes\",\"resultMode\":\"all\",\"resultCount\":1000},\"aidedDesign\":{\"showGrid\":false,\"matrixBase\":4},\"refreshViewLoading\":true,\"refreshUnit\":\"minute\",\"refreshTime\":5,\"themeId\":\"e846db60-9619-11ed-b973-39e0420a3eeb\",\"chartInfo\":{\"chartTitle\":{\"show\":true,\"fontSize\":\"18\",\"color\":\"#000000\",\"hPosition\":\"left\",\"vPosition\":\"top\",\"isItalic\":false,\"isBolder\":true,\"remarkShow\":false,\"remark\":\"\",\"remarkBackgroundColor\":\"#ffffffff\",\"fontFamily\":\"Microsoft YaHei\",\"letterSpace\":\"0\",\"fontShadow\":false},\"chartColor\":{\"value\":\"default\",\"colors\":[\"#5470c6\",\"#91cc75\",\"#fac858\",\"#ee6666\",\"#73c0de\",\"#3ba272\",\"#fc8452\",\"#9a60b4\",\"#ea7ccc\"],\"alpha\":100,\"tableHeaderBgColor\":\"#6D9A49\",\"tableItemBgColor\":\"#FFFFFF\",\"tableHeaderFontColor\":\"#000000\",\"tableFontColor\":\"#000000\",\"tableStripe\":true,\"dimensionColor\":\"#000000\",\"quotaColor\":\"#5470c6\",\"tableBorderColor\":\"#E6E7E4\",\"seriesColors\":[],\"areaBorderColor\":\"#303133\",\"gradient\":false,\"areaBaseColor\":\"#FFFFFF\",\"tableScrollBarColor\":\"rgba(0, 0, 0, 0.15)\",\"tableScrollBarHoverColor\":\"rgba(0, 0, 0, 0.4)\"},\"chartCommonStyle\":{\"backgroundColorSelect\":true,\"color\":\"#FFFFFF\",\"alpha\":100,\"borderRadius\":5,\"innerPadding\":0,\"enable\":false,\"innerImageColor\":\"#1E90FF\",\"backgroundType\":\"outerImage\",\"outerImage\":null},\"filterStyle\":{\"horizontal\":\"left\",\"vertical\":\"top\",\"color\":\"#000000\",\"brColor\":\"\",\"wordColor\":\"\",\"innerBgColor\":\"\"},\"tabStyle\":{\"headFontColor\":\"#OOOOOO\",\"headFontActiveColor\":\"#OOOOOO\",\"headBorderColor\":\"#OOOOOO\",\"headBorderActiveColor\":\"#OOOOOO\",\"headPosition\":\"left\"}}}'
WHERE `id` = 'system_1';

View File

@ -270,5 +270,14 @@
memoryStoreEvictionPolicy="LRU"
/>
<cache
name="sys_token_store"
eternal="true"
maxElementsInMemory="100"
maxElementsOnDisk="3000"
overflowToDisk="true"
diskPersistent="false"
/>
</ehcache>

View File

@ -1222,14 +1222,15 @@ export default {
this.edit_api_item = false
if (!this.add_api_item) {
for (let i = 0; i < this.form.apiConfiguration.length; i++) {
if (
this.form.apiConfiguration[i].serialNumber ===
this.apiItem.serialNumber
) {
this.form.apiConfiguration[i] = JSON.parse(
JSON.stringify(this.apiItem)
)
if (this.form.apiConfiguration[i].serialNumber === this.apiItem.serialNumber) {
this.certinKey = !this.certinKey
if(this.form.apiConfiguration[i].name !== this.apiItem.name){
this.apiItem.reName = true
this.apiItem.orgName = this.form.apiConfiguration[i].name
}else {
this.apiItem.reName = false
}
this.form.apiConfiguration[i] = JSON.parse(JSON.stringify(this.apiItem))
}
}
} else {