@ -17,11 +17,8 @@
package org.apache.dolphinscheduler.api.service.impl ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.USER_MANAGER ;
import org.apache.dolphinscheduler.api.dto.resources.ResourceComponent ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.exceptions.ServiceException ;
@ -59,28 +56,34 @@ import org.apache.dolphinscheduler.dao.mapper.TenantMapper;
import org.apache.dolphinscheduler.dao.mapper.UDFUserMapper ;
import org.apache.dolphinscheduler.dao.mapper.UserMapper ;
import org.apache.dolphinscheduler.dao.utils.ResourceProcessDefinitionUtils ;
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import java.io.IOException ;
import java.text.MessageFormat ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Set ;
import java.util.TimeZone ;
import java.util.Arrays ;
import java.util.Objects ;
import java.util.stream.Collectors ;
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.USER_MANAGER ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
/ * *
* users service impl
@ -129,8 +132,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Autowired
private K8sNamespaceUserMapper k8sNamespaceUserMapper ;
@Autowired
private ResourcePermissionCheckService resourcePermissionCheckService ;
/ * *
* create user , only system admin have permission
@ -159,7 +160,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
//check all user params
String msg = this . checkUserParams ( userName , userPassword , email , phone ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED , msg ) ;
return result ;
}
@ -185,7 +186,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
// resource upload startup
if ( PropertyUtils . getResUploadStartupState ( ) ) {
storageOperate . createTenantDirIfNotExists ( tenant . getTenantCode ( ) ) ;
//
}
result . put ( Constants . DATA_LIST , user ) ;
@ -337,7 +337,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Override
public Result < Object > queryUserList ( User loginUser , String searchVal , Integer pageNo , Integer pageSize ) {
Result < Object > result = new Result < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -387,7 +387,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -453,62 +453,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
user . setState ( state ) ;
Date now = new Date ( ) ;
user . setUpdateTime ( now ) ;
//if user switches the tenant, the user's resources need to be copied to the new tenant
// if (user.getTenantId() != tenantId) {
// Tenant oldTenant = tenantMapper.queryById(user.getTenantId());
// //query tenant
// Tenant newTenant = tenantMapper.queryById(tenantId);
// // if hdfs startup
// if (null != newTenant && PropertyUtils.getResUploadStartupState() && oldTenant != null) {
// String newTenantCode = newTenant.getTenantCode();
// String oldResourcePath = storageOperate.getResDir(oldTenant.getTenantCode());
// String oldUdfsPath = storageOperate.getUdfDir(oldTenant.getTenantCode());
//
// try {// if old tenant dir exists
// if (storageOperate.exists(oldTenant.getTenantCode(), oldResourcePath)) {
// String newResourcePath = storageOperate.getResDir(newTenantCode);
// String newUdfsPath = storageOperate.getUdfDir(newTenantCode);
//
// //file resources list
// List<Resource> fileResourcesList = resourceMapper.queryResourceList(
// null, userId, ResourceType.FILE.ordinal());
// if (CollectionUtils.isNotEmpty(fileResourcesList)) {
// ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(fileResourcesList);
// ResourceComponent resourceComponent = resourceTreeVisitor.visit();
// copyResourceFiles(oldTenant.getTenantCode(), newTenantCode, resourceComponent, oldResourcePath, newResourcePath);
// }
//
// //udf resources
// List<Resource> udfResourceList = resourceMapper.queryResourceList(
// null, userId, ResourceType.UDF.ordinal());
// if (CollectionUtils.isNotEmpty(udfResourceList)) {
// ResourceTreeVisitor resourceTreeVisitor = new ResourceTreeVisitor(udfResourceList);
// ResourceComponent resourceComponent = resourceTreeVisitor.visit();
// copyResourceFiles(oldTenant.getTenantCode(), newTenantCode, resourceComponent, oldUdfsPath, newUdfsPath);
// }
//
// } else {
// // if old tenant dir not exists , create
// storageOperate.createTenantDirIfNotExists(oldTenant.getTenantCode());
//
// if (!storageOperate.exists(newTenant.getTenantCode(), storageOperate.getDir(null,newTenant.getTenantCode()))) {
// storageOperate.createTenantDirIfNotExists(newTenant.getTenantCode());
// }
// }
// } catch (Exception e) {
// logger.error("create tenant {} failed ,the reason is {}", oldTenant, e.getMessage());
// }
//
//
// try {
// storageOperate.createTenantDirIfNotExists(newTenant.getTenantCode());
// } catch (Exception e) {
// logger.error("create tenant {} failed ,the reason is {}", newTenant, e.getMessage());
// }
// }
// user.setTenantId(tenantId);
// }
user . setTenantId ( tenantId ) ;
// updateProcessInstance user
userMapper . updateById ( user ) ;
@ -528,7 +472,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Transactional
public Map < String , Object > deleteUserById ( User loginUser , int id ) throws IOException {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -553,7 +497,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
// delete user
userMapper . queryTenantCodeByUserId ( id ) ;
accessTokenMapper . deleteAccessTokenByUserId ( id ) ;
userMapper . deleteById ( id ) ;
@ -577,7 +520,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -621,7 +564,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -676,7 +619,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -718,7 +661,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > grantResources ( User loginUser , int userId , String resourceIds ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -816,7 +759,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > grantUDFFunction ( User loginUser , int userId , String udfIds ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -864,7 +807,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > grantNamespaces ( User loginUser , int userId , String namespaceIds ) {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -915,7 +858,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -961,7 +904,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1004,7 +947,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Override
public Map < String , Object > queryAllGeneralUsers ( User loginUser ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1078,7 +1021,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > unauthorizedUser ( User loginUser , Integer alertgroupId ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1118,7 +1061,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
@Override
public Map < String , Object > authorizedUser ( User loginUser , Integer alertGroupId ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1141,7 +1084,6 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
return tenantMapper . queryById ( tenantId ) ! = null ;
}
/ * *
* @return if check failed return the field , otherwise return null
* /
@ -1225,7 +1167,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
//check user params
String msg = this . checkUserParams ( userName , userPassword , email , "" ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1255,7 +1197,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > activateUser ( User loginUser , String userName ) {
Map < String , Object > result = new HashMap < > ( ) ;
result . put ( Constants . STATUS , false ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}
@ -1303,7 +1245,7 @@ public class UsersServiceImpl extends BaseServiceImpl implements UsersService {
public Map < String , Object > batchActivateUser ( User loginUser , List < String > userNames ) {
Map < String , Object > result = new HashMap < > ( ) ;
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
if ( resourcePermissionCheckService . functionDisabled ( ) ) {
putMsg ( result , Status . FUNCTION_DISABLED ) ;
return result ;
}