Compare commits

...

1 Commits

Author SHA1 Message Date
apoltavtsev
502db95a56 fix(APPINT-32494) cleanup Studio artifact sensitive parameters 2021-09-20 09:17:58 +02:00
4 changed files with 108 additions and 1 deletions

View File

@@ -71,6 +71,9 @@ public class ContextUtils {
"instanceof", "return", "transient", "catch", "extends", "int", "short", "try", "char", "final", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$
"static", "void", "class", "finally", "long", "strictfp", "volatile", "const", "float", "native", "super", "while")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$
private static final Set<String> SECURE_SENSITIVE_CONTEXT_NAMES_EXP = new HashSet<String>(Arrays.asList("resource_flow_temp_folder", "resource_webhook_payload", "resource_file_[\\w]+",
"resource_directory_[\\w]+", "connection_[a-zA-Z0-9]+_[\\w]+"));
/**
*
@@ -90,6 +93,22 @@ public class ContextUtils {
return false;
}
/**
*
* ggu Comment method "isSecureSensitiveParam".
*
*/
public static boolean isSecureSensitiveParam (final String name) {
for (String regexp : SECURE_SENSITIVE_CONTEXT_NAMES_EXP) {
if (name.matches(regexp)) {
return true;
}
}
return false;
}
/**
*
* update the JobContextParameter form repository ContextItem by context name.

View File

@@ -240,6 +240,11 @@ public class ContextParameterJavaTypeManager {
if (javaType == null) {
return null;
}
if(javaType.equals(JavaTypesManager.PASSWORD)) {
return "Password";
}
Class primitiveClass = javaType.getPrimitiveClass();
Class nullableClass = javaType.getNullableClass();
if (nullable) {

View File

@@ -66,6 +66,8 @@ public interface TalendProcessArgumentConstant {
static final String ARG_AVOID_BRANCH_NAME = "AVOID_BRANCH_NAME";
static final String ARG_CLEAR_PASSWORD_CONTEXT_PARAMETERS = "CLEAR_PASSWORD_CONTEXT_PARAMETERS";
static final String CMD_ARG_STATS_PORT_PARAM = "stat_port";
static final String CMD_ARG_TRACE_PORT_PARAM = "trace_port";

View File

@@ -50,6 +50,7 @@ import org.talend.commons.exception.CommonExceptionHandler;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.exception.PersistenceException;
import org.talend.commons.runtime.model.repository.ERepositoryStatus;
import org.talend.commons.runtime.utils.io.FileCopyUtils;
import org.talend.commons.utils.PasswordEncryptUtil;
import org.talend.commons.utils.generation.JavaUtils;
import org.talend.commons.utils.time.TimeMeasure;
@@ -67,6 +68,7 @@ import org.talend.core.language.LanguageManager;
import org.talend.core.model.components.ComponentCategory;
import org.talend.core.model.components.EComponentType;
import org.talend.core.model.components.IComponent;
import org.talend.core.model.context.ContextUtils;
import org.talend.core.model.general.ModuleNeeded;
import org.talend.core.model.general.Project;
import org.talend.core.model.metadata.IMetadataColumn;
@@ -863,9 +865,11 @@ public class ProcessorUtilities {
if (context.getName().equals(currentContext.getName())) {
// override parameter value before generate current context
IContext checkedContext = checkNeedOverrideContextParameterValue(currentContext, jobInfo);
checkedContext = checkCleanSecureContextParameterValue(checkedContext, jobInfo);
processor.setContext(checkedContext); // generate current context.
} else {
processor.setContext(context);
IContext checkedContext = checkCleanSecureContextParameterValue(context, jobInfo);
processor.setContext(checkedContext);
}
LastGenerationInfo.getInstance().getContextPerJob(jobInfo.getJobId(), jobInfo.getJobVersion()).add(
context.getName());
@@ -936,6 +940,49 @@ public class ProcessorUtilities {
return context;
}
private static IContext checkCleanSecureContextParameterValue(IContext currentContext, JobInfo jobInfo) {
JobInfo job = null;
if (jobInfo.getFatherJobInfo() == null) {
job = jobInfo;
} else {
job = getRootJob(jobInfo);
if (job.getProcess() == null || "route".equalsIgnoreCase(job.getProcess().getElementName())) {
// cleanup context only for child jobs which are referenced
// by tRunJob component or for Joblets (see TESB-29718 for details)
return currentContext;
}
}
if (job.getArgumentsMap() == null
|| job.getArgumentsMap().get(TalendProcessArgumentConstant.ARG_CLEAR_PASSWORD_CONTEXT_PARAMETERS) == null
|| !Boolean.parseBoolean((ProcessUtils.getOptionValue(job.getArgumentsMap(), TalendProcessArgumentConstant.ARG_CLEAR_PASSWORD_CONTEXT_PARAMETERS,
(String) null)))) {
return currentContext;
}
IContext context = currentContext.clone();
List<IContextParameter> contextParameterList = context.getContextParameterList();
for (IContextParameter contextParameter : contextParameterList) {
if (PasswordEncryptUtil.isPasswordType(contextParameter.getType())
|| ContextUtils.isSecureSensitiveParam(contextParameter.getName())) {
contextParameter.setValue("");
}
}
return context;
}
private static JobInfo getRootJob(JobInfo jobInfo) {
if (jobInfo != null && jobInfo.getFatherJobInfo() != null) {
return getRootJob(jobInfo.getFatherJobInfo());
}
return jobInfo;
}
private static void generateDataSet(IProcess process, IProcessor processor) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService =
@@ -1216,6 +1263,39 @@ public class ProcessorUtilities {
}
}
private static void syncContextResourcesForParentJob(IProcess currentProcess, IProgressMonitor progressMonitor) {
ITalendProcessJavaProject processJavaProject = mainJobInfo.getProcessor().getTalendJavaProject();
final IFolder mainResourcesFolder = processJavaProject.getExternalResourcesFolder();
final File targetFolder = mainResourcesFolder.getLocation().toFile();
final Set<JobInfo> dependenciesItems = mainJobInfo.getProcessor().getBuildChildrenJobs();
final IRunProcessService runProcessService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(
IRunProcessService.class);
List<ProcessItem> dependenciesItemsFiltered = dependenciesItems.stream().filter(jobInfo -> !jobInfo.isJoblet())
.map(JobInfo::getProcessItem).collect(Collectors.toList());
if (dependenciesItemsFiltered.size() > 0) {
dependenciesItemsFiltered.forEach(item -> {
ITalendProcessJavaProject childJavaProject = runProcessService.getTalendJobJavaProject(item.getProperty());
if (childJavaProject != null) {
final IFolder childResourcesFolder = childJavaProject.getExternalResourcesFolder();
if (childResourcesFolder.exists()) {
FileCopyUtils.syncFolder(childResourcesFolder.getLocation().toFile(), targetFolder, false);
}
}
});
try {
mainResourcesFolder.refreshLocal(IResource.DEPTH_INFINITE, progressMonitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
}
private static Set<ModuleNeeded> getAllJobTestcaseModules(ProcessItem selectedProcessItem) {
Set<ModuleNeeded> neededLibraries = new HashSet<>();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
@@ -1419,6 +1499,7 @@ public class ProcessorUtilities {
}
}
}
syncContextResourcesForParentJob(currentProcess, null);
}
/**