use of org.cloudfoundry.credhub.util.CertificateReader in project credhub by cloudfoundry-incubator.
the class CertificateSignedByCAValidator method isValid.
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
try {
Field certificateField = value.getClass().getDeclaredField("certificate");
Field caField = value.getClass().getDeclaredField("ca");
certificateField.setAccessible(true);
caField.setAccessible(true);
final String certificateValue = (String) certificateField.get(value);
final String caValue = (String) caField.get(value);
if (StringUtils.isEmpty(certificateValue) || StringUtils.isEmpty(caValue)) {
return true;
}
final CertificateReader certificateReader = new CertificateReader(certificateValue);
return certificateReader.isSignedByCa(caValue);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.cloudfoundry.credhub.util.CertificateReader in project credhub by cloudfoundry-incubator.
the class CertificateValidator method isValid.
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
for (String fieldName : fields) {
try {
Field field = value.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
if (StringUtils.isEmpty((String) field.get(value))) {
return true;
}
CertificateReader reader = new CertificateReader((String) field.get(value));
return reader.isValid();
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return true;
}
Aggregations