use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class StaticJobAccessor method updateJob.
@Override
@Transactional
public DistributionJobModel updateJob(UUID jobId, DistributionJobRequestModel requestModel) throws AlertConfigurationException {
DistributionJobEntity jobEntity = distributionJobRepository.findById(jobId).orElseThrow(() -> new AlertConfigurationException(String.format("No job exists with the id [%s]", jobId)));
OffsetDateTime createdAt = jobEntity.getCreatedAt();
if (!jobEntity.getChannelDescriptorName().equals(requestModel.getChannelDescriptorName())) {
// Deleting a Job will affect all tables with foreign keys referencing it.
// Only delete a job if the channel for which it is configured changes.
deleteJob(jobId);
}
return createJobWithId(jobId, requestModel, createdAt, DateUtils.createCurrentDateTimestamp());
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class ConfigurationCrudHelper method create.
public <T extends Obfuscated<T>> ActionResponse<T> create(Supplier<ValidationResponseModel> validator, BooleanSupplier existingModelSupplier, ThrowingSupplier<T, Exception> modelCreator) {
String actionName = "create";
logger.trace(ACTION_CALLED_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
if (!authorizationManager.hasCreatePermission(context, descriptorKey)) {
logger.trace(ACTION_MISSING_PERMISSIONS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return ActionResponse.createForbiddenResponse();
}
ValidationResponseModel validationResponse = validator.get();
if (validationResponse.hasErrors()) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponse.getMessage());
}
boolean configurationExists = existingModelSupplier.getAsBoolean();
if (configurationExists) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, "A configuration with this name already exists.");
}
try {
return new ActionResponse<>(HttpStatus.OK, modelCreator.get().obfuscate());
} catch (AlertConfigurationException ex) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Error creating config: %s", ex.getMessage()));
} catch (Exception ex) {
logger.error("Error creating config:", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
} finally {
logger.trace(ACTION_SUCCESS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class LdapManager method createAuthenticator.
private LdapAuthenticator createAuthenticator(FieldUtility configurationModel, LdapContextSource contextSource) throws AlertConfigurationException {
BindAuthenticator authenticator = new BindAuthenticator(contextSource);
try {
String[] userDnArray = createArrayFromCSV(configurationModel.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_USER_DN_PATTERNS));
String[] userAttributeArray = createArrayFromCSV(configurationModel.getStringOrEmpty(AuthenticationDescriptor.KEY_LDAP_USER_ATTRIBUTES));
authenticator.setUserSearch(createLdapUserSearch(configurationModel, contextSource));
authenticator.setUserDnPatterns(userDnArray);
authenticator.setUserAttributes(userAttributeArray);
authenticator.afterPropertiesSet();
} catch (Exception ex) {
throw new AlertConfigurationException("Error creating LDAP authenticator", ex);
}
return authenticator;
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class AuthenticationEventHandler method handle.
@Override
public void handle(AlertAuthenticationEvent event) {
UserModel user = event.getUser();
if (null != user) {
try {
Optional<UserModel> userModel = userAccessor.getUser(user.getName());
if (userModel.isPresent() && user.isExternal()) {
UserModel model = userModel.get();
UserModel updatedUser = UserModel.existingUser(model.getId(), user.getName(), user.getPassword(), user.getEmailAddress(), user.getAuthenticationType(), user.getRoles(), user.isEnabled());
userAccessor.updateUser(updatedUser, true);
} else {
userAccessor.addUser(user, true);
}
} catch (AlertForbiddenOperationException ignored) {
// Cannot update an external user's credentials
} catch (AlertConfigurationException ignored) {
// User already exists. Nothing to do.
}
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class SettingsProxyConfigAccessor method updateConfiguration.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public SettingsProxyModel updateConfiguration(SettingsProxyModel configuration) throws AlertConfigurationException {
SettingsProxyConfigurationEntity configurationEntity = settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException("Proxy config does not exist"));
if (BooleanUtils.toBoolean(configuration.getIsProxyPasswordSet()) && configuration.getProxyPassword().isEmpty()) {
String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getPassword());
configuration.setProxyPassword(decryptedPassword);
}
UUID configurationId = configurationEntity.getConfigurationId();
OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
SettingsProxyConfigurationEntity configurationToSave = toEntity(configurationId, configuration, configurationEntity.getCreatedAt(), currentTime);
SettingsProxyConfigurationEntity savedProxyConfig = settingsProxyConfigurationRepository.save(configurationToSave);
List<NonProxyHostConfigurationEntity> nonProxyHosts = toNonProxyHostEntityList(configurationId, configuration);
nonProxyHostsConfigurationRepository.saveAll(nonProxyHosts);
savedProxyConfig = settingsProxyConfigurationRepository.getOne(savedProxyConfig.getConfigurationId());
return createConfigModel(savedProxyConfig);
}
Aggregations