/** * For all sensitive arguments (e.g. key names containing words like password, secret, * key, token) replace the value with '*****' string */ public List<String> sanitizeArguments(List<String> arguments) { if (!CollectionUtils.isEmpty(arguments)) { final List<String> sanitizedArguments = new ArrayList<>(arguments.size()); for (String argument : arguments) { sanitizedArguments.add(this.sanitize(argument)); } return sanitizedArguments; } return arguments; }
/** * Replaces a potential secure value with "******". * * @param argument the argument to cleanse. * @return the argument with a potentially sanitized value */ public String sanitize(String argument) { int indexOfFirstEqual = argument.indexOf("="); if (indexOfFirstEqual == -1) { return argument; } String key = argument.substring(0, indexOfFirstEqual); String value = argument.substring(indexOfFirstEqual + 1); value = sanitize(key, value); return String.format("%s=%s", key, value); }
/** * For all sensitive properties (e.g. key names containing words like password, secret, * key, token) replace the value with '*****' string */ public Map<String, String> sanitizeProperties(Map<String, String> properties) { if (!CollectionUtils.isEmpty(properties)) { final Map<String, String> sanitizedProperties = new LinkedHashMap<>(properties.size()); for (Map.Entry<String, String > property : properties.entrySet()) { sanitizedProperties.put(property.getKey(), this.sanitize(property.getKey(), property.getValue())); } return sanitizedProperties; } return properties; }
private TaskExecution sanitizePotentialSensitiveKeys(TaskExecution taskExecution) { List<String> args = taskExecution.getArguments().stream() .map(argument -> (this.argumentSanitizer.sanitize(argument))).collect(Collectors.toList()); taskExecution.setArguments(args); return taskExecution; }
/** * Replaces the sensitive String values in the JobParameter value. * * @param jobParameters the original job parameters * @return the sanitized job parameters */ public JobParameters sanitizeJobParameters(JobParameters jobParameters) { Map<String,JobParameter> newJobParameters = new HashMap<>(); jobParameters.getParameters().forEach( (key, jobParameter) -> { String updatedKey = !jobParameter.isIdentifying() ? "-" + key : key; if (jobParameter.getType().equals(JobParameter.ParameterType.STRING)) { newJobParameters.put(updatedKey, new JobParameter(this.sanitize(key, jobParameter.toString()))); } else { newJobParameters.put(updatedKey, jobParameter); } }); return new JobParameters(newJobParameters); } /**
modelBuilder.addRow().addValue(updatedKey).addValue(new ArgumentSanitizer().sanitize(key, String.valueOf(jobParameterEntry.getValue())));