com.ibm.passwordrules.standard
Class RuleSet

java.lang.Object
  |
  +--com.ibm.passwordrules.standard.RuleSet
All Implemented Interfaces:
java.lang.Cloneable, Rule, java.io.Serializable

public class RuleSet
extends java.lang.Object
implements Rule, java.lang.Cloneable, java.io.Serializable

The RuleSet class represents a set of related password rules. A RuleSet can be used to generate a random password that conforms to all the password rules in the set. The RuleSet can also be used to test a given password for conformity to all the rules in the RuleSet. Additional rules can be added to the RuleSet using the join method. An note that since RuleSet is a specialization of Rule, and entire RuleSet can be added to a given RuleSet. When adding rules, if the new rule conflicts with the existing rules in the set, an exception is thrown.

See Also:
Serialized Form

Field Summary
static int ITERATION_LIMIT
          This number was 200 when only standard rules were used.
 
Constructor Summary
RuleSet(PasswordRulesInfo rulesInfo)
          Constructor
 
Method Summary
 void constrain(PasswordGenerator generator)
          This Rule interface method in is not valid in the context of this class
 java.lang.String generate()
          Generates a randomly created password compatible with the contained rules.
 int getLastIterationCount()
          Used for testing only
 java.lang.String getParameter()
          This Rule interface method in is not valid in the context of this class
 java.util.Collection getRules()
          Method will return all rules contained in this ruleSet objects.
 PasswordRulesInfo getRulesInfo()
          Getter for PasswordRulesInfo object
 ValidationInfo getValidationInfo()
          Getter for ValidationInfo object.
 boolean join(Rule rule)
          Method joins given rule object to this RuleSet object.
 void join(RuleSet ruleSet)
          Joins two rule sets together.
static RuleSet loadFromXML(java.io.InputStream is)
          Method will generate a ruleSet object from XML representation
static void saveToXML(RuleSet ruleSet, java.io.OutputStream os, java.lang.String title)
          Method will generate XML representation from a give RuleSet object
 void setParameter(java.lang.String parameter)
          This Rule interface method in is not valid in the context of this class
 void setRulesInfo(PasswordRulesInfo rulesInfo)
          Setter for PasswordRulesInfo object
 void setValidationInfo(ValidationInfo validationInfo)
          Setter for ValidationInfo object
 boolean validate(java.lang.String password, ValidationInfo validationInfo)
          Validate the given password using the given validation info.
 boolean validateSafe(java.lang.String password, ValidationInfo validationInfo)
          Validate the given password using the given validation info.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ITERATION_LIMIT

public static final int ITERATION_LIMIT
This number was 200 when only standard rules were used. In anticipation of the need for more iterations when custom rules are used, it was bumped up to 10000 It is possible to estimate the magnitude this "magic number" using statistical analysis on a large number of samples for a known set of password rules. The number needs to leverage the maximum expected amount of time to generate a password.
Constructor Detail

RuleSet

public RuleSet(PasswordRulesInfo rulesInfo)
Constructor
Parameters:
rulesInfo - Value object containing the password rules
Method Detail

loadFromXML

public static RuleSet loadFromXML(java.io.InputStream is)
                           throws java.lang.Exception
Method will generate a ruleSet object from XML representation
Parameters:
is - InputStream
Returns:
RuleSet object
Throws:
java.lang.Exception - any exception thrown during parsing.

saveToXML

public static void saveToXML(RuleSet ruleSet,
                             java.io.OutputStream os,
                             java.lang.String title)
                      throws java.lang.Exception
Method will generate XML representation from a give RuleSet object
Parameters:
ruleSet - RuleSet object
os - OutputStream to write to
title - of the XML document
Throws:
java.lang.Exception - Any exception thrown when converting ruleSet to XML.

setRulesInfo

public void setRulesInfo(PasswordRulesInfo rulesInfo)
Setter for PasswordRulesInfo object
Parameters:
rulesInfo - PasswordRulesInfo object

getRulesInfo

public PasswordRulesInfo getRulesInfo()
Getter for PasswordRulesInfo object
Returns:
PasswordRulesInfo object

getValidationInfo

public ValidationInfo getValidationInfo()
Getter for ValidationInfo object.
Returns:
ValidationInfo object

setValidationInfo

public void setValidationInfo(ValidationInfo validationInfo)
Setter for ValidationInfo object
Parameters:
validationInfo - ValidationInfo object

getRules

public java.util.Collection getRules()
Method will return all rules contained in this ruleSet objects.
Returns:
Collection of Rule objects.

join

public void join(RuleSet ruleSet)
          throws IncompatibleRulesException
Joins two rule sets together.
Parameters:
ruleSet - ruleSet to join
Throws:
IncompatibleRulesException - when RuleSet object to join contains incompatible rules.

join

public boolean join(Rule rule)
             throws IncompatibleRulesException
Method joins given rule object to this RuleSet object.
Specified by:
join in interface Rule
Parameters:
rule - Rule to join
Returns:
true if join was successful
Throws:
IncompatibleRulesException - when RuleSet object to join contains incompatible rules.

validate

public boolean validate(java.lang.String password,
                        ValidationInfo validationInfo)
                 throws InvalidPasswordException
Validate the given password using the given validation info.
Specified by:
validate in interface Rule
Parameters:
validationInfo - ValidationInfo object
password - Password to validate.
Returns:
true when rules were successfully validated
Throws:
InvalidPasswordException - Thrown when given password violates one of the rules.

generate

public java.lang.String generate()
                          throws IterationsExceededException
Generates a randomly created password compatible with the contained rules.
Returns:
Generated password.
Throws:
IterationsExceededException - Thrown when a maximum number of iterations allowed before generating a valid password is exceeded.

validateSafe

public boolean validateSafe(java.lang.String password,
                            ValidationInfo validationInfo)
Validate the given password using the given validation info. This version will never throw an exception, but will return false if the password is invalid. It is not possible to get any more information about why the password failed when using this version.
Specified by:
validateSafe in interface Rule
Parameters:
validationInfo - ValidationInfo object
password - Password to validate.
Returns:
True if the password validates false otherwise.

constrain

public void constrain(PasswordGenerator generator)
This Rule interface method in is not valid in the context of this class
Specified by:
constrain in interface Rule
Parameters:
generator - Generator which contains a character template(s) to be constrained.

getParameter

public java.lang.String getParameter()
This Rule interface method in is not valid in the context of this class
Specified by:
getParameter in interface Rule
Returns:
 

setParameter

public void setParameter(java.lang.String parameter)
This Rule interface method in is not valid in the context of this class
Specified by:
setParameter in interface Rule
Following copied from interface: com.ibm.passwordrules.Rule
Parameters:
parameter - String representing the constraining parameter

getLastIterationCount

public int getLastIterationCount()
Used for testing only