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());
}
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;
}
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;
}
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);
}
}
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.");
}
}
Aggregations