org.owasp.esapi.reference.validation
Class CreditCardValidationRule

java.lang.Object
  extended by org.owasp.esapi.reference.validation.BaseValidationRule
      extended by org.owasp.esapi.reference.validation.CreditCardValidationRule
All Implemented Interfaces:
ValidationRule

public class CreditCardValidationRule
extends BaseValidationRule

A validator performs syntax and possibly semantic validation of Credit Card String from an untrusted source.

Since:
June 1, 2007
Author:
Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
See Also:
Validator

Field Summary
protected static java.lang.String CREDIT_CARD_VALIDATOR_KEY
          Key used to pull out encoder in configuration.
 
Fields inherited from class org.owasp.esapi.reference.validation.BaseValidationRule
allowNull, encoder
 
Constructor Summary
CreditCardValidationRule(java.lang.String typeName, Encoder encoder)
          Creates a CreditCardValidator using the rule found in security configuration
CreditCardValidationRule(java.lang.String typeName, Encoder encoder, StringValidationRule validationRule)
           
 
Method Summary
 int getMaxCardLength()
           
 StringValidationRule getStringValidatorRule()
           
 java.lang.String getValid(java.lang.String context, java.lang.String input)
          Parse the input, throw exceptions if validation fails
 java.lang.String sanitize(java.lang.String context, java.lang.String input)
          The method is similar to ValidationRuile.getSafe except that it returns a harmless object that may or may not have any similarity to the original input (in some cases you may not care).
 void setMaxCardLength(int maxCardLength)
           
 void setStringValidatorRule(StringValidationRule ccrule)
           
protected  boolean validCreditCardFormat(java.lang.String ccNum)
          Performs additional validation on the card nummber.
 
Methods inherited from class org.owasp.esapi.reference.validation.BaseValidationRule
assertValid, charArrayToSet, getEncoder, getSafe, getTypeName, getValid, isAllowNull, isValid, setAllowNull, setEncoder, setTypeName, whitelist, whitelist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CREDIT_CARD_VALIDATOR_KEY

protected static final java.lang.String CREDIT_CARD_VALIDATOR_KEY
Key used to pull out encoder in configuration. Prefixed with "Validator."

See Also:
Constant Field Values
Constructor Detail

CreditCardValidationRule

public CreditCardValidationRule(java.lang.String typeName,
                                Encoder encoder)
Creates a CreditCardValidator using the rule found in security configuration

Parameters:
typeName - a description of the type of card being validated
encoder -

CreditCardValidationRule

public CreditCardValidationRule(java.lang.String typeName,
                                Encoder encoder,
                                StringValidationRule validationRule)
Method Detail

getValid

public java.lang.String getValid(java.lang.String context,
                                 java.lang.String input)
                          throws ValidationException
Parse the input, throw exceptions if validation fails

Parameters:
context - for logging
input - the value to be parsed
Returns:
a validated value
Throws:
ValidationException - if any validation rules fail

validCreditCardFormat

protected boolean validCreditCardFormat(java.lang.String ccNum)
Performs additional validation on the card nummber. This implementation performs Luhn algorithm checking

Parameters:
ccNum - number to be validated
Returns:
true if the ccNum passes the Luhn Algorithm

sanitize

public java.lang.String sanitize(java.lang.String context,
                                 java.lang.String input)
The method is similar to ValidationRuile.getSafe except that it returns a harmless object that may or may not have any similarity to the original input (in some cases you may not care). In most cases this should be the same as the getSafe method only instead of throwing an exception, return some default value.

Specified by:
sanitize in class BaseValidationRule
Returns:
a parsed version of the input or a default value.

setStringValidatorRule

public void setStringValidatorRule(StringValidationRule ccrule)
Parameters:
ccrule - the ccrule to set

getStringValidatorRule

public StringValidationRule getStringValidatorRule()
Returns:
the ccrule

setMaxCardLength

public void setMaxCardLength(int maxCardLength)
Parameters:
maxCardLength - the maxCardLength to set

getMaxCardLength

public int getMaxCardLength()
Returns:
the maxCardLength


Copyright © 2010 The Open Web Application Security Project (OWASP). All Rights Reserved.