Search in sources :

Example 16 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.

private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
    Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
    if (optionalProperties.isPresent()) {
        BlackDuckProperties blackDuckProperties = optionalProperties.get();
        Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
        try {
            BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
            return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
        } catch (AlertException e) {
            throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
        }
    }
    throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 17 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class AbstractBlackDuckComponentConcernMessageExtractor method extract.

@Override
protected final ProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper, T notificationContent) {
    AlertNotificationModel notificationModel = notificationContentWrapper.getAlertNotificationModel();
    Long providerConfigId = notificationModel.getProviderConfigId();
    String providerUrl;
    List<BomComponentDetails> bomComponentDetails;
    try {
        BlackDuckServicesFactory blackDuckServicesFactory = servicesFactoryCache.retrieveBlackDuckServicesFactory(providerConfigId);
        providerUrl = blackDuckServicesFactory.getBlackDuckHttpClient().getBlackDuckUrl().string();
        bomComponentDetails = createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    } catch (AlertConfigurationException e) {
        logger.warn("Invalid BlackDuck configuration for notification. ID: {}. Name: {}", providerConfigId, notificationModel.getProviderConfigName(), e);
        return ProviderMessageHolder.empty();
    } catch (IntegrationException e) {
        logger.warn("Failed to retrieve BOM Component(s) from BlackDuck", e);
        return ProviderMessageHolder.empty();
    }
    LinkableItem providerItem = new LinkableItem(blackDuckProviderKey.getDisplayName(), notificationModel.getProviderConfigName(), providerUrl);
    ProviderDetails providerDetails = new ProviderDetails(notificationModel.getProviderConfigId(), providerItem);
    Optional<String> projectUrl = extractProjectUrl(notificationContent.getProjectVersionUrl());
    LinkableItem project = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT, notificationContent.getProjectName(), projectUrl.orElse(null));
    LinkableItem projectVersion = new LinkableItem(BlackDuckMessageLabels.LABEL_PROJECT_VERSION, notificationContent.getProjectVersionName(), notificationContent.getProjectVersionUrl());
    // FIXME this is where I should put the additional info
    ProjectMessage projectMessage = createProjectMessage(providerDetails, project, projectVersion, bomComponentDetails);
    return new ProviderMessageHolder(List.of(projectMessage), List.of());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) IntegrationException(com.synopsys.integration.exception.IntegrationException) ProviderDetails(com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 18 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class LdapManagerTest method testExceptionOnAuthenticator.

@Test
public void testExceptionOnAuthenticator() {
    final String userSearchBase = "";
    final String userSearchFilter = "";
    final String userDNPatterns = "";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_BASE).get().setFieldValue(userSearchBase);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_SEARCH_FILTER).get().setFieldValue(userSearchFilter);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS).get().setFieldValue(userDNPatterns);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    try {
        ldapManager.getAuthenticationProvider();
        fail();
    } catch (AlertConfigurationException ex) {
    // exception occurred
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 19 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class LdapManagerTest method testExceptionOnContext.

@Test
public void testExceptionOnContext() {
    final String managerDN = "";
    final String managerPassword = "";
    ConfigurationModel configurationModel = createConfigurationModel();
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_SERVER).get().setFieldValue(null);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN).get().setFieldValue(managerDN);
    configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD).get().setFieldValue(managerPassword);
    DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
    UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
    LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
    try {
        ldapManager.getAuthenticationProvider();
        fail();
    } catch (AlertConfigurationException ex) {
    // exception occurred
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) UserManagementAuthoritiesPopulator(com.synopsys.integration.alert.component.authentication.security.UserManagementAuthoritiesPopulator) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthenticationDescriptorKey(com.synopsys.integration.alert.component.authentication.descriptor.AuthenticationDescriptorKey) DefaultConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.database.api.DefaultConfigurationModelConfigurationAccessor) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 20 with AlertConfigurationException

use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.

the class JiraServerGlobalConfigAccessor method updateConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public JiraServerGlobalConfigModel updateConfiguration(UUID configurationId, JiraServerGlobalConfigModel configuration) throws AlertConfigurationException {
    JiraServerConfigurationEntity configurationEntity = jiraServerConfigurationRepository.findById(configurationId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%s' did not exist", configurationId.toString())));
    if (BooleanUtils.toBoolean(configuration.getIsPasswordSet().orElse(Boolean.FALSE)) && configuration.getPassword().isEmpty()) {
        String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getPassword());
        configuration.setPassword(decryptedPassword);
    }
    return populateConfiguration(configurationId, configuration, configurationEntity.getCreatedAt());
}
Also used : JiraServerConfigurationEntity(com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)54 Test (org.junit.jupiter.api.Test)20 Transactional (org.springframework.transaction.annotation.Transactional)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 UUID (java.util.UUID)8 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)5 Map (java.util.Map)5 JiraServerConfigurationEntity (com.synopsys.integration.alert.channel.jira.server.database.configuration.JiraServerConfigurationEntity)4 JiraServerGlobalConfigModel (com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel)4 AlertForbiddenOperationException (com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException)4 UserModel (com.synopsys.integration.alert.common.persistence.model.UserModel)4 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)4 HashMap (java.util.HashMap)4 EmailGlobalCrudActions (com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions)3 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)3 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)3 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 UserEntity (com.synopsys.integration.alert.database.user.UserEntity)3 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)3