/** * A method to append a validation response to this validation response. The errors list and warnings list are * simply appended, and the isValid is logically AND-ed and isModified is logically OR-ed. * * @param validationResponse */ public void append( ValidationResponse validationResponse ) { for ( ValidationMessage msg : validationResponse.getValidationErrors() ) { if ( getValidationError( msg.getKey() ) != null ) { msg.setKey( msg.getKey() + "(" + key++ + ")" ); } addValidationError( msg ); } for ( ValidationMessage msg : validationResponse.getValidationWarnings() ) { if ( getValidationWarning( msg.getKey() ) != null ) { msg.setKey( msg.getKey() + "(" + key++ + ")" ); } addValidationWarning( msg ); } setValid( isValid() && validationResponse.isValid() ); setModified( isModified() || validationResponse.isModified() ); }
@Override public ValidationResponse doValidateChanges( Object changedConfiguration ) { return new ValidationResponse(); } }
public ValidationResponse validateAnonymousPassword( SecurityValidationContext context, String anonymousPassword ) { // we are not currently doing anything here ValidationResponse validationResponse = new ValidationResponse(); validationResponse.setContext( context ); return validationResponse; }
@RequestMapping(value="/validate", method = RequestMethod.POST, consumes="text/plain", produces="application/json") public ValidationResponse process(@RequestBody String payload) throws JsonParseException, IOException { ValidationResponse response = new ValidationResponse(); boolean retValue = false; retValue = Validator.isValid(payload); System.out.println(retValue); if (retValue == false) { response.setMessage("Invalid JSON"); } else { response.setMessage("Valid JSON"); } return response; }
@RequestMapping(value="/validate") public @ResponseBody ValidationResponse processForm(Model model, @Valid AddressForm addressForm, BindingResult result) { ValidationResponse res = new ValidationResponse(); if (result.hasErrors()) { res.setStatus("FAIL"); for (ObjectError error : result.getAllErrors()) { if (error instanceof FieldError) { FieldError fieldError = (FieldError) error; res.addError(fieldError.getField(), fieldError.getDefaultMessage()); } } } else { res.setStatus("SUCCESS"); } return res; }
public ValidationResponse validateHttpProxySettings( ApplicationValidationContext ctx, CHttpProxySettings settings ) { ValidationResponse response = new ApplicationValidationResponse(); if ( ctx != null ) { response.setContext( ctx ); } if ( settings.getPort() < 80 ) { settings.setPort( 8082 ); response.addValidationWarning( "The HTTP Proxy port is below 80? Settings defaulted." ); response.setModified( true ); } if ( !CHttpProxySettings.PROXY_POLICY_PASS_THRU.equals( settings.getProxyPolicy() ) && !CHttpProxySettings.PROXY_POLICY_STRICT.equals( settings.getProxyPolicy() ) ) { response.addValidationError( "The HTTP Proxy policy settings is invalid: '" + settings.getProxyPolicy() + "'. Valid policies are '" + CHttpProxySettings.PROXY_POLICY_STRICT + "' and '" + CHttpProxySettings.PROXY_POLICY_PASS_THRU + "'." ); } return response; }
protected void checkUsersStatus(String status) throws InvalidConfigurationException { boolean found = false; for (UserStatus userStatus : UserStatus.values()) { if (userStatus.name().equals(status)) { found = true; } } if (!found) { ValidationResponse response = new ValidationResponse(); response.addValidationError(new ValidationMessage("status", "Users status is not valid.")); throw new InvalidConfigurationException(response); } }
public void createUserRoleMapping( CUserRoleMapping userRoleMapping, SecurityValidationContext context ) throws InvalidConfigurationException { if ( context == null ) { context = this.initializeContext(); } try { // this will throw a NoSuchRoleMappingException, if there isn't one readUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ); ValidationResponse vr = new ValidationResponse(); vr.addValidationError( new ValidationMessage( "*", "User Role Mapping for user '" + userRoleMapping.getUserId() + "' already exists." ) ); throw new InvalidConfigurationException( vr ); } catch ( NoSuchRoleMappingException e ) { // expected } ValidationResponse vr = validator.validateUserRoleMapping( context, userRoleMapping, false ); if ( vr.getValidationErrors().size() > 0 ) { throw new InvalidConfigurationException( vr ); } getConfiguration().addUserRoleMapping( userRoleMapping ); logValidationWarnings( vr ); }
public void addValidationError( String message ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message ); addValidationError( e ); }
protected void checkValidationResponse( ValidationResponse response ) throws ConfigurationException { if ( response != null && !response.isValid() ) { throw new InvalidConfigurationException( response ); } }
public ValidationResponse validateRealms( SecurityValidationContext context, List<String> realms ) { ValidationResponse validationResponse = new ValidationResponse(); validationResponse.setContext( context ); if ( ( context.getSecurityConfiguration() != null && context.getSecurityConfiguration().isEnabled() ) || context.getSecurityConfiguration() == null ) { if ( realms.size() < 1 ) { validationResponse.addValidationError( "Security is enabled, You must have at least one realm enabled." ); } // TODO: we should also try to load each one to see if it exists } return validationResponse; }
public void addValidationError( ValidationMessage message ) { getValidationErrors().add( message ); this.valid = false; }
public ValidationResponse validateErrorReporting( ApplicationValidationContext ctx, CErrorReporting settings ) { ValidationResponse response = new ApplicationValidationResponse(); if ( ctx != null ) { response.setContext( ctx ); } if ( settings.isEnabled() ) { if ( StringUtils.isEmpty( settings.getJiraUrl() ) ) { ValidationMessage msg = new ValidationMessage( "jiraUrl", "JIRA URL is empty." ); response.addValidationError( msg ); } if ( StringUtils.isEmpty( settings.getJiraProject() ) ) { ValidationMessage msg = new ValidationMessage( "jiraProject", "JIRA Project is empty." ); response.addValidationError( msg ); } } return response; }
public ValidationResponse validateRemoteHttpProxySettings( ApplicationValidationContext ctx, CRemoteHttpProxySettings settings ) { ValidationResponse response = new ApplicationValidationResponse(); if ( ctx != null ) { response.setContext( ctx ); } if ( settings.getProxyPort() < 1 || settings.getProxyPort() > 65535 ) { response.addValidationError( "The proxy port must be an integer between 1 and 65535!" ); } response.append( validateRemoteAuthentication( ctx, settings.getAuthentication() ) ); return response; }
response.setContext( ctx ); ApplicationValidationContext context = (ApplicationValidationContext) response.getContext(); response.addValidationError( "The RepositoryTarget may have no empty/null ID!" ); response.addValidationError( "The RepositoryTarget may have no empty/null Name!" ); response.addValidationError( "Repository target with ID='" + settings.getId() + "' has empty content class!" ); response.addValidationError( "This target ID is already existing!" ); response.addValidationError( "Repository target with ID='" + settings.getId() + "' has invalid regexp pattern: " + pattern ); response.addValidationError( "Repository target with ID='" + settings.getId() + "' has no regexp pattern defined!" );
response.addValidationError( new ValidationMessage( "id", "Repository ID must not be blank!" ) ); .addValidationError( new ValidationMessage( "id", "Only letters, digits, underscores, hyphens, and dots are allowed in Repository ID" ) ); response.addValidationError( new ValidationMessage( "id", "Repository ID can't be 'all', reserved word" ) ); response.addValidationWarning( new ValidationMessage( "id", "Repository with ID='" + cfg.getId() + "' has no name, defaulted it's name to it's ID." ) ); response.setModified( true ); response.addValidationError( new ValidationMessage( "localStatus", "LocalStatus of repository with ID=\"" + cfg.getId() + "\" has unacceptable value \"" + cfg.getLocalStatus() + "\"! (Allowed values are: \"" + LocalStatus.IN_SERVICE + "\" and \"" + LocalStatus.OUT_OF_SERVICE + "\")", e ) ); response.addValidationWarning( new ValidationMessage( "indexable", "Indexing isn't supported for \"" + cfg.getProviderHint() + "\" repositories, only Maven2 repositories are indexable!" ) ); response.setModified( true );
public ValidationResponse validateModel( SecurityValidationContext context, ValidationRequest<SecurityConfiguration> request ) { ValidationResponse validationResponse = new ValidationResponse(); validationResponse.setContext( context ); SecurityConfiguration configuration = request.getConfiguration(); validationResponse.append( this.validateAnonymousUsername( context, configuration.getAnonymousUsername() ) ); validationResponse.append( this.validateAnonymousPassword( context, configuration.getAnonymousPassword() ) ); validationResponse.append( this.validateRealms( context, configuration.getRealms() ) ); return validationResponse; }
public String getMessage() { StringWriter sw = new StringWriter(); sw.append( super.getMessage() ); if ( getValidationResponse() != null ) { if ( getValidationResponse().getValidationErrors().size() > 0 ) { sw.append( "\nValidation errors follows:\n" ); for ( ValidationMessage error : getValidationResponse().getValidationErrors() ) { sw.append( error.toString() ); } sw.append( "\n" ); } if ( getValidationResponse().getValidationWarnings().size() > 0 ) { sw.append( "\nValidation warnings follows:\n" ); for ( ValidationMessage warning : getValidationResponse().getValidationWarnings() ) { sw.append( warning.toString() ); } sw.append( "\n" ); } } return sw.toString(); }
@RequestMapping(value = "/client/register", method = RequestMethod.POST, headers = {"Access-Control-Allow-Origin=*"}) @ResponseBody ValidationResponse registerClient(@ModelAttribute("user")User user, BindingResult errors, @Param String type) { ValidationResponse response = new ValidationResponse(); getUserValidator().validate(user, errors); if(errors.hasErrors()) { response.setStatus("FAIL"); List<FieldError> allErrors = errors.getFieldErrors(); List<ErrorMessage> errorMesages = new ArrayList<ErrorMessage>(); errorMesages.add(new ErrorMessage(objectError.getField(), objectError.getDefaultMessage())); response.setErrorMessageList(errorMesages); }else { Role role = new Role(); boolean mailSent = true; if(mailSent){ response.setStatus("SUCCESS"); response.setStatus("FAIL");
if ( vResponse.isValid() ) if ( vResponse.isModified() )