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));
}
});
}
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);
}
}
Aggregations