Search in sources :

Example 1 with AlertConfigurationException

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());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) OffsetDateTime(java.time.OffsetDateTime) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AlertConfigurationException

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);
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 3 with AlertConfigurationException

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;
}
Also used : BindAuthenticator(org.springframework.security.ldap.authentication.BindAuthenticator) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 4 with AlertConfigurationException

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.
        }
    }
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertForbiddenOperationException(com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)

Example 5 with AlertConfigurationException

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);
}
Also used : NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) OffsetDateTime(java.time.OffsetDateTime) UUID(java.util.UUID) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) 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