/*
* 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 CharacterMixRule implements PasswordValidationRule {
private String description;
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");
}
String password = querySpec.getCandidatePassword();
if (password.matches(".*[a-z].*") && password.matches(".*[A-Z].*")
&& password.matches(".*[0-9].*")) {
return null;
} else {
ValidationStatus vs=new ValidationStatus();
try {
vs.setStatusCode(validationStatusCode);
vs.setExplanation(explanation);
vs.setDescription(description);
} 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");
description = props.getProperty("description");
validationStatusCode = props.getProperty("validationStatusCode");
if (explanation==null || description==null || validationStatusCode==null) {
String errmsg="One or more required properties are null. Check config for properties:"
+" description, validationStatusCode, explanation";
throw new InstantiationException(errmsg);
}
}
}