public void addValidationError( String message ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message ); addValidationError( e ); }
public void addValidationError( String message, Throwable t ) { ValidationMessage e = new ValidationMessage( String.valueOf( key++ ), message, t ); addValidationError( e ); }
public void validateTime(String key, Date date) throws InvalidConfigurationException { if (date.before(new Date())) { ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage(key, "Time cannot be in the past."); vr.addValidationError(vm); throw new InvalidConfigurationException(vr); } }
public void validateTime( String key, Date date ) throws InvalidConfigurationException { if ( date.before( new Date() ) ) { ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage( key, "Time cannot be in the past." ); vr.addValidationError( vm ); throw new InvalidConfigurationException( vr ); } }
public void validateStartDate(String date) throws InvalidConfigurationException { Calendar cal = Calendar.getInstance(); Date startDate = new Date(Long.parseLong(date)); cal.setTime(startDate); Calendar nowCal = Calendar.getInstance(); nowCal.add(Calendar.DAY_OF_YEAR, -1); nowCal.set(Calendar.HOUR, 0); nowCal.set(Calendar.MINUTE, 0); nowCal.set(Calendar.SECOND, 0); nowCal.set(Calendar.MILLISECOND, 0); // This is checking just the year/month/day, time isn't of concern right now // basic check that the day timestamp is roughly in the correct range if (cal.before(nowCal)) { if (getLogger().isDebugEnabled()) { getLogger().debug("Validation error for startDate: " + startDate.toString()); } ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage("startDate", "Date cannot be in the past."); vr.addValidationError(vm); throw new InvalidConfigurationException(vr); } }
public void validateStartDate( String date ) throws InvalidConfigurationException { Calendar cal = Calendar.getInstance(); Date startDate = new Date( Long.parseLong( date ) ); cal.setTime( startDate ); Calendar nowCal = Calendar.getInstance(); nowCal.add( Calendar.DAY_OF_YEAR, -1 ); nowCal.set( Calendar.HOUR, 0 ); nowCal.set( Calendar.MINUTE, 0 ); nowCal.set( Calendar.SECOND, 0 ); nowCal.set( Calendar.MILLISECOND, 0 ); // This is checking just the year/month/day, time isn't of concern right now // basic check that the day timestamp is roughly in the correct range if ( cal.before( nowCal ) ) { if ( getLogger().isDebugEnabled() ) { getLogger().debug( "Validation error for startDate: " + startDate.toString() ); } ValidationResponse vr = new ApplicationValidationResponse(); ValidationMessage vm = new ValidationMessage( "startDate", "Date cannot be in the past." ); vr.addValidationError( vm ); throw new InvalidConfigurationException( vr ); } }
public ValidationResponse validateSmtpConfiguration( ApplicationValidationContext ctx, CSmtpConfiguration settings ) { ValidationResponse response = new ApplicationValidationResponse(); if ( ctx != null ) { response.setContext( ctx ); } if ( StringUtils.isEmpty( settings.getHostname() ) ) { ValidationMessage msg = new ValidationMessage( "host", "SMTP Host is empty." ); response.addValidationError( msg ); } if ( settings.getPort() < 0 ) { ValidationMessage msg = new ValidationMessage( "port", "SMTP Port is inavlid. Enter a port greater than 0." ); response.addValidationError( msg ); } if ( StringUtils.isEmpty( settings.getSystemEmailAddress() ) ) { ValidationMessage msg = new ValidationMessage( "systemEmailAddress", "System Email Address is empty." ); response.addValidationError( msg ); } return response; }
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; }
response.addValidationError(msg); response.addValidationError(msg); response.addValidationError(msg); response.addValidationError(msg); log.debug("Failed to find role {} during validation.", config.getDefaultRole(), e); ValidationMessage msg = new ValidationMessage("defaultRole", "Failed to find role."); response.addValidationError(msg);
response.addValidationError( msg ); response.addValidationError( msg ); response.addValidationError( msg ); response.addValidationError( msg ); response.addValidationError( msg );
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); } }
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 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 ValidationResponse validateRepositoryMirrors( ApplicationValidationContext ctx, List<CMirror> mirrors ) { ValidationResponse response = new ApplicationValidationResponse(); if ( ctx != null ) { response.setContext( ctx ); } for ( CMirror mirror : mirrors ) { if ( StringUtils.isEmpty( mirror.getId() ) ) { String newId = generateId(); mirror.setId( newId ); response .addValidationWarning( "Fixed wrong mirror ID from '" + mirror.getId() + "' to '" + newId + "'" ); response.setModified( true ); } if ( StringUtils.isEmpty( mirror.getId() ) ) { response.addValidationError( "The Mirror may have no empty/null ID!" ); } if ( StringUtils.isEmpty( mirror.getUrl() ) ) { response.addValidationError( "The Mirror may have no empty/null URL!" ); } } return response; }
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; }
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.addValidationError( message ); response.addValidationError( message );
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 updateUserRoleMapping( CUserRoleMapping userRoleMapping, SecurityValidationContext context ) throws InvalidConfigurationException, NoSuchRoleMappingException { if ( context == null ) { context = initializeContext(); } if ( readUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ) == null ) { ValidationResponse vr = new ValidationResponse(); vr.addValidationError( new ValidationMessage( "*", "No User Role Mapping found for user '" + userRoleMapping.getUserId() + "'." ) ); throw new InvalidConfigurationException( vr ); } ValidationResponse vr = validator.validateUserRoleMapping( context, userRoleMapping, true ); if ( vr.getValidationErrors().size() > 0 ) { throw new InvalidConfigurationException( vr ); } deleteUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ); getConfiguration().addUserRoleMapping( userRoleMapping ); }
/** * 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() ); }