Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.dolphinscheduler.api.audit.enums.AuditType;
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.DataSourceService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
Expand Down Expand Up @@ -202,7 +203,6 @@ public Result<Object> queryDataSourceListPaging(@Parameter(hidden = true) @Reque
/**
* connect datasource
*
* @param loginUser login user
* @param jsonStr datasource param
* example: {"type":"MYSQL","name":"txx","note":"","host":"localhost","port":3306,"principal":"","javaSecurityKrb5Conf":"","loginUserKeytabUsername":"","loginUserKeytabPath":"","userName":"root","password":"xxx","database":"ds","connectType":"","other":{"serverTimezone":"GMT-8"},"id":2}
* @return connect result code
Expand All @@ -211,8 +211,7 @@ public Result<Object> queryDataSourceListPaging(@Parameter(hidden = true) @Reque
@PostMapping(value = "/connect")
@ResponseStatus(HttpStatus.OK)
@ApiException(CONNECT_DATASOURCE_FAILURE)
public Result<Boolean> connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
public Result<Boolean> connectDataSource(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

This issue is related to user authentication and will be addressed in a separate PR. Per the senior developer's suggestion, I will split these two types of issues into distinct Issues and PRs.

please review this:
#18073

BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
DataSourceUtils.checkDatasourceParam(dataSourceParam);
ConnectionParam connectionParams = DataSourceUtils.buildConnectionParams(dataSourceParam);
Expand Down Expand Up @@ -264,9 +263,8 @@ public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttrib
/**
* verify datasource name
*
* @param loginUser login user
* @param name data source name
* @return true if data source name not exists, otherwise return false
* @return true if data source name not exists, otherwise throw a {@link ServiceException}
*/
@Operation(summary = "verifyDataSourceName", description = "VERIFY_DATA_SOURCE_NOTES")
@Parameters({
Expand All @@ -275,8 +273,7 @@ public Result<Boolean> deleteDataSource(@Parameter(hidden = true) @RequestAttrib
@GetMapping(value = "/verify-name")
@ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
public Result<Boolean> verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "name") String name) {
public Result<Boolean> verifyDataSourceName(@RequestParam(value = "name") String name) {
dataSourceService.verifyDataSourceName(name);
return Result.success(true);
}
Expand Down Expand Up @@ -323,16 +320,15 @@ public Result<Object> authedDatasource(@Parameter(hidden = true) @RequestAttribu
}

/**
* get user info
* Checks the startup status of Kerberos authentication.
*
* @param loginUser login user
* @return user info data
* @return a boolean indicating whether Kerberos is currently active
*/
@Operation(summary = "getKerberosStartupState", description = "GET_USER_INFO_NOTES")
@Operation(summary = "getKerberosStartupState", description = "GET_KERBEROS_STARTUP_STATE")
@GetMapping(value = "/kerberos-startup-state")
@ResponseStatus(HttpStatus.OK)
@ApiException(KERBEROS_STARTUP_STATE)
public Result<Object> getKerberosStartupState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
public Result<Object> getKerberosStartupState() {
// if upload resource is HDFS and kerberos startup is true , else false
return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.dolphinscheduler.api.service;

import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.User;
Expand All @@ -28,33 +29,36 @@
import java.util.List;

/**
* data source service
* datasource service
*/
public interface DataSourceService {

/**
* create data source
* create a new datasource.
*
* @param loginUser login user
* @param datasourceParam datasource parameter
* @return create result code
* @param datasourceParam datasource configuration DTO
* @return created {@link DataSource} entity (sensitive fields masked)
* @throws ServiceException if permission denied, security check fails, or connection test fails
*/
DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam);

/**
* updateWorkflowInstance datasource
* update datasource
*
* @param loginUser login user
* @param dataSourceParam data source params
* @return update result code
* @param dataSourceParam datasource params
* @return updated {@link DataSource} entity (sensitive fields masked)
* @throws ServiceException if permission denied, security check fails, or connection test fails
*/
DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam);

/**
* updateWorkflowInstance datasource
* query datasource
*
* @param loginUser login user
* @param id datasource id
* @return data source detail
* @return a {@link BaseDataSourceParamDTO} entity (sensitive fields masked)
*/
BaseDataSourceParamDTO queryDataSource(int id, User loginUser);

Expand All @@ -65,35 +69,42 @@ public interface DataSourceService {
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
* @return data source list page
* @return datasource list page
*/
PageInfo<DataSource> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);

/**
* query data resource list
*
* @param loginUser login user
* @param type data source type
* @return data source list page
* @param type datasource type
* @return datasource list
*/
List<DataSource> queryDataSourceList(User loginUser, Integer type);

/**
* verify datasource exists
* verify whether a datasource name already exists.
* <p>
* If the name already exists, a {@link ServiceException} is thrown.
* If the name is available (does not exist), the method completes successfully without returning a value.
*
* @param name datasource name
* @return true if data datasource not exists, otherwise return false
* @param name the datasource name to verify
* @throws ServiceException if the datasource name already exists (Status.DATASOURCE_EXIST)
*/
void verifyDataSourceName(String name);

/**
* check connection
* Checks the connectivity of a datasource based on the provided type and parameters.
* <p>
* This method attempts to establish a connection.
* - If the connection is successful, the method returns normally (void).
* - If the connection fails, a {@link ServiceException} is thrown.
*
* @param type data source type
* @param parameter data source parameters
* @return true if connect successfully, otherwise false
* @param type the type of the datasource (e.g., MYSQL, POSTGRESQL)
* @param connectionParam the connection parameters containing host, port, credentials, etc.
* @throws ServiceException if the connection test fails (Status.CONNECTION_TEST_FAILURE)
*/
void checkConnection(DbType type, ConnectionParam parameter);
void checkConnection(DbType type, ConnectionParam connectionParam);

/**
* test connection
Expand All @@ -104,11 +115,11 @@ public interface DataSourceService {
void connectionTest(int id);

/**
* delete datasource
* delete a datasource by ID.
*
* @param loginUser login user
* @param datasourceId data source id
* @return delete result code
* @param loginUser the current logged-in user
* @param datasourceId the unique identifier of the datasource to delete
* @throws ServiceException if checks fail or deletion encounters an error
*/
void delete(User loginUser, int datasourceId);

Expand All @@ -117,7 +128,7 @@ public interface DataSourceService {
*
* @param loginUser login user
* @param userId user id
* @return unauthed data source result code
* @return a list of {@link DataSource} objects that are available to be authorized to the target user
*/
List<DataSource> unAuthDatasource(User loginUser, Integer userId);

Expand All @@ -126,7 +137,7 @@ public interface DataSourceService {
*
* @param loginUser login user
* @param userId user id
* @return authorized result code
* @return a list of {@link DataSource} objects that are authorized to the target user
*/
List<DataSource> authedDatasource(User loginUser, Integer userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ public class DataSourceServiceImpl extends BaseServiceImpl implements DataSource
private static final String TABLE_NAME = "TABLE_NAME";
private static final String COLUMN_NAME = "COLUMN_NAME";

/**
* create data source
*
* @param loginUser login user
* @param datasourceParam datasource parameters
* @return create result code
*/
@Override
public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO datasourceParam) {
DataSourceUtils.checkDatasourceParam(datasourceParam);
Expand Down Expand Up @@ -129,12 +122,6 @@ public DataSource createDataSource(User loginUser, BaseDataSourceParamDTO dataso
}
}

/**
* updateWorkflowInstance datasource
*
* @param loginUser login user
* @return update result code
*/
@Override
public DataSource updateDataSource(User loginUser, BaseDataSourceParamDTO dataSourceParam) {
DataSourceUtils.checkDatasourceParam(dataSourceParam);
Expand Down Expand Up @@ -188,12 +175,6 @@ private boolean checkName(String name) {
return queryDataSource != null && !queryDataSource.isEmpty();
}

/**
* updateWorkflowInstance datasource
*
* @param id datasource id
* @return data source detail
*/
@Override
public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) {
DataSource dataSource = dataSourceMapper.selectById(id);
Expand All @@ -202,7 +183,7 @@ public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) {
throw new ServiceException(Status.RESOURCE_NOT_EXIST);
}

if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,
if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.DATASOURCE,
ApiFuncIdentificationConstant.DATASOURCE)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}
Expand All @@ -218,15 +199,6 @@ public BaseDataSourceParamDTO queryDataSource(int id, User loginUser) {
return baseDataSourceParamDTO;
}

/**
* query datasource list by keyword
*
* @param loginUser login user
* @param searchVal search value
* @param pageNo page number
* @param pageSize page size
* @return data source list page
*/
@Override
public PageInfo<DataSource> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo,
Integer pageSize) {
Expand Down Expand Up @@ -272,13 +244,6 @@ private String getHiddenPassword() {
return Constants.XXXXXX;
}

/**
* query data resource list
*
* @param loginUser login user
* @param type data source type
* @return data source list page
*/
@Override
public List<DataSource> queryDataSourceList(User loginUser, Integer type) {

Expand All @@ -298,12 +263,6 @@ public List<DataSource> queryDataSourceList(User loginUser, Integer type) {
return datasourceList;
}

/**
* verify datasource exists
*
* @param name datasource name
* @return true if data datasource not exists, otherwise return false
*/
@Override
public void verifyDataSourceName(String name) {
List<DataSource> dataSourceList = dataSourceMapper.queryDataSourceByName(name);
Expand All @@ -312,14 +271,6 @@ public void verifyDataSourceName(String name) {
}
}

/**
* check connection
*
* @param type data source type
* @param connectionParam connectionParam
* @return true if connect successfully, otherwise false
* @return true if connect successfully, otherwise false
*/
@Override
public void checkConnection(DbType type, ConnectionParam connectionParam) {
DataSourceProcessor sshDataSourceProcessor = DataSourceUtils.getDatasourceProcessor(type);
Expand All @@ -346,36 +297,25 @@ public void connectionTest(int id) {
DataSourceUtils.buildConnectionParams(dataSource.getType(), dataSource.getConnectionParams()));
}

/**
* delete datasource
*
* @param loginUser login user
* @param datasourceId data source id
* @return delete result code
*/
@Override
@Transactional
public void delete(User loginUser, int datasourceId) {
// query datasource by id
DataSource dataSource = dataSourceMapper.selectById(datasourceId);

if (dataSource == null) {
throw new ServiceException(Status.RESOURCE_NOT_EXIST);
}
if (!canOperatorPermissions(loginUser, new Object[]{dataSource.getId()}, AuthorizationType.DATASOURCE,

if (!canOperatorPermissions(loginUser, new Object[]{datasourceId}, AuthorizationType.DATASOURCE,
DATASOURCE_DELETE)) {
throw new ServiceException(Status.USER_NO_OPERATION_PERM);
}

dataSourceMapper.deleteById(datasourceId);
datasourceUserMapper.deleteByDatasourceId(datasourceId);
}

/**
* unauthorized datasource
*
* @param loginUser login user
* @param userId user id
* @return unauthed data source result code
*/
@Override
public List<DataSource> unAuthDatasource(User loginUser, Integer userId) {
List<DataSource> datasourceList;
Expand Down Expand Up @@ -403,13 +343,6 @@ public List<DataSource> unAuthDatasource(User loginUser, Integer userId) {
return resultList;
}

/**
* authorized datasource
*
* @param loginUser login user
* @param userId user id
* @return authorized result code
*/
@Override
public List<DataSource> authedDatasource(User loginUser, Integer userId) {
List<DataSource> authedDatasourceList = dataSourceMapper.queryAuthedDatasource(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ DELETE_DATA_SOURCE_NOTES=delete data source
VERIFY_DATA_SOURCE_NOTES=verify data source
UNAUTHORIZED_DATA_SOURCE_NOTES=unauthorized data source
AUTHORIZED_DATA_SOURCE_NOTES=authorized data source
GET_KERBEROS_STARTUP_STATE=get the Kerberos startup state
DELETE_SCHEDULE_NOTES=delete schedule by id
QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging
QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES= query authorized and user created project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ DELETE_DATA_SOURCE_NOTES=delete data source
VERIFY_DATA_SOURCE_NOTES=verify data source
UNAUTHORIZED_DATA_SOURCE_NOTES=unauthorized data source
AUTHORIZED_DATA_SOURCE_NOTES=authorized data source
GET_KERBEROS_STARTUP_STATE=get the Kerberos startup state
DELETE_SCHEDULE_NOTES=delete schedule by id
QUERY_ALERT_GROUP_LIST_PAGING_NOTES=query alert group list paging
QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES=query authorized and user created project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ DELETE_DATA_SOURCE_NOTES=\u5220\u9664\u6570\u636E\u6E90
VERIFY_DATA_SOURCE_NOTES=\u9A8C\u8BC1\u6570\u636E\u6E90
UNAUTHORIZED_DATA_SOURCE_NOTES=\u672A\u6388\u6743\u7684\u6570\u636E\u6E90
AUTHORIZED_DATA_SOURCE_NOTES=\u6388\u6743\u7684\u6570\u636E\u6E90
GET_KERBEROS_STARTUP_STATE=\u83B7\u53D6Kerberos\u542F\u52A8\u72B6\u6001
DELETE_SCHEDULE_NOTES=\u6839\u636E\u5B9A\u65F6id\u5220\u9664\u5B9A\u65F6\u6570\u636E
QUERY_ALERT_GROUP_LIST_PAGING_NOTES=\u5206\u9875\u67E5\u8BE2\u544A\u8B66\u7EC4\u5217\u8868
QUERY_AUTHORIZED_AND_USER_CREATED_PROJECT_NOTES=\u67E5\u8BE2\u6388\u6743\u548C\u7528\u6237\u521B\u5EFA\u7684\u9879\u76EE
Expand Down
Loading