Search in sources :

Example 1 with NoCertificateFoundException

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;
}
Also used : NoCertificateFoundException(uk.gov.ida.hub.config.exceptions.NoCertificateFoundException) CertificateDisabledException(uk.gov.ida.hub.config.exceptions.CertificateDisabledException) Certificate(uk.gov.ida.hub.config.domain.Certificate)

Example 2 with NoCertificateFoundException

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);
    }
}
Also used : PathParam(javax.ws.rs.PathParam) ExceptionFactory(uk.gov.ida.hub.config.exceptions.ExceptionFactory) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) CertificateDto(uk.gov.ida.hub.config.dto.CertificateDto) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) InvalidCertificateDto(uk.gov.ida.hub.config.dto.InvalidCertificateDto) Urls(uk.gov.ida.hub.config.Urls) NoCertificateFoundException(uk.gov.ida.hub.config.exceptions.NoCertificateFoundException) Certificate(uk.gov.ida.hub.config.domain.Certificate) Collection(java.util.Collection) CertificateDto.aCertificateDto(uk.gov.ida.hub.config.dto.CertificateDto.aCertificateDto) ConfigConfiguration(uk.gov.ida.hub.config.ConfigConfiguration) CertificateHealthCheckDto(uk.gov.ida.hub.config.dto.CertificateHealthCheckDto) Set(java.util.Set) CertificateService(uk.gov.ida.hub.config.application.CertificateService) CertificateDisabledException(uk.gov.ida.hub.config.exceptions.CertificateDisabledException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Response(javax.ws.rs.core.Response) OCSPCertificateChainValidityChecker(uk.gov.ida.hub.config.domain.OCSPCertificateChainValidityChecker) Optional(java.util.Optional) NoCertificateFoundException(uk.gov.ida.hub.config.exceptions.NoCertificateFoundException) CertificateDisabledException(uk.gov.ida.hub.config.exceptions.CertificateDisabledException) Certificate(uk.gov.ida.hub.config.domain.Certificate) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Certificate (uk.gov.ida.hub.config.domain.Certificate)2 CertificateDisabledException (uk.gov.ida.hub.config.exceptions.CertificateDisabledException)2 NoCertificateFoundException (uk.gov.ida.hub.config.exceptions.NoCertificateFoundException)2 Timed (com.codahale.metrics.annotation.Timed)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 ConfigConfiguration (uk.gov.ida.hub.config.ConfigConfiguration)1 Urls (uk.gov.ida.hub.config.Urls)1 CertificateService (uk.gov.ida.hub.config.application.CertificateService)1 OCSPCertificateChainValidityChecker (uk.gov.ida.hub.config.domain.OCSPCertificateChainValidityChecker)1