public ValidationErrorException() { this(null, null, new ValidatorHelperResult(false)); }
/** * Checks if the confidential value received in <code>value</code> is a value lower than the number or values received for the parameter * <code>parameter</code>. * * @param target Part of the url that represents the target action * @param parameter parameter * @param value value * @param stateValues real values for <code>parameter</code> * @return ValidatorHelperResult with the result of the validation. * @since HDIV 2.0 */ protected ValidatorHelperResult isInRange(final String target, final String parameter, final String value, final List<String> stateValues) { Matcher m = numberPattern.matcher(value); try { if (!m.matches() || Integer.parseInt(value) >= stateValues.size()) { String originalValue = stateValues.size() > 1 ? stateValues.toString() : stateValues.get(0); ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_CONFIDENTIAL_VALUE, target, parameter, value, originalValue); return new ValidatorHelperResult(error); } } catch (final NumberFormatException e) { // value is not a number or is greater than the length of Integer.MAX_VALUE String originalValue = stateValues.size() > 1 ? stateValues.toString() : stateValues.get(0); ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_CONFIDENTIAL_VALUE, target, parameter, value, originalValue); return new ValidatorHelperResult(error); } return ValidatorHelperResult.VALID; }
/** * Checks if the action received in the request is the same as the one stored in the HDIV state. * * @param context Request context * @param target Part of the url that represents the target action * @param stateAction The restored state for this url * @return valid result if the actions are the same. False otherwise. */ protected ValidatorHelperResult isTheSameAction(final RequestContextHolder context, final String target, String stateAction) { // Remove HTML escaped content from the action, for example, HTML entities like Ñ stateAction = HtmlUtils.htmlUnescape(stateAction); if (stateAction.equalsIgnoreCase(target)) { return ValidatorHelperResult.VALID; } if (target.endsWith("/")) { String actionSlash = stateAction + "/"; if (actionSlash.equalsIgnoreCase(target)) { return ValidatorHelperResult.VALID; } } if (log.isDebugEnabled()) { log.debug("Validation error in the action. Action in state [" + stateAction + "], action in the request [" + target + "]"); } ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_ACTION, target); return new ValidatorHelperResult(error); }
public ValidationErrorException(final String message) { this(message, null, new ValidatorHelperResult(new ValidatorError(message))); }
/** * Validate required parameters but not received in the request. * * @param request HttpServletRequest to validate * @param state IState The restored state for this url * @param target Part of the url that represents the target action * @param stateParams Url params from State * @param missingParameters Required parameters not received in the request. * @return result with the error */ protected ValidatorHelperResult validateMissingParameters(final RequestContextHolder request, final IState state, final String target, final Map<String, String[]> stateParams, final List<String> missingParameters) { for (Iterator<String> i = missingParameters.iterator(); i.hasNext();) { String param = i.next(); if (hdivConfig.isStartParameter(param) || hdivConfig.isParameterWithoutValidation(target, param)) { i.remove(); } } if (missingParameters.isEmpty()) { return ValidatorHelperResult.VALID; } if (log.isDebugEnabled()) { log.debug("Missing some required parameters: " + missingParameters.toString()); } ValidatorError error = new ValidatorError(HDIVErrorCodes.NOT_RECEIVED_ALL_REQUIRED_PARAMETERS, target, missingParameters.toString()); return new ValidatorHelperResult(error); }
ValidatorError error = new ValidatorError(HDIVErrorCodes.REPEATED_VALUES_FOR_PARAMETER, target, parameter, values[i], originalValue); return new ValidatorHelperResult(error); return new ValidatorHelperResult(error);
/** * Validate parameter non present in the state. * * @param request HttpServletRequest to validate * @param stateParams parameter and values from the parameters stored in the state * @param stateParameter IParameter The restored state for this url * @param actionParamValues actio params values * @param unauthorizedEditableParameters Editable parameters with errors * @param hdivParameter Hdiv state parameter name * @param target Part of the url that represents the target action * @param parameter Parameter name to validate * @return Valid if parameter has not errors * @since HDIV 2.1.13 */ protected ValidatorHelperResult validateExtraParameter(final RequestContextHolder request, final Map<String, String[]> stateParams, final IParameter stateParameter, final String[] actionParamValues, final List<ValidatorError> unauthorizedEditableParameters, final String hdivParameter, final String target, final String parameter) { // If the parameter is not defined in the state, it is an error. // With this verification we guarantee that no extra parameters are added. if (log.isDebugEnabled()) { log.debug("Validation Error Detected: Parameter [" + parameter + "] does not exist in the state for action [" + target + "]"); } ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_PARAMETER_NAME, target, parameter, request.getParameter(parameter)); return new ValidatorHelperResult(error); }
/** * It validates the parameters of an init page because our application can receive requests that require validation but don't have any * HDIV state. So, despite being init pages, editable data validation must be done. * * @param request HttpServletRequest to validate * @param target Part of the url that represents the target action * @return valid result if the values of the editable parameters pass the validations defined in hdiv-config.xml. False otherwise. * @since HDIV 1.1.2 */ protected ValidatorHelperResult validateStartPageParameters(final RequestContextHolder request, final String target) { List<ValidatorError> unauthorizedEditableParameters = new ArrayList<ValidatorError>(); Enumeration<?> parameters = request.getParameterNames(); while (parameters.hasMoreElements()) { String parameter = (String) parameters.nextElement(); String[] values = request.getParameterValues(parameter); validateEditableParameter(target, parameter, values, "text", unauthorizedEditableParameters); } if (!unauthorizedEditableParameters.isEmpty()) { return new ValidatorHelperResult(unauthorizedEditableParameters); } return ValidatorHelperResult.VALID; }
return new ValidatorHelperResult(error);
public ValidationErrorException(final String message, final Throwable e) { this(message, e, new ValidatorHelperResult(new ValidatorError(message))); result.getErrors().get(0).setException(e); }
ValidatorError error = new ValidatorError(HDIVErrorCodes.REPEATED_VALUES_FOR_PARAMETER, target, parameter, values[i], originalValue); return new ValidatorHelperResult(error);
ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_COOKIE, target, requestCookies[i].getName(), requestCookies[i].getValue(), savedCookie != null ? savedCookie.getValue() : null); return new ValidatorHelperResult(error);
ValidatorError error = new ValidatorError(HDIVErrorCodes.HDIV_PARAMETER_DOES_NOT_EXIST, context.getRequestedTarget(), context.getRequestContext().getHdivParameterName()); return new ValidatorHelperResult(error); ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_HDIV_PARAMETER_VALUE, context.getRequestedTarget(), context.getRequestContext().getHdivParameterName(), requestState); return new ValidatorHelperResult(error); return new ValidatorHelperResult(true, state); return new ValidatorHelperResult(error);
return new ValidatorHelperResult(unauthorizedEditableParameters);
/** * Checks that values <code>values</code> for the <code>parameter</code> are valid. * * @param request HttpServletRequest to validate * @param target Part of the url that represents the target action * @param stateParameter parameters from the state * @param actionParamValues parameter from the state * @param parameter Parameter name * @param values Parameter <code>parameter</code> values. * @return True If the <code>values</code> validation is correct. False otherwise. */ protected ValidatorHelperResult validateReceivedValuesInState(final RequestContextHolder request, final String target, final IParameter stateParameter, final String[] actionParamValues, final String parameter, final String[] values) { int size = values.length; String[] originalValues = new String[size]; for (int i = 0; i < size; i++) { IValidationResult result = dataValidator.validate(request, values[i], target, parameter, stateParameter, actionParamValues); if (!result.getLegal()) { ValidatorError error = new ValidatorError(HDIVErrorCodes.INVALID_PARAMETER_VALUE, target, parameter, values[i]); return new ValidatorHelperResult(error); } else { originalValues[i] = result.getResult(); } } if (hdivConfig.getConfidentiality()) { request.addParameterToRequest(parameter, originalValues); } return ValidatorHelperResult.VALID; }
return new ValidatorHelperResult(error);