use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class AlertTrustStoreManager method importCertificate.
public synchronized void importCertificate(CustomCertificateModel customCertificate) throws AlertException {
logger.debug("Importing certificate into trust store.");
validateCustomCertificateHasValues(customCertificate);
File trustStoreFile = getAndValidateTrustStoreFile();
KeyStore trustStore = getAsKeyStore(trustStoreFile, getTrustStorePassword(), getTrustStoreType());
try {
Certificate cert = getAsJavaCertificate(customCertificate);
trustStore.setCertificateEntry(customCertificate.getAlias(), cert);
try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(trustStoreFile))) {
trustStore.store(stream, getTrustStorePassword());
}
} catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException e) {
throw new AlertException("There was a problem storing the certificate.", e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class MsTeamsChannelTest method sendMessageTestIT.
@Test
@Tag(TestTags.DEFAULT_INTEGRATION)
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendMessageTestIT() {
ChannelRestConnectionFactory connectionFactory = createConnectionFactory();
MarkupEncoderUtil markupEncoderUtil = new MarkupEncoderUtil();
MSTeamsChannelMessageConverter messageConverter = new MSTeamsChannelMessageConverter(new MSTeamsChannelMessageFormatter(markupEncoderUtil));
MSTeamsChannelMessageSender messageSender = new MSTeamsChannelMessageSender(ChannelKeys.MS_TEAMS, connectionFactory);
MSTeamsChannel msTeamsChannel = new MSTeamsChannel(messageConverter, messageSender);
MSTeamsJobDetailsModel msTeamsJobDetailsModel = new MSTeamsJobDetailsModel(UUID.randomUUID(), properties.getProperty(TestPropertyKey.TEST_MSTEAMS_WEBHOOK));
MessageResult messageResult = null;
try {
messageResult = msTeamsChannel.distributeMessages(msTeamsJobDetailsModel, TEST_MESSAGE_HOLDER, "jobName");
} catch (AlertException e) {
Assertions.fail("Failed to distribute simple channel message due to an exception", e);
}
Assertions.assertFalse(messageResult.hasErrors(), "The message result had errors");
Assertions.assertFalse(messageResult.hasWarnings(), "The message result had warnings");
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class ConfigurationOverridesStartupComponent method checkAndResetDefaultAdminPassword.
private void checkAndResetDefaultAdminPassword() throws AlertException {
boolean disable = isEnvironmentVariableActivated(ENV_VAR_ADMIN_USER_PASSWORD_RESET);
if (disable) {
UserModel userModel = userAccessor.getUser(UserAccessor.DEFAULT_ADMIN_USER_ID).orElseThrow(() -> new AlertException("The default admin user was not found."));
logger.info("Resetting the password for the user '{}'.", userModel.getName());
UserModel newModel = UserModel.existingUser(userModel.getId(), userModel.getName(), DEFAULT_ADMIN_PASSWORD, userModel.getEmailAddress(), userModel.getAuthenticationType(), userModel.getRoles(), userModel.isEnabled());
userAccessor.updateUser(newModel, true);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class BlackDuckSSOConfigRetrieverTest method retrieveExceptionTest.
@Test
public void retrieveExceptionTest() throws IntegrationException {
HttpUrl baseUrl = new HttpUrl("https://a-blackduck-server");
ApiDiscovery apiDiscovery = new ApiDiscovery(baseUrl);
BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(BlackDuckRequest.class))).thenThrow(new AlertException());
BlackDuckSSOConfigRetriever ssoConfigRetriever = new BlackDuckSSOConfigRetriever(apiDiscovery, blackDuckApiClient);
try {
ssoConfigRetriever.retrieve();
fail(String.format("Expected an %s to be thrown", AlertException.class.getSimpleName()));
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertException in project hub-alert by blackducksoftware.
the class EmailMessagingService method sendEmailMessage.
public void sendEmailMessage(Properties javamailProperties, String smtpFrom, String smtpHost, int smtpPort, boolean smtpAuth, String smtpUsername, String smtpPassword, EmailTarget emailTarget) throws AlertException {
try {
String templateName = StringUtils.trimToEmpty(emailTarget.getTemplateName());
Set<String> emailAddresses = emailTarget.getEmailAddresses().stream().map(String::trim).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
if (emailAddresses.isEmpty() || StringUtils.isBlank(templateName)) {
// Nothing to send
logger.debug("No non-blank email addresses were provided");
return;
}
Map<String, Object> model = emailTarget.getModel();
Session session = Session.getInstance(javamailProperties);
TemplateLoader templateLoader = freemarkerTemplatingService.createClassTemplateLoader("/templates/email");
Configuration templateDirectory = freemarkerTemplatingService.createFreemarkerConfig(templateLoader);
Template emailTemplate = templateDirectory.getTemplate(templateName);
String html = freemarkerTemplatingService.resolveTemplate(model, emailTemplate);
MimeMultipartBuilder mimeMultipartBuilder = new MimeMultipartBuilder();
mimeMultipartBuilder.addHtmlContent(html);
mimeMultipartBuilder.addTextContent(Jsoup.parse(html).text());
mimeMultipartBuilder.addEmbeddedImages(emailTarget.getContentIdsToFilePaths());
List<String> attachmentFilePaths = emailTarget.getAttachmentFilePaths();
if (!attachmentFilePaths.isEmpty()) {
mimeMultipartBuilder.addAttachments(attachmentFilePaths);
}
MimeMultipart mimeMultipart = mimeMultipartBuilder.build();
String subjectLine = (String) model.get(EmailPropertyKeys.TEMPLATE_KEY_SUBJECT_LINE.getPropertyKey());
if (StringUtils.isBlank(subjectLine)) {
subjectLine = "Default Subject Line - please define one";
}
Template subjectLineTemplate = new Template(EMAIL_SUBJECT_LINE_TEMPLATE, subjectLine, templateDirectory);
String resolvedSubjectLine = freemarkerTemplatingService.resolveTemplate(model, subjectLineTemplate);
List<Message> messages = createMessages(emailAddresses, resolvedSubjectLine, session, mimeMultipart, smtpFrom);
sendMessages(smtpAuth, smtpHost, smtpPort, smtpUsername, smtpPassword, session, messages);
} catch (MessagingException | IOException | IntegrationException ex) {
String errorMessage = "Could not send the email. " + ex.getMessage();
throw new AlertException(errorMessage, ex);
}
}
Aggregations