private boolean isHostKeySpecifiedWhenAlgorithmSet(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { if (hasText(sshUriProperties.getHostKeyAlgorithm()) && !VALID_HOST_KEY_ALGORITHMS.contains(sshUriProperties.getHostKeyAlgorithm())) { context.buildConstraintViolationWithTemplate( format("Property '%shostKeyAlgorithm' must be one of %s", GIT_PROPERTY_PREFIX, VALID_HOST_KEY_ALGORITHMS)) .addConstraintViolation(); return false; } return true; }
private boolean isPrivateKeyFormatCorrect(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { try { KeyPair.load(new JSch(), sshUriProperties.getPrivateKey().getBytes(), null); return true; } catch (JSchException e) { context.buildConstraintViolationWithTemplate( format("Property '%sprivateKey' is not a valid private key", GIT_PROPERTY_PREFIX)) .addConstraintViolation(); return false; } } }
@Override public boolean isValid(MultipleJGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { String knownHostsFile = sshUriProperties.getKnownHostsFile(); if (knownHostsFile != null && !new File(knownHostsFile).exists()) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( format("File '%s' specified in property 'spring.cloud.config.server.git.knownHostsFile' could not be located", knownHostsFile)) .addConstraintViolation(); return false; } return true; } }
@Override public boolean isValid(Map<String, String> map, ConstraintValidatorContext context) { for (String key : map.keySet()) { if (key == null || key.isEmpty()) { context.disableDefaultConstraintViolation(); // disable violation message context.buildConstraintViolationWithTemplate("key value cannot be null or empty").addConstraintViolation(); // add message return false; } if (map.get(key) == null || map.get(key).isEmpty()) { context.disableDefaultConstraintViolation(); // disable violation message context.buildConstraintViolationWithTemplate("value cannot be null or empty for key: " + key).addConstraintViolation(); // add message return false; } } return true; } }
private boolean isDecisionTaskValid(WorkflowTask workflowTask, ConstraintValidatorContext context) { boolean valid = true; if (workflowTask.getCaseValueParam() == null){ String message = String.format(PARAM_REQUIRED_STRING_FORMAT, "caseValueParam", TaskType.DECISION, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } if (workflowTask.getDecisionCases() == null) { String message = String.format(PARAM_REQUIRED_STRING_FORMAT, "decisionCases", TaskType.DECISION, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } else if (workflowTask.getDecisionCases() != null && (workflowTask.getDecisionCases().size() == 0)){ String message = String.format("decisionCases should have atleast one task for taskType: %s taskName: %s", TaskType.DECISION, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } return valid; }
private boolean isHttpTaskValid(WorkflowTask workflowTask, ConstraintValidatorContext context) { boolean valid = true; boolean isInputParameterSet = false; boolean isInputTemplateSet = false; //Either http_request in WorkflowTask inputParam should be set or in inputTemplate Taskdef should be set if (workflowTask.getInputParameters() != null && workflowTask.getInputParameters().containsKey("http_request")) { isInputParameterSet = true; } TaskDef taskDef = Optional.ofNullable(workflowTask.getTaskDefinition()).orElse(ValidationContext.getMetadataDAO().getTaskDef(workflowTask.getName())); if (taskDef != null && taskDef.getInputTemplate() != null && taskDef.getInputTemplate().containsKey("http_request")) { isInputTemplateSet = true; } if (!(isInputParameterSet || isInputTemplateSet)) { String message = String.format(PARAM_REQUIRED_STRING_FORMAT, "inputParameters.http_request", TaskType.HTTP, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } return valid; }
@Override public boolean isValid(WorkflowDef workflowDef, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); boolean valid = true; //check if taskReferenceNames are unique across tasks or not HashMap<String, Integer> taskReferenceMap = new HashMap<>(); for (WorkflowTask workflowTask : workflowDef.getTasks()) { if (taskReferenceMap.containsKey(workflowTask.getTaskReferenceName())) { String message = String.format("taskReferenceName: %s should be unique across tasks for a given workflowDefinition: %s", workflowTask.getTaskReferenceName(), workflowDef.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } else { taskReferenceMap.put(workflowTask.getTaskReferenceName(), 1); } } //check inputParameters points to valid taskDef return valid & verifyTaskInputParameters(context, workflowDef); }
private boolean verifyTaskInputParameters(ConstraintValidatorContext context, WorkflowDef workflow) { MutableBoolean valid = new MutableBoolean(); valid.setValue(true); if (workflow.getTasks() == null) { return valid.getValue(); } workflow.getTasks() .stream() .filter(workflowTask -> workflowTask.getInputParameters() != null) .forEach(workflowTask -> { List<String> errors = ConstraintParamUtil.validateInputParam(workflowTask.getInputParameters(), workflowTask.getName(), workflow); errors.forEach(message -> context.buildConstraintViolationWithTemplate(message).addConstraintViolation()); if(errors.size() > 0) { valid.setValue(false); } }); return valid.getValue(); }
@Override public boolean isValid(OAuthConfiguration value, ConstraintValidatorContext context) { boolean valid = true; if (value.client != null && value.client.autoapprove != null) { if (value.clients != null) { context.buildConstraintViolationWithTemplate( "Please use oauth.clients to specifiy autoapprove not client.autoapprove") .addConstraintViolation(); valid = false; } } return valid; }
@Override public boolean isValid(TaskDef taskDef, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); boolean valid = true; if (taskDef.getTimeoutSeconds() > 0) { if (taskDef.getResponseTimeoutSeconds() > taskDef.getTimeoutSeconds()) { valid = false; String message = String.format("TaskDef: %s responseTimeoutSeconds: %d must be less than timeoutSeconds: %d", taskDef.getName(), taskDef.getResponseTimeoutSeconds(), taskDef.getTimeoutSeconds()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); } } return valid; } }
@Override public boolean isValid(Map<String, Object> value, ConstraintValidatorContext context) { boolean valid = true; for (String key : requiredKeys) { if (!value.containsKey(key)) { context.buildConstraintViolationWithTemplate("Missing key ''" + key + "''") .addConstraintViolation(); valid = false; } } return valid; }
private boolean isPrivateKeyPresent(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { if (!hasText(sshUriProperties.getPrivateKey())) { context.buildConstraintViolationWithTemplate( format("Property '%sprivateKey' must be set when '%signoreLocalSshSettings' is specified", GIT_PROPERTY_PREFIX, GIT_PROPERTY_PREFIX)) .addConstraintViolation(); return false; } return true; }
private boolean isHostKeySpecifiedWhenAlgorithmSet(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { if (hasText(sshUriProperties.getHostKeyAlgorithm()) && !hasText(sshUriProperties.getHostKey())) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( format("Property '%shostKey' must be set when '%shostKeyAlgorithm' is specified", GIT_PROPERTY_PREFIX, GIT_PROPERTY_PREFIX)) .addConstraintViolation(); return false; } return true; }
private boolean isAlgorithmSpecifiedWhenHostKeySet(JGitEnvironmentProperties sshUriProperties, ConstraintValidatorContext context) { if (hasText(sshUriProperties.getHostKey()) && !hasText(sshUriProperties.getHostKeyAlgorithm())) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( format("Property '%shostKeyAlgorithm' must be set when '%shostKey' is specified", GIT_PROPERTY_PREFIX, GIT_PROPERTY_PREFIX)) .addConstraintViolation(); return false; } return true; } }
public boolean isValid(String value, ConstraintValidatorContext context) { if (!TimeUnit.contains(value)) { context.disableDefaultConstraintViolation(); // disable violation message context.buildConstraintViolationWithTemplate("must be one of " + TimeUnit.toValueNames()).addConstraintViolation(); // add message return false; } return true; } }
@Override public boolean isValid(Double aDouble, ConstraintValidatorContext context) { if (aDouble == 0) { context.disableDefaultConstraintViolation(); // disable violation message context.buildConstraintViolationWithTemplate("may not be zero").addConstraintViolation(); // add message return false; } return true; } }
private boolean isForkJoinTaskValid(WorkflowTask workflowTask, ConstraintValidatorContext context) { boolean valid = true; if (workflowTask.getForkTasks() != null && (workflowTask.getForkTasks().size() == 0)){ String message = String.format("forkTasks should have atleast one task for taskType: %s taskName: %s", TaskType.FORK_JOIN, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } return valid; } }
private boolean isDynamicTaskValid(WorkflowTask workflowTask, ConstraintValidatorContext context) { boolean valid = true; if (workflowTask.getDynamicTaskNameParam() == null){ String message = String.format(PARAM_REQUIRED_STRING_FORMAT, "dynamicTaskNameParam", TaskType.DYNAMIC, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } return valid; }
private boolean isEventTaskValid(WorkflowTask workflowTask, ConstraintValidatorContext context) { boolean valid = true; if (workflowTask.getSink() == null){ String message = String.format(PARAM_REQUIRED_STRING_FORMAT, "sink", TaskType.TASK_TYPE_EVENT, workflowTask.getName()); context.buildConstraintViolationWithTemplate(message).addConstraintViolation(); valid = false; } return valid; }
/** * Adds a new violation to this collector. This also sets violationOccurred to true. * * @param msg the message of the violation */ public void addViolation(String msg) { violationOccurred = true; context.buildConstraintViolationWithTemplate(msg) .addConstraintViolation(); }