class DefaultCertificateAuthorityService implements CertificateAuthorityService {

  @Override
  public CertificateCredentialValue findActiveVersion(final String caName) {
    final CredentialVersion mostRecent = certificateVersionDataService.findActive(caName);

    if (mostRecent == null) {
      throw new EntryNotFoundException(ErrorMessages.Credential.CERTIFICATE_ACCESS);
    }

    if (!(mostRecent instanceof CertificateCredentialVersion)) {
      throw new ParameterizedValidationException(ErrorMessages.NOT_A_CA_NAME);
    }
    final CertificateCredentialVersion certificateCredential = (CertificateCredentialVersion) mostRecent;

    if (!certificateCredential.getParsedCertificate().isCa()) {
      throw new ParameterizedValidationException(ErrorMessages.CERT_NOT_CA);
    }
    return new CertificateCredentialValue(
            certificateCredential.getCertificate(),
            certificateCredential.getPrivateKey(),
            certificateCredential.isCertificateAuthority(),
            certificateCredential.isSelfSigned(),
            certificateCredential.getGenerated(),
            certificateCredential.isVersionTransitional(),
            certificateCredential.getVersionCreatedAt());

  }

  @Autowired public  DefaultCertificateAuthorityService(final DefaultCertificateVersionDataService certificateVersionDataService);

}