use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class SettingsProxyConfigAccessor method createConfiguration.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public SettingsProxyModel createConfiguration(SettingsProxyModel configuration) throws AlertConfigurationException {
if (doesConfigurationExist()) {
throw new AlertConfigurationException("A proxy config already exists.");
}
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
UUID configurationId = UUID.randomUUID();
configuration.setId(configurationId.toString());
SettingsProxyConfigurationEntity configurationToSave = toEntity(configurationId, configuration, currentTime, currentTime);
SettingsProxyConfigurationEntity savedProxyConfig = settingsProxyConfigurationRepository.save(configurationToSave);
List<NonProxyHostConfigurationEntity> nonProxyHosts = toNonProxyHostEntityList(configurationId, configuration);
nonProxyHostsConfigurationRepository.saveAll(nonProxyHosts);
savedProxyConfig = settingsProxyConfigurationRepository.getOne(savedProxyConfig.getConfigurationId());
return createConfigModel(savedProxyConfig);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultUserAccessor method addUser.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public UserModel addUser(UserModel user, boolean passwordEncoded) throws AlertConfigurationException {
String username = user.getName();
Optional<UserEntity> userWithSameUsername = userRepository.findByUserName(username);
if (userWithSameUsername.isPresent()) {
throw new AlertConfigurationException(String.format("A user with username '%s' is already present", username));
}
String password = passwordEncoded ? user.getPassword() : defaultPasswordEncoder.encode(user.getPassword());
AuthenticationTypeDetails authenticationType = authenticationTypeAccessor.getAuthenticationTypeDetails(user.getAuthenticationType()).orElseThrow(() -> new AlertRuntimeException("Cannot find Authentication Type."));
UserEntity newEntity = new UserEntity(username, password, user.getEmailAddress(), authenticationType.getId());
UserEntity savedEntity = userRepository.save(newEntity);
UserModel model = createModel(savedEntity);
roleAccessor.updateUserRoles(model.getId(), user.getRoles());
return model;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessorTest method storeCertificateIdDoesNotExistTest.
@Test
public void storeCertificateIdDoesNotExistTest() {
CustomCertificateRepository customCertificateRepository = new MockCustomCertificateRepository();
DefaultCustomCertificateAccessor customCertificateAccessor = new DefaultCustomCertificateAccessor(customCertificateRepository);
try {
CustomCertificateModel certificateModel = new CustomCertificateModel(9L, alias, content, testDate.toString());
customCertificateAccessor.storeCertificate(certificateModel);
fail();
} catch (AlertConfigurationException e) {
assertNotNull(e);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class UserActionsTest method testCreateWithoutChecksDatabaseError.
@Test
public void testCreateWithoutChecksDatabaseError() throws Exception {
Mockito.when(userAccessor.addUser(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenThrow(new AlertConfigurationException("Exception for test"));
Set<String> roleNames = roles.stream().map(UserRoleModel::getName).collect(Collectors.toSet());
UserConfig userConfig = new UserConfig(id.toString(), name, "newPassword", emailAddress, roleNames, false, false, false, true, false, authenticationType.name(), false);
UserActions userActions = new UserActions(userManagementDescriptorKey, userAccessor, roleAccessor, authorizationManager, authenticationTypeAccessor, userSystemValidator);
ActionResponse<UserConfig> userConfigActionResponse = userActions.createWithoutChecks(userConfig);
assertTrue(userConfigActionResponse.isError());
assertFalse(userConfigActionResponse.hasContent());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, userConfigActionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCacheTest method invalidConfigurationTest.
@Test
public void invalidConfigurationTest() {
ConfigurationModel configurationModel = new ConfigurationModel(1L, 2L, "createdAt", "lastUpdated", ConfigContextEnum.GLOBAL, Map.of());
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(Mockito.eq(blackDuckConfigId))).thenReturn(Optional.of(configurationModel));
try {
cache.retrieveBlackDuckServicesFactory(blackDuckConfigId);
fail("Expected AlertConfigurationException to be thrown due to missing configuredFields in the ConfigurationModel.");
} catch (AlertConfigurationException e) {
// Pass
}
}
Aggregations