Search in sources :

Example 16 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate in project verify-hub by alphagov.

the class CertificateServiceTest method encryptionCertificateForEntityIdWarnsAndThrowsWhenTransactionCertificateExistsButIsInvalid.

@Test
public void encryptionCertificateForEntityIdWarnsAndThrowsWhenTransactionCertificateExistsButIsInvalid() {
    Assertions.assertThrows(NoCertificateFoundException.class, () -> {
        TransactionConfig transactionConfig = aTransactionConfigData().withEntityId(RP_ONE_ENTITY_ID).withEnabled(true).build();
        when(connectedServiceConfigRepository.has(RP_ONE_ENTITY_ID)).thenReturn(true);
        when(connectedServiceConfigRepository.get(RP_ONE_ENTITY_ID)).thenReturn(Optional.of(transactionConfig));
        when(certificateValidityChecker.isValid(any(Certificate.class))).thenReturn(false);
        try {
            certificateService.encryptionCertificateFor(RP_ONE_ENTITY_ID);
        } finally {
            String expectedLogMessage = "Encryption certificate for entityId '" + RP_ONE_ENTITY_ID + "' was requested but is invalid";
            checkForExpectedLogWarnings(List.of(expectedLogMessage));
        }
    });
}
Also used : TransactionConfig(uk.gov.ida.hub.config.domain.TransactionConfig) Certificate(uk.gov.ida.hub.config.domain.Certificate) Test(org.junit.jupiter.api.Test)

Example 17 with Certificate

use of uk.gov.ida.hub.config.domain.Certificate 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)17 Test (org.junit.jupiter.api.Test)13 MatchingServiceConfig (uk.gov.ida.hub.config.domain.MatchingServiceConfig)6 MatchingServiceConfigBuilder.aMatchingServiceConfig (uk.gov.ida.hub.config.domain.builders.MatchingServiceConfigBuilder.aMatchingServiceConfig)6 TransactionConfig (uk.gov.ida.hub.config.domain.TransactionConfig)5 DateTime (org.joda.time.DateTime)3 CertificateException (java.security.cert.CertificateException)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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)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