use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class AuthenticationFieldModelTestAction method performLdapTest.
private void performLdapTest(FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
logger.info("LDAP enabled testing LDAP authentication.");
String userName = fieldModel.getFieldValue(AuthenticationDescriptor.TEST_FIELD_KEY_USERNAME).orElse("");
Optional<LdapAuthenticationProvider> ldapProvider = ldapManager.createAuthProvider(registeredFieldValues);
String errorMessage = String.format("Ldap Authentication test failed for the test user %s. Please check the LDAP configuration.", userName);
List<AlertFieldStatus> errors = new ArrayList<>();
if (!ldapProvider.isPresent()) {
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_LDAP_ENABLED, errorMessage));
} else {
try {
Authentication pendingAuthentication = new UsernamePasswordAuthenticationToken(userName, fieldModel.getFieldValue(AuthenticationDescriptor.TEST_FIELD_KEY_PASSWORD).orElse(""));
Authentication authentication = ldapProvider.get().authenticate(pendingAuthentication);
if (!authentication.isAuthenticated()) {
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_LDAP_ENABLED, errorMessage));
}
authentication.setAuthenticated(false);
} catch (Exception ex) {
logger.error("Exception occurred testing LDAP authentication", ex);
String exceptionMessage = ex.getMessage();
if (StringUtils.isNotBlank(exceptionMessage)) {
errorMessage = String.format("%s Additional details: %s", errorMessage, exceptionMessage);
}
errors.add(AlertFieldStatus.error(AuthenticationDescriptor.KEY_LDAP_ENABLED, errorMessage));
}
}
if (!errors.isEmpty()) {
throw new AlertFieldException(errors);
}
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class ComponentUnknownVersionNotificationSerializationTest method testNotificationSerialization.
@Test
@Ignore
@Disabled
public void testNotificationSerialization() throws IntegrationException, InterruptedException {
LocalDateTime searchStartTime = LocalDateTime.now().minusMinutes(1);
AlertRequestUtility alertRequestUtility = IntegrationPerformanceTestRunner.createAlertRequestUtility(webApplicationContext);
BlackDuckProviderService blackDuckProviderService = new BlackDuckProviderService(alertRequestUtility, gson);
configureJob(alertRequestUtility, blackDuckProviderService);
ExternalId externalId = new ExternalId(Forge.MAVEN);
externalId.setGroup("commons-fileupload");
externalId.setName("commons-fileupload");
Predicate<ProjectVersionComponentVersionView> componentFilter = (component) -> component.getComponentName().equals("Apache Commons FileUpload");
blackDuckProviderService.triggerBlackDuckNotification(() -> externalId, componentFilter);
try {
WaitJobConfig waitJobConfig = new WaitJobConfig(intLogger, "notification serialization test notification wait", 300, searchStartTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 20);
NotificationReceivedWaitJobTask notificationWaitJobTask = new NotificationReceivedWaitJobTask(notificationAccessor, searchStartTime, "Apache Commons FileUpload", null, NotificationType.COMPONENT_UNKNOWN_VERSION);
WaitJob<Boolean> waitForNotificationToBeProcessed = WaitJob.createSimpleWait(waitJobConfig, notificationWaitJobTask);
boolean isComplete = waitForNotificationToBeProcessed.waitFor();
if (isComplete) {
String notificationContent = notificationWaitJobTask.getNotificationContent().orElseThrow(() -> new IllegalStateException("Expected notification is missing."));
BlackDuckResponseResolver resolver = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckResponseResolver();
ComponentUnknownVersionNotificationView notificationView = resolver.resolve(notificationContent, ComponentUnknownVersionNotificationView.class);
assertNotNull(notificationView.getContent());
assertTrue(StringUtils.isNotBlank(notificationView.getContent().getComponentName()));
BlackDuckApiClient apiClient = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckApiClient();
Optional<HttpUrl> componentUrl = HttpUrl.createSafely(notificationView.getContent().getBomComponent());
if (componentUrl.isPresent()) {
apiClient.delete(componentUrl.get());
}
}
} catch (InterruptedException ex) {
// if a timeout happens that's ok we are trying to ensure deserialization is correct.
}
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class DockerTagRetriever method getTagResponseModel.
private DockerTagsResponseModel getTagResponseModel(String pageUrl) {
HttpUrl httpUrl;
try {
httpUrl = new HttpUrl(pageUrl);
} catch (IntegrationException e) {
logger.warn("Invalid url: " + pageUrl);
return DockerTagsResponseModel.EMPTY;
}
Request dockerTagsRequest = new Request.Builder(httpUrl).build();
try (Response tagsResponse = intHttpClient.execute(dockerTagsRequest)) {
tagsResponse.throwExceptionForError();
return gson.fromJson(tagsResponse.getContentString(), DockerTagsResponseModel.class);
} catch (IOException | IntegrationException e) {
logger.warn("Could not get docker tags from {}: {}", pageUrl, e.getMessage());
}
return DockerTagsResponseModel.EMPTY;
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class JiraServerIssueCreator method retrieveProjectComponent.
private ProjectComponent retrieveProjectComponent() throws AlertException {
String jiraProjectName = distributionDetails.getProjectNameOrKey();
List<ProjectComponent> foundProjectComponents;
try {
foundProjectComponents = projectService.getProjectsByName(jiraProjectName);
} catch (IntegrationException e) {
throw new AlertException("Failed to retrieve projects from Jira", e);
}
return foundProjectComponents.stream().findAny().orElseThrow(() -> new AlertException(String.format("Unable to find project matching '%s'", jiraProjectName)));
}
use of com.synopsys.integration.exception.IntegrationException in project hub-alert by blackducksoftware.
the class FreemarkerTemplatingService method resolveTemplate.
public String resolveTemplate(FreemarkerDataModel dataModel, Template template) throws IntegrationException {
try {
StringWriter stringWriter = new StringWriter();
template.process(dataModel, stringWriter);
return stringWriter.toString();
} catch (IOException | TemplateException e) {
throw new IntegrationException(e.getMessage(), e);
}
}
Aggregations