Package com.any_service_provider.gateways.pvs.rule

Source Code of com.any_service_provider.gateways.pvs.rule.LengthRule

/*
* Created on Dec 8, 2006
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.any_service_provider.gateways.pvs.rule;

import java.util.Properties;

import org.openeai.config.EnterpriseFieldException;

import com.any_service_provider.gateways.pvs.PasswordValidationException;
import com.any_service_provider.gateways.pvs.PasswordValidationRule;
import com.openii.moa.objects.resources.v1_0.PasswordValidationQuerySpecification;
import com.openii.moa.objects.resources.v1_0.ValidationStatus;

/**
* @author tcerven
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class LengthRule implements PasswordValidationRule  {
 
  private int minimum;
  private int maximum;
  private String minimumLengthDescription;
  private String maximumLengthDescription;
  private String explanation;
  private String validationStatusCode;

  /* (non-Javadoc)
   * @see com.any_service_provider.gateways.pvs.PasswordValidationRule#validate(com.openii.moa.objects.resources.v1_0.ValidPasswordQuerySpecification)
   */
  public ValidationStatus validate(PasswordValidationQuerySpecification querySpec)
    throws PasswordValidationException
  {
    if (querySpec==null) {
      throw new PasswordValidationException("The query spec is null");
    }
    int l = querySpec.getCandidatePassword().length();
    if (l>=minimum && l<=maximum) {
      return null;
    } else {
      ValidationStatus vs=new ValidationStatus();
      try {
        vs.setStatusCode(validationStatusCode);
        vs.setExplanation(explanation);
        if (l<minimum) {
          vs.setDescription(minimumLengthDescription);
        }
        if (l>maximum) {
          vs.setDescription(maximumLengthDescription);
        }
      } catch (EnterpriseFieldException e) {
        e.printStackTrace();
        throw new PasswordValidationException(e.getMessage());
      }
      return vs;
    }
   
  }

  /* (non-Javadoc)
   * @see com.any_service_provider.gateways.pvs.PasswordValidationRule#setProperites(java.util.Properties)
   */
  public void setProperites(Properties props) throws InstantiationException {
    explanation = props.getProperty("explanation");
    minimumLengthDescription = props.getProperty("minimumLengthDescription");
    maximumLengthDescription = props.getProperty("maximumLengthDescription");
    validationStatusCode = props.getProperty("validationStatusCode");
    if (explanation==null || props.getProperty("minimumLength")==null || props.getProperty("maximumLength")==null
        || minimumLengthDescription==null || maximumLengthDescription==null || validationStatusCode==null) {
          String errmsg="One or more required properties are null. Check config for properties:"
              +" minimum, maximum, minimumLengthDescription, maximumLengthDescription, validationStatusCode, explanation";
          throw new InstantiationException(errmsg);
      }
    try {
      minimum = Integer.parseInt(props.getProperty("minimumLength"));
      maximum = Integer.parseInt(props.getProperty("maximumLength"));
    } catch (NumberFormatException e) {
      String errmsg="Either minimumLength or maximumLength are not integers. Check config.";
      throw new InstantiationException(errmsg);     
    }

  }
}
TOP

Related Classes of com.any_service_provider.gateways.pvs.rule.LengthRule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.