use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.
the class DatasourceService method kerberosConnectPrepare.
/**
* kerberos认证前预处理 :对kerberos参数替换相对路径为绝对路径等操作
* @param sourceId
* @return
*/
public Map<String, Object> kerberosConnectPrepare(Long sourceId) {
DsInfo dataSource = dsInfoService.getOneById(sourceId);
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(dataSource.getDataType(), dataSource.getDataVersion());
if (Objects.isNull(typeEnum)) {
throw new PubSvcDefineException(ErrorCode.CAN_NOT_FITABLE_SOURCE_TYPE);
}
Map<String, Object> kerberosConfig = fillKerberosConfig(dataSource.getId());
HashMap<String, Object> tmpKerberosConfig = new HashMap<>(kerberosConfig);
// kerberos获取表操作预处理
if (MapUtils.isNotEmpty(kerberosConfig)) {
String localKerberosPath = kerberosService.getLocalKerberosPath(sourceId);
IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
try {
kerberos.prepareKerberosForConnect(tmpKerberosConfig, localKerberosPath);
} catch (Exception e) {
LOGGER.error("kerberos连接预处理失败!{}", e.getMessage(), e);
throw new DtCenterDefException(String.format("kerberos连接预处理失败,Caused by: %s", e.getMessage()), e);
}
}
return tmpKerberosConfig;
}
use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.
the class BatchTaskService method handleKerberos.
/**
* kerberos配置预处理、替换相对路径为绝对路径等操作
*
* @param sourceType
* @param kerberosMap
* @param localKerberosConf
* @return
*/
private Map<String, Object> handleKerberos(Integer sourceType, Map<String, Object> kerberosMap, String localKerberosConf) {
IKerberos kerberos = ClientCache.getKerberos(sourceType);
HashMap<String, Object> tmpKerberosConfig = new HashMap<>(kerberosMap);
try {
kerberos.prepareKerberosForConnect(tmpKerberosConfig, localKerberosConf);
} catch (Exception e) {
throw new RdosDefineException("common-loader中kerberos配置文件处理失败", e);
}
return tmpKerberosConfig;
}
use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.
the class DatasourceService method getPrincipalsWithConf.
/**
* 解析kerberos文件获取principal列表
* @param source
* @param resource
* @param userId
* @return
*/
public List<String> getPrincipalsWithConf(DataSourceVO source, Pair<String, String> resource, Long userId) {
String localKerberosPath;
Map<String, Object> kerberosConfig;
// 获取数据源类型,这里要做type version的改造
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
if (Objects.nonNull(resource)) {
localKerberosPath = kerberosService.getTempLocalKerberosConf(userId);
try {
// 解析Zip文件获取配置对象
kerberosConfig = kerberos.parseKerberosFromUpload(resource.getRight(), localKerberosPath);
} catch (IOException e) {
LOGGER.error("解析principals, kerberos config 解析异常,{}", e.getMessage(), e);
throw new PubSvcDefineException(String.format("kerberos config 解析异常,Caused by: %s", e.getMessage()), e);
}
// 连接 Kerberos 前的准备工作
kerberos.prepareKerberosForConnect(kerberosConfig, localKerberosPath);
} else {
kerberosConfig = kerberosConnectPrepare(source.getId());
}
return kerberos.getPrincipals(kerberosConfig);
}
use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.
the class DatasourceService method checkConnectionWithConf.
/**
* 数据源连通性测试
* @param source
* @param confMap
* @param localKerberosPath
* @return
*/
public Boolean checkConnectionWithConf(DataSourceVO source, Map<String, Object> confMap, String localKerberosPath) {
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
if (MapUtils.isEmpty(confMap) && source.getId() > 0L) {
confMap = fillKerberosConfig(source.getId());
localKerberosPath = kerberosService.getLocalKerberosPath(source.getId());
}
if (DataSourceTypeEnum.ADB_PostgreSQL == typeEnum) {
typeEnum = DataSourceTypeEnum.PostgreSQL;
}
// 替换相对绝对路径
Map<String, Object> tempConfMap = null;
if (MapUtils.isNotEmpty(confMap)) {
tempConfMap = Maps.newHashMap(confMap);
IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
kerberos.prepareKerberosForConnect(tempConfMap, localKerberosPath);
}
// 测试连通性
ISourceDTO sourceDTO = SourceDTOType.getSourceDTO(source.getDataJson(), typeEnum.getVal(), tempConfMap, Maps.newHashMap());
return ClientCache.getClient(typeEnum.getVal()).testCon(sourceDTO);
}
use of com.dtstack.dtcenter.loader.client.IKerberos in project Taier by DTStack.
the class DatasourceService method checkConnectionWithKerberos.
/**
* 检测kerberos认证的数据源连通性
* @param source
* @param resource
* @param projectId
* @param userId
* @return
*/
public Boolean checkConnectionWithKerberos(DataSourceVO source, Pair<String, String> resource, Long projectId, Long userId) {
Map<String, Object> kerberosConfig;
String localKerberosPath;
DataSourceTypeEnum typeEnum = DataSourceTypeEnum.typeVersionOf(source.getDataType(), source.getDataVersion());
IKerberos kerberos = ClientCache.getKerberos(typeEnum.getVal());
if (Objects.nonNull(resource)) {
localKerberosPath = kerberosService.getTempLocalKerberosConf(userId);
try {
kerberosConfig = kerberos.parseKerberosFromUpload(resource.getRight(), localKerberosPath);
} catch (IOException e) {
LOGGER.error("检测连通性, kerberos config 解析异常,{}", e.getMessage(), e);
throw new PubSvcDefineException(String.format("kerberos config 解析异常,Caused by: %s", e.getMessage()), e);
}
} else {
localKerberosPath = kerberosService.getLocalKerberosPath(source.getId());
kerberosConfig = fillKerberosConfig(source.getId());
}
try {
source.setDataJson(DataSourceUtils.getDataSourceJson(source.getDataJsonString()));
} catch (Exception e) {
LOGGER.error("检查数据源连接,DataJsonString 转化异常", e);
throw new PubSvcDefineException("JSONObject 转化异常", e);
}
// 设置前台传入的principals
setPrincipals(source.getDataJson(), kerberosConfig);
return checkConnectionWithConf(source, kerberosConfig, localKerberosPath);
}
Aggregations