use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class EmailConfigActionTestIT method updatePasswordEmailGlobalConfigTest.
@Test
void updatePasswordEmailGlobalConfigTest() throws AlertConfigurationException {
AuthorizationManager authorizationManager = createEmailAuthorizationManager();
EmailGlobalCrudActions emailGlobalCrudActions = createEmailCrudActions(authorizationManager);
GlobalConfigurationModelToConcreteConversionService globalConfigurationModelToConcreteConversionService = createConversionService(emailGlobalCrudActions);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, globalConfigurationModelToConcreteConversionService);
FieldModel fieldModel = createEmailFieldModel();
fieldModel = configActions.create(fieldModel).getContent().orElseThrow(() -> new AlertConfigurationException("Couldn't create configuration"));
String updatedHost = "updated." + TEST_SMTP_HOST;
String updatedPassword = "updatedPassword";
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedHost), false));
fieldModel.putField(EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), new FieldValueModel(List.of(updatedPassword), false));
configActions.update(Long.valueOf(fieldModel.getId()), fieldModel);
Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
assertTrue(staticEmailConfig.isPresent());
EmailGlobalConfigModel staticModel = staticEmailConfig.get();
assertEquals(Boolean.TRUE, staticModel.getSmtpAuth().orElse(null));
assertEquals(TEST_AUTH_USER, staticModel.getSmtpUsername().orElse(null));
assertEquals(updatedPassword, staticModel.getSmtpPassword().orElse(null));
assertEquals(updatedHost, staticModel.getSmtpHost().orElse(null));
assertEquals(Integer.valueOf(TEST_SMTP_PORT), staticModel.getSmtpPort().orElse(null));
assertEquals(TEST_FROM, staticModel.getSmtpFrom().orElse(null));
String propertyValue = staticModel.getAdditionalJavaMailProperties().map(map -> map.get(EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey())).orElse(null);
assertEquals("true", propertyValue);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultCustomCertificateAccessor method storeCertificate.
@Override
public CustomCertificateModel storeCertificate(CustomCertificateModel certificateModel) throws AlertConfigurationException {
String alias = certificateModel.getAlias();
String certificateContent = certificateModel.getCertificateContent();
CustomCertificateEntity entityToSave = new CustomCertificateEntity(alias, certificateContent, DateUtils.createCurrentDateTimestamp());
Long id = certificateModel.getNullableId();
if (null == id) {
// Mimic keystore functionality
id = customCertificateRepository.findByAlias(alias).map(CustomCertificateEntity::getId).orElse(null);
} else if (!customCertificateRepository.existsById(id)) {
throw new AlertConfigurationException("A custom certificate with that id did not exist");
}
entityToSave.setId(id);
CustomCertificateEntity updatedEntity = customCertificateRepository.save(entityToSave);
return createModel(updatedEntity);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultRoleAccessor method updatePermissionsForRole.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix) throws AlertConfigurationException {
RoleEntity roleEntity = roleRepository.findByRoleName(roleName).orElseThrow(() -> new AlertConfigurationException("No role exists with name: " + roleName));
List<PermissionMatrixRelation> permissions = updateRoleOperations(roleEntity, permissionMatrix);
return createModelFromPermission(permissions);
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method updateUserNonDatabaseAuthInvalidTest.
@Test
public void updateUserNonDatabaseAuthInvalidTest() throws Exception {
final String roleName = "roleName";
AuthenticationType authenticationType = AuthenticationType.LDAP;
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
UserEntity existingUserEntity = new UserEntity("usernam-teste", "existing-password", "old-email.noreply@blackducksoftware.com", 2L);
existingUserEntity.setId(1L);
UserRoleModel roles = createUserRoleModel(1L, roleName, true);
UserModel userModel = UserModel.existingUser(1L, username, password, emailAddress, authenticationType, Set.of(roles), true);
UserRoleRelation userRoleRelation = new UserRoleRelation(1L, 2L);
UserRoleModel userRoleModel = createUserRoleModel(1L, roleName, true);
Mockito.when(userRepository.findById(Mockito.any())).thenReturn(Optional.of(existingUserEntity));
Mockito.when(authenticationTypeAccessor.getAuthenticationType(Mockito.any())).thenReturn(Optional.of(authenticationType));
Mockito.when(userRepository.save(Mockito.any())).thenReturn(existingUserEntity);
createModelMocks(userRoleRelation, userRoleModel, authenticationType);
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
try {
defaultUserAccessor.updateUser(userModel, false);
fail("External user with ? did not throw expected " + AlertForbiddenOperationException.class.getSimpleName());
} catch (AlertForbiddenOperationException e) {
assertNotNull(e);
} catch (AlertConfigurationException wrongException) {
fail("Wrong exception thrown");
}
}
use of com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException in project hub-alert by blackducksoftware.
the class DefaultUserAccessorTest method addUserExistsTest.
@Test
public void addUserExistsTest() throws Exception {
UserEntity userEntity = new UserEntity(username, password, emailAddress, 2L);
userEntity.setId(1L);
Mockito.when(userRepository.findByUserName(Mockito.any())).thenReturn(Optional.of(userEntity));
DefaultUserAccessor defaultUserAccessor = new DefaultUserAccessor(userRepository, userRoleRepository, defaultPasswordEncoder, roleAccessor, authenticationTypeAccessor);
try {
defaultUserAccessor.addUser(username, password, emailAddress);
fail("User with the same name that already exists in the userRepository did not throw expected " + AlertConfigurationException.class.getSimpleName());
} catch (AlertConfigurationException e) {
assertNotNull(e);
}
}
Aggregations