use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method getEmailAddressesForNonExistentProjectHrefTest.
@Test
void getEmailAddressesForNonExistentProjectHrefTest() throws Exception {
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenThrow(new IntegrationException("Could not find the project."));
Long providerConfigId = providerConfiguration.getConfigurationId();
BlackDuckProviderDataAccessor providerDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
Set<String> foundEmailAddresses = providerDataAccessor.getEmailAddressesForProjectHref(providerConfigId, "expecting no results");
assertEquals(0, foundEmailAddresses.size());
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class BlackDuckApiTokenValidator method hasPermittedRole.
private boolean hasPermittedRole(BlackDuckServicesFactory blackDuckServicesFactory) {
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
UserView currentUser;
try {
currentUser = blackDuckApiClient.getResponse(apiDiscovery.metaCurrentUserLink());
} catch (IntegrationException integrationException) {
logger.error("Failed to GET the currently authenticated Black Duck user", integrationException);
return false;
}
try {
List<RoleAssignmentView> allRolesForCurrentUser = blackDuckApiClient.getAllResponses(currentUser.metaRolesLink());
return allRolesForCurrentUser.stream().anyMatch(this::isPermittedRole);
} catch (IntegrationException integrationException) {
logger.error("Failed to GET the currently authenticated Black Duck user's roles", integrationException);
}
return false;
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class JiraIssueCreator method createIssueAndExtractDetails.
@Override
protected final ExistingIssueDetails<String> createIssueAndExtractDetails(IssueCreationModel alertIssueCreationModel) throws AlertException {
MessageReplacementValues replacementValues = alertIssueCreationModel.getSource().map(this::createCustomFieldReplacementValues).orElse(new MessageReplacementValues.Builder(alertIssueCreationModel.getProvider().getLabel(), MessageReplacementValues.DEFAULT_NOTIFICATION_REPLACEMENT_VALUE).build());
T creationRequest = createIssueCreationRequest(alertIssueCreationModel, replacementValues);
try {
IssueCreationResponseModel issueCreationResponseModel = createIssue(creationRequest);
IssueResponseModel createdIssue = fetchIssue(issueCreationResponseModel.getKey());
IssueFieldsComponent createdIssueFields = createdIssue.getFields();
String issueUILink = JiraCallbackUtils.createUILink(createdIssue);
IssueCategory issueCategory = alertIssueCreationModel.getSource().map(issueCategoryRetriever::retrieveIssueCategoryFromProjectIssueModel).orElse(IssueCategory.BOM);
return new ExistingIssueDetails<>(createdIssue.getId(), createdIssue.getKey(), createdIssueFields.getSummary(), issueUILink, IssueStatus.RESOLVABLE, issueCategory);
} catch (IntegrationRestException restException) {
throw jiraErrorMessageUtility.improveRestException(restException, issueCreatorDescriptorKey, extractReporter(creationRequest));
} catch (JiraPreconditionNotMetException jiraException) {
String message = StringUtils.join(FAILED_TO_CREATE_ISSUE_MESSAGE, jiraException.getMessage(), " ");
throw new AlertException(message, jiraException);
} catch (IntegrationException intException) {
throw new AlertException(FAILED_TO_CREATE_ISSUE_MESSAGE, intException);
}
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class AuthenticationFieldModelTestAction method performSAMLTest.
private void performSAMLTest(FieldUtility registeredFieldValues) throws IntegrationException {
List<AlertFieldStatus> errors = new ArrayList<>();
Optional<String> registeredEntityId = registeredFieldValues.getString(AuthenticationDescriptor.KEY_SAML_ENTITY_ID);
if (registeredEntityId.isEmpty()) {
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_ENTITY_ID, "Entity ID missing."));
}
logger.info("Testing SAML Metadata URL...");
try {
Optional<ExtendedMetadataDelegate> provider = samlManager.createHttpProvider(registeredFieldValues.getStringOrEmpty(AuthenticationDescriptor.KEY_SAML_METADATA_URL));
if (provider.isPresent()) {
ExtendedMetadataDelegate extendedMetadataDelegate = provider.get();
extendedMetadataDelegate.initialize();
}
} catch (Exception ex) {
logger.error("Testing SAML Metadata URL error: ", ex);
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_METADATA_URL, ex.getMessage()));
}
logger.info("Testing SAML Metadata File...");
try {
Optional<ExtendedMetadataDelegate> provider = samlManager.createFileProvider();
if (provider.isPresent()) {
ExtendedMetadataDelegate extendedMetadataDelegate = provider.get();
extendedMetadataDelegate.initialize();
}
} catch (Exception ex) {
logger.error("Testing SAML Metadata File error: ", ex);
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_SAML_METADATA_FILE, ex.getMessage()));
}
samlManager.initializeConfiguration();
if (!errors.isEmpty()) {
throw new AlertFieldException(errors);
}
}
use of com.synopsys.integration.exception.IntegrationException 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