use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class CertificateActions method importCertificate.
private CertificateModel importCertificate(CertificateModel certificateModel) throws AlertException {
CustomCertificateModel certificateToStore = convertToDatabaseModel(certificateModel);
try {
CustomCertificateModel storedCertificate = certificateAccessor.storeCertificate(certificateToStore);
trustStoreService.importCertificate(storedCertificate);
return convertDatabaseModelToRestModel(storedCertificate);
} catch (AlertException importException) {
deleteByAlias(certificateToStore);
throw importException;
}
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class CertificateActions method validateCertificateFields.
private List<AlertFieldStatus> validateCertificateFields(CertificateModel certificateModel) {
CustomCertificateModel convertedModel = convertToDatabaseModel(certificateModel);
List<AlertFieldStatus> fieldErrors = new ArrayList<>();
if (StringUtils.isBlank(certificateModel.getAlias())) {
fieldErrors.add(AlertFieldStatus.error(CertificatesDescriptor.KEY_ALIAS, "Alias cannot be empty."));
} else {
List<CustomCertificateModel> duplicateCertificates = certificateAccessor.getCertificates().stream().filter(certificate -> certificate.getAlias().equals(certificateModel.getAlias())).collect(Collectors.toList());
if (duplicateCertificates.size() > 1) {
fieldErrors.add(AlertFieldStatus.error(CertificatesDescriptor.KEY_ALIAS, ERROR_DUPLICATE_ALIAS));
} else if (duplicateCertificates.size() == 1) {
boolean sameConfig = convertedModel.getNullableId() != null && duplicateCertificates.get(0).getNullableId().equals(convertedModel.getNullableId());
if (!sameConfig) {
fieldErrors.add(AlertFieldStatus.error(CertificatesDescriptor.KEY_ALIAS, ERROR_DUPLICATE_ALIAS));
}
}
}
if (StringUtils.isBlank(certificateModel.getCertificateContent())) {
fieldErrors.add(AlertFieldStatus.error(CertificatesDescriptor.KEY_CERTIFICATE_CONTENT, "Certificate content cannot be empty."));
} else {
try {
trustStoreService.validateCertificateContent(convertedModel);
} catch (AlertException ex) {
logger.error(ex.getMessage(), ex);
fieldErrors.add(AlertFieldStatus.error(CertificatesDescriptor.KEY_CERTIFICATE_CONTENT, String.format("Certificate content not valid: %s", ex.getMessage())));
}
}
return fieldErrors;
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessor method createModel.
private CustomCertificateModel createModel(CustomCertificateEntity entity) {
CustomCertificateModel customCertificateModel = new CustomCertificateModel(entity.getAlias(), entity.getCertificateContent(), DateUtils.formatDate(entity.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE));
customCertificateModel.setId(entity.getId());
return customCertificateModel;
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessorTest method storeCertificateIdDoesNotExistTest.
@Test
public void storeCertificateIdDoesNotExistTest() {
CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository();
DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
try {
CustomCertificateModel certificateModel = new CustomCertificateModel(9L, alias, content, testDate.toString());
customCertificateAccessor.storeCertificate(certificateModel);
fail();
} catch (AlertConfigurationException e) {
assertNotNull(e);
}
}
use of com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessorTest method getCertificatesTest.
@Test
public void getCertificatesTest() {
CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository(alias, content, testDate);
DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
List<CustomCertificateModel> customCertificateModelList = customCertificateAccessor.getCertificates();
assertEquals(1, customCertificateModelList.size());
CustomCertificateModel customCertificateModel = customCertificateModelList.get(0);
testCustomCertificateModel(expectedCustomCertificateModel, customCertificateModel);
}
Aggregations