Search in sources :

Example 46 with AlertConfigurationException

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

the class BomEditNotificationDetailExtractorTest method extractDetailedContentErrorTest.

@Test
public void extractDetailedContentErrorTest() throws IOException, IntegrationException {
    Long blackDuckConfigId = 0L;
    String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
    BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
    NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    Mockito.doThrow(new AlertConfigurationException("Expected Exception thrown creating BlackDuckServicesFactory")).when(cache).retrieveBlackDuckServicesFactory(Mockito.anyLong());
    BomEditNotificationDetailExtractor extractor = new BomEditNotificationDetailExtractor(cache);
    AlertNotificationModel notification = new AlertNotificationModel(0L, blackDuckConfigId, "BlackDuck", "Config 1", null, null, null, null, false);
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(0, detailedNotificationContents.size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) BomEditNotificationView(com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 47 with AlertConfigurationException

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

the class DefaultConfigurationModelConfigurationAccessor method updateConfiguration.

/**
 * @return the config after update
 */
@Override
public ConfigurationModel updateConfiguration(Long descriptorConfigId, Collection<ConfigurationFieldModel> configuredFields) throws AlertConfigurationException {
    DescriptorConfigEntity descriptorConfigEntity = descriptorConfigsRepository.findById(descriptorConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("Config with id '%d' did not exist", descriptorConfigId)));
    List<FieldValueEntity> oldValues = fieldValueRepository.findByConfigId(descriptorConfigId);
    fieldValueRepository.deleteAll(oldValues);
    fieldValueRepository.flush();
    ConfigurationModelMutable updatedConfig = createEmptyConfigModel(descriptorConfigEntity.getDescriptorId(), descriptorConfigEntity.getId(), descriptorConfigEntity.getCreatedAt(), descriptorConfigEntity.getLastUpdated(), descriptorConfigEntity.getContextId());
    if (configuredFields != null && !configuredFields.isEmpty()) {
        List<FieldValueEntity> fieldValuesToSave = new ArrayList<>(configuredFields.size());
        for (ConfigurationFieldModel configFieldModel : configuredFields) {
            String fieldKey = configFieldModel.getFieldKey();
            Long fieldId = getFieldIdOrThrowException(fieldKey);
            boolean isSensitive = isFieldSensitive(fieldKey);
            for (String value : configFieldModel.getFieldValues()) {
                FieldValueEntity newFieldValue = new FieldValueEntity(descriptorConfigId, fieldId, encrypt(value, isSensitive));
                fieldValuesToSave.add(newFieldValue);
            }
            updatedConfig.put(configFieldModel);
        }
        fieldValueRepository.saveAll(fieldValuesToSave);
        fieldValueRepository.flush();
    }
    descriptorConfigEntity.setLastUpdated(DateUtils.createCurrentDateTimestamp());
    descriptorConfigsRepository.save(descriptorConfigEntity);
    return updatedConfig;
}
Also used : ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) DescriptorConfigEntity(com.synopsys.integration.alert.database.configuration.DescriptorConfigEntity) ArrayList(java.util.ArrayList) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) FieldValueEntity(com.synopsys.integration.alert.database.configuration.FieldValueEntity)

Example 48 with AlertConfigurationException

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

the class LdapAuthenticationPerformer method authenticateWithProvider.

@Override
public Authentication authenticateWithProvider(Authentication pendingAuthentication) {
    logger.info("Checking ldap based authentication...");
    Authentication result = pendingAuthentication;
    if (ldapManager.isLdapEnabled()) {
        logger.info("LDAP authentication enabled");
        try {
            Optional<LdapAuthenticationProvider> authenticationProvider = ldapManager.getAuthenticationProvider();
            if (authenticationProvider.isPresent()) {
                result = authenticationProvider.get().authenticate(pendingAuthentication);
            }
        } catch (AlertConfigurationException ex) {
            logger.error("LDAP Configuration error", ex);
        } catch (Exception ex) {
            logger.error("LDAP Authentication error", ex);
        }
    } else {
        logger.info("LDAP authentication disabled");
    }
    return result;
}
Also used : Authentication(org.springframework.security.core.Authentication) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 49 with AlertConfigurationException

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

the class LdapManager method createAuthProvider.

public Optional<LdapAuthenticationProvider> createAuthProvider(FieldUtility configuration) throws AlertConfigurationException {
    try {
        boolean enabled = configuration.getBooleanOrFalse(AuthenticationDescriptor.KEY_LDAP_ENABLED);
        if (!enabled) {
            return Optional.empty();
        }
        LdapContextSource ldapContextSource = new LdapContextSource();
        String ldapServer = configuration.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_SERVER);
        String managerDN = configuration.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_MANAGER_DN);
        String managerPassword = configuration.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_MANAGER_PWD);
        String ldapReferral = configuration.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_REFERRAL);
        if (StringUtils.isNotBlank(ldapServer)) {
            ldapContextSource.setUrl(ldapServer);
            ldapContextSource.setUserDn(managerDN);
            ldapContextSource.setPassword(managerPassword);
            ldapContextSource.setReferral(ldapReferral);
            ldapContextSource.setAuthenticationStrategy(createAuthenticationStrategy(configuration));
        }
        ldapContextSource.afterPropertiesSet();
        LdapAuthenticationProvider ldapAuthenticationProvider = updateAuthenticationProvider(configuration, ldapContextSource);
        return Optional.of(ldapAuthenticationProvider);
    } catch (IllegalArgumentException ex) {
        throw new AlertConfigurationException("Error creating LDAP Context Source", ex);
    }
}
Also used : LdapContextSource(org.springframework.ldap.core.support.LdapContextSource) LdapAuthenticationProvider(org.springframework.security.ldap.authentication.LdapAuthenticationProvider) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 50 with AlertConfigurationException

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

the class AlertTrustStoreManager method getAndValidateTrustStoreFile.

public synchronized File getAndValidateTrustStoreFile() throws AlertConfigurationException {
    logger.debug("Get and validate trust store.");
    Optional<String> optionalTrustStoreFileName = alertProperties.getTrustStoreFile();
    if (optionalTrustStoreFileName.isPresent()) {
        String trustStoreFileName = optionalTrustStoreFileName.get();
        File trustStoreFile;
        try {
            URI trustStoreUri = new URI(trustStoreFileName);
            trustStoreFile = new File(trustStoreUri);
        } catch (IllegalArgumentException | URISyntaxException ex) {
            logger.debug("Error getting Java trust store from file URI", ex);
            trustStoreFile = new File(trustStoreFileName);
        }
        if (!trustStoreFile.isFile()) {
            throw new AlertConfigurationException("The trust store provided is not a file: " + trustStoreFileName);
        }
        if (!trustStoreFile.canWrite()) {
            throw new AlertConfigurationException("The trust store provided cannot be written by Alert: " + trustStoreFileName);
        }
        return trustStoreFile;
    } else {
        throw new AlertConfigurationException("No trust store file has been provided.");
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

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