use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class CertificateActions method createWithoutChecks.
@Override
protected ActionResponse<CertificateModel> createWithoutChecks(CertificateModel resource) {
String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
logger.info("Importing certificate with alias {}", loggableAlias);
try {
CertificateModel certificateModel = importCertificate(resource);
return new ActionResponse<>(HttpStatus.CREATED, certificateModel);
} catch (AlertException ex) {
String message = ex.getMessage();
logger.error("There was an issue importing the certificate. {}", message);
logger.debug(message, ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("There was an issue importing the certificate. %s", message));
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException 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.api.common.model.exception.AlertException 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.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessorTest method setAuditEntryFailureTest.
@Test
public void setAuditEntryFailureTest() {
String testErrorMessage = "Uh oh, an error occurred!";
String testExceptionMessage = "Something bad happened. Yikes...";
Throwable testThrowable = new AlertException(testExceptionMessage);
AuditEntryEntity testResultEntry = setAuditEntryStatusTest(AuditEntryStatus.FAILURE, (accessor, jobId, notificationIds) -> accessor.setAuditEntryFailure(jobId, notificationIds, testErrorMessage, testThrowable));
assertEquals(testErrorMessage, testResultEntry.getErrorMessage());
assertNotNull(testResultEntry.getErrorStackTrace(), "Expected the audit entry to contain an error stack trace");
assertTrue(testResultEntry.getErrorStackTrace().contains(testExceptionMessage), "Expected the error stack trace to contain a specific message, but that message was missing");
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class CertificateActionsTestIT method createExceptionTest.
@Test
public void createExceptionTest() throws Exception {
String certificateContent = certTestUtil.readCertificateContents();
CertificateModel certificate = new CertificateModel(TEST_ALIAS, certificateContent, DateUtils.createCurrentDateString(DateUtils.UTC_DATE_FORMAT_TO_MINUTE));
AlertTrustStoreManager trustStoreService = Mockito.mock(AlertTrustStoreManager.class);
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasCreatePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
Mockito.doThrow(new AlertException("Test exception")).when(trustStoreService).importCertificate(Mockito.any(CustomCertificateModel.class));
CertificateActions certificateActions = new CertificateActions(new CertificatesDescriptorKey(), authorizationManager, certificateAccessor, trustStoreService);
ActionResponse<CertificateModel> response = certificateActions.create(certificate);
assertTrue(response.isError());
assertTrue(certificateAccessor.getCertificates().isEmpty());
}
Aggregations