Search in sources :

Example 6 with AlertConfigurationException

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

Example 7 with AlertConfigurationException

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;
}
Also used : UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) AuthenticationTypeDetails(com.synopsys.integration.alert.common.persistence.model.AuthenticationTypeDetails) UserEntity(com.synopsys.integration.alert.database.user.UserEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with AlertConfigurationException

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);
    }
}
Also used : CustomCertificateRepository(com.synopsys.integration.alert.database.certificates.CustomCertificateRepository) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) CustomCertificateModel(com.synopsys.integration.alert.common.persistence.model.CustomCertificateModel) MockCustomCertificateRepository(com.synopsys.integration.alert.database.api.mock.MockCustomCertificateRepository) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 9 with AlertConfigurationException

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());
}
Also used : AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 10 with AlertConfigurationException

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
    }
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

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