Search in sources :

Example 1 with IntegrationException

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);
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) AlertFieldException(com.synopsys.integration.alert.common.exception.AlertFieldException) IntegrationException(com.synopsys.integration.exception.IntegrationException)

Example 2 with IntegrationException

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.
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) IntegrationException(com.synopsys.integration.exception.IntegrationException) DescriptorMocker(com.synopsys.integration.alert.util.DescriptorMocker) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FrequencyType(com.synopsys.integration.alert.common.enumeration.FrequencyType) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) Disabled(org.junit.jupiter.api.Disabled) StringUtils(org.apache.commons.lang3.StringUtils) TestTags(com.synopsys.integration.alert.test.common.TestTags) HttpUrl(com.synopsys.integration.rest.HttpUrl) BeforeAll(org.junit.jupiter.api.BeforeAll) Gson(com.google.gson.Gson) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) TestPropertyKey(com.synopsys.integration.alert.test.common.TestPropertyKey) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) WebAppConfiguration(org.springframework.test.context.web.WebAppConfiguration) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) Predicate(java.util.function.Predicate) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) IntegrationPerformanceTestRunner(com.synopsys.integration.alert.performance.utility.IntegrationPerformanceTestRunner) ApplicationConfiguration(com.synopsys.integration.alert.configuration.ApplicationConfiguration) NotificationType(com.synopsys.integration.blackduck.api.manual.enumeration.NotificationType) ZoneId(java.time.ZoneId) WaitJob(com.synopsys.integration.wait.WaitJob) Test(org.junit.jupiter.api.Test) SlackDescriptor(com.synopsys.integration.alert.channel.slack.descriptor.SlackDescriptor) List(java.util.List) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) DatabaseDataSource(com.synopsys.integration.alert.database.DatabaseDataSource) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) TestProperties(com.synopsys.integration.alert.test.common.TestProperties) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) Forge(com.synopsys.integration.bdio.model.Forge) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) IntLogger(com.synopsys.integration.log.IntLogger) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ConfigurationManager(com.synopsys.integration.alert.performance.utility.ConfigurationManager) ChannelDescriptor(com.synopsys.integration.alert.common.descriptor.ChannelDescriptor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) Application(com.synopsys.integration.alert.Application) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) Ignore(org.junit.Ignore) ContextConfiguration(org.springframework.test.context.ContextConfiguration) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) BlackDuckResponseResolver(com.synopsys.integration.blackduck.http.transform.subclass.BlackDuckResponseResolver) AlertRequestUtility(com.synopsys.integration.alert.performance.utility.AlertRequestUtility) BlackDuckProviderService(com.synopsys.integration.alert.performance.utility.BlackDuckProviderService) ExternalId(com.synopsys.integration.bdio.model.externalid.ExternalId) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) WaitJobConfig(com.synopsys.integration.wait.WaitJobConfig) ComponentUnknownVersionNotificationView(com.synopsys.integration.blackduck.api.manual.view.ComponentUnknownVersionNotificationView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Ignore(org.junit.Ignore) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Example 3 with IntegrationException

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;
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntegrationException(com.synopsys.integration.exception.IntegrationException) Request(com.synopsys.integration.rest.request.Request) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 4 with IntegrationException

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)));
}
Also used : ProjectComponent(com.synopsys.integration.jira.common.model.components.ProjectComponent) IntegrationException(com.synopsys.integration.exception.IntegrationException) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 5 with IntegrationException

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);
    }
}
Also used : StringWriter(java.io.StringWriter) IntegrationException(com.synopsys.integration.exception.IntegrationException) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException)

Aggregations

IntegrationException (com.synopsys.integration.exception.IntegrationException)53 HttpUrl (com.synopsys.integration.rest.HttpUrl)19 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)13 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)12 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)11 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)10 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)9 ArrayList (java.util.ArrayList)9 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)8 Slf4jIntLogger (com.synopsys.integration.log.Slf4jIntLogger)8 Set (java.util.Set)8 Test (org.junit.jupiter.api.Test)8 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)7 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)7 List (java.util.List)7 Optional (java.util.Optional)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)6 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)6 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)6