no.difi.certvalidator.structure.XorJunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-certvalidator Show documentation
Show all versions of commons-certvalidator Show documentation
Rule engine for creation of certificate validator.
package no.difi.certvalidator.structure;
import no.difi.certvalidator.api.CertificateValidationException;
import no.difi.certvalidator.api.FailedValidationException;
import no.difi.certvalidator.api.ValidatorRule;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
/**
* Allows combining instances of validators using a limited set of logic.
*/
public class XorJunction extends AbstractJunction {
public XorJunction(ValidatorRule... validatorRules) {
super(validatorRules);
}
/**
* {@inheritDoc}
*/
@Override
public void validate(X509Certificate certificate) throws CertificateValidationException {
List exceptions = new ArrayList();
for (ValidatorRule validatorRule : validatorRules) {
try {
validatorRule.validate(certificate);
} catch (CertificateValidationException e) {
exceptions.add(e);
}
}
if (exceptions.size() != validatorRules.size() - 1) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(String.format("Xor-junction failed with results (%s of %s):", exceptions.size(), validatorRules.size()));
for (Exception e : exceptions)
stringBuilder.append("\n* ").append(e.getMessage());
throw new FailedValidationException(stringBuilder.toString());
}
}
}