throw new FailedAuthenticationException();
}
if (keyStore == null)
{
throw new WSSecurityException("TrustStore not set.");
}
// Check for the exact entry in the truststore first, then fallback to a CA check
try
{
if (trustStore.getCertificateAlias(cert) != null)
{
return;
}
}
catch (KeyStoreException e)
{
throw new WSSecurityException("Problems searching truststore", e);
}
List list = new ArrayList(1);
list.add(cert);
CertPath cp;
CertPathValidator cpv;
PKIXParameters parameters;
try
{
cp = CertificateFactory.getInstance("X.509").generateCertPath(list);
cpv = CertPathValidator.getInstance("PKIX");
parameters = new PKIXParameters(trustStore);
// We currently don't support CRLs
parameters.setRevocationEnabled(false);
}
catch (Exception e)
{
throw new WSSecurityException("Problems setting up certificate validation", e);
}
try
{
cpv.validate(cp, parameters);
}
catch (CertPathValidatorException cpve)
{
log.debug("Certificate is invalid:", cpve);
throw new FailedAuthenticationException();
}
catch (InvalidAlgorithmParameterException e)
{
throw new WSSecurityException("Problems setting up certificate validation", e);
}
}