use of uk.gov.ida.hub.config.exceptions.NoCertificateFoundException in project verify-hub by alphagov.
the class CertificateService method encryptionCertificateFor.
public Certificate encryptionCertificateFor(String entityId) {
CertificateConfigurable<?> config = getConfig(entityId);
Certificate cert = config.getEncryptionCertificate();
if (!certificateValidityChecker.isValid(cert)) {
LOG.warn("Encryption certificate for entityId '{}' was requested but is invalid", entityId);
throw new NoCertificateFoundException();
}
if (!cert.isEnabled()) {
throw new CertificateDisabledException();
}
return cert;
}
use of uk.gov.ida.hub.config.exceptions.NoCertificateFoundException in project verify-hub by alphagov.
the class CertificatesResource method getEncryptionCertificate.
@GET
@Path(Urls.ConfigUrls.ENCRYPTION_CERTIFICATE_PATH)
@Timed
public CertificateDto getEncryptionCertificate(@PathParam(Urls.SharedUrls.ENTITY_ID_PARAM) String entityId) {
try {
Certificate certificate = certificateService.encryptionCertificateFor(entityId);
Optional<String> base64Encoded = certificate.getBase64Encoded();
return certificate.getBase64Encoded().map(base64 -> aCertificateDto(entityId, base64Encoded.get(), CertificateDto.KeyUse.Encryption, certificate.getFederationEntityType())).orElseThrow(() -> exceptionFactory.createNoDataForEntityException(entityId));
} catch (NoCertificateFoundException ncfe) {
throw exceptionFactory.createNoDataForEntityException(entityId);
} catch (CertificateDisabledException cde) {
throw exceptionFactory.createDisabledTransactionException(entityId);
}
}
Aggregations