no.difi.certvalidator.rule.ExpirationSoonRule 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.rule;
import no.difi.certvalidator.api.CertificateValidationException;
import no.difi.certvalidator.api.FailedValidationException;
import java.security.cert.X509Certificate;
/**
* Validation making sure certificate doesn't expire in n milliseconds.
*/
public class ExpirationSoonRule extends AbstractRule {
private long millis;
public ExpirationSoonRule(long millis) {
this.millis = millis;
}
/**
* {@inheritDoc}
*/
@Override
public void validate(X509Certificate certificate) throws CertificateValidationException {
if (certificate.getNotAfter().getTime() < (System.currentTimeMillis() + millis))
throw new FailedValidationException(String.format("Certificate expires in less than %s milliseconds.", millis));
}
}