mirror of
https://github.com/dataease/dataease.git
synced 2026-05-21 12:19:38 +08:00
fix: 修复调用飞书认证信息
This commit is contained in:
@@ -2,9 +2,11 @@ package io.dataease.datasource.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import io.dataease.api.lark.vo.LarkInfoVO;
|
||||
import io.dataease.commons.constants.OptConstants;
|
||||
import io.dataease.commons.constants.TaskStatus;
|
||||
import io.dataease.constant.DataSourceType;
|
||||
import io.dataease.constant.MessageEnum;
|
||||
import io.dataease.datasource.dao.auto.entity.CoreDatasource;
|
||||
import io.dataease.datasource.dao.auto.mapper.CoreDatasourceMapper;
|
||||
import io.dataease.datasource.dao.ext.mapper.CoreDatasourceExtMapper;
|
||||
@@ -34,7 +36,6 @@ import java.util.Stack;
|
||||
@Component
|
||||
public class DataSourceManage {
|
||||
|
||||
|
||||
@Resource
|
||||
private DataSourceExtMapper dataSourceExtMapper;
|
||||
|
||||
@@ -125,6 +126,11 @@ public class DataSourceManage {
|
||||
}
|
||||
}
|
||||
|
||||
@XpackInteract(value = "larkManageInteract", before = true)
|
||||
public String getTenantAccessToken() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@XpackInteract(value = "datasourceResourceTree", before = false)
|
||||
public void innerEdit(CoreDatasource coreDatasource) {
|
||||
|
||||
@@ -105,8 +105,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
@Resource
|
||||
private DatasetDataManage datasetDataManage;
|
||||
@Resource
|
||||
private LarkManage larkManage;
|
||||
@Resource
|
||||
private ScheduleManager scheduleManager;
|
||||
@Resource
|
||||
private CoreUserManage coreUserManage;
|
||||
@@ -114,14 +112,11 @@ public class DatasourceServer implements DatasourceApi {
|
||||
private PluginManageApi pluginManage;
|
||||
@Autowired(required = false)
|
||||
private RelationApi relationManage;
|
||||
@Resource(name = "externalTokenManage")
|
||||
private ExternalTokenManage externalTokenManage;
|
||||
|
||||
public enum UpdateType {
|
||||
all_scope, add_scope
|
||||
}
|
||||
|
||||
private static final String tenantAccessTokenUrl = "https://open.larksuite.com/open-apis/auth/v3/tenant_access_token/internal";
|
||||
private TypeReference<List<ApiDefinition>> listTypeReference = new TypeReference<List<ApiDefinition>>() {
|
||||
};
|
||||
@Resource
|
||||
@@ -914,29 +909,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
return apiDefinition;
|
||||
}
|
||||
|
||||
private void generateToken(LarkInfoVO info) {
|
||||
if (ObjectUtils.isEmpty(info)) {
|
||||
info = larkManage.query();
|
||||
}
|
||||
HttpClientConfig clientConfig = new HttpClientConfig();
|
||||
clientConfig.addHeader("Content-Type", "application/json");
|
||||
String tokenPost = HttpClientUtil.post(tenantAccessTokenUrl, buildAccessTokenParam(info.getAppId(), info.getAppSecret()), clientConfig);
|
||||
Map<String, Object> parse = null;
|
||||
try {
|
||||
parse = buildAccessTokenResult(tokenPost);
|
||||
} catch (Exception e) {
|
||||
DEException.throwException("请检查appId和appSecret参数," + e.getMessage());
|
||||
}
|
||||
String tenantAccessToken = parse.get("tenant_access_token").toString();
|
||||
Integer expires_in = (Integer) parse.get("expire");
|
||||
ExternalTokenEntity externalTokenEntity = new ExternalTokenEntity();
|
||||
long expTimePoint = System.currentTimeMillis() + expires_in * 1000L;
|
||||
externalTokenEntity.setId(MessageEnum.LARK.getFlag());
|
||||
externalTokenEntity.setToken(tenantAccessToken);
|
||||
externalTokenEntity.setExpTime(expTimePoint);
|
||||
externalTokenManage.refreshToken(externalTokenEntity);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildAccessTokenResult(String json) {
|
||||
if (ObjectUtils.isEmpty(json)) {
|
||||
DEException.throwException("get access token error");
|
||||
@@ -987,10 +959,6 @@ public class DatasourceServer implements DatasourceApi {
|
||||
}
|
||||
}
|
||||
|
||||
public String getTenantAccessToken() {
|
||||
LarkInfoVO larkInfo = larkManage.query();
|
||||
return externalTokenManage.getToken(MessageEnum.LARK.getFlag(), t -> generateToken(larkInfo));
|
||||
}
|
||||
|
||||
public void updateDemoDs() {
|
||||
}
|
||||
@@ -1334,7 +1302,7 @@ public class DatasourceServer implements DatasourceApi {
|
||||
if (object instanceof DatasourceRequest) {
|
||||
Class<?> clazz = Class.forName(DatasourceRequest.class.getName());
|
||||
Method setToken = clazz.getMethod("setToken", String.class);
|
||||
setToken.invoke(object, getTenantAccessToken());
|
||||
setToken.invoke(object, dataSourceManage.getTenantAccessToken());
|
||||
}
|
||||
resObj = method.invoke(null, object);
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user