Search in sources :

Example 66 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailConfigActionTestIT method createEmailGlobalConfigTest.

@Test
void createEmailGlobalConfigTest() {
    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();
    configActions.create(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(TEST_AUTH_PASSWORD, staticModel.getSmtpPassword().orElse(null));
    assertEquals(TEST_SMTP_HOST, 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);
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) BeforeEach(org.junit.jupiter.api.BeforeEach) EmailGlobalConfigurationModelSaveActions(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelSaveActions) DescriptorAccessor(com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) PKIXErrorResponseFactory(com.synopsys.integration.alert.component.certificates.web.PKIXErrorResponseFactory) EmailPropertyKeys(com.synopsys.integration.alert.service.email.enumeration.EmailPropertyKeys) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) DescriptorMap(com.synopsys.integration.alert.common.descriptor.DescriptorMap) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) ConfigurationFieldModelConverter(com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) FieldModelProcessor(com.synopsys.integration.alert.common.rest.FieldModelProcessor) EmailGlobalConfigurationModelConverter(com.synopsys.integration.alert.channel.email.convert.EmailGlobalConfigurationModelConverter) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) Optional(java.util.Optional) EncryptionUtility(com.synopsys.integration.alert.common.security.EncryptionUtility) ChannelKeys(com.synopsys.integration.alert.descriptor.api.model.ChannelKeys) DescriptorProcessor(com.synopsys.integration.alert.common.descriptor.DescriptorProcessor) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) GlobalConfigurationModelToConcreteSaveActions(com.synopsys.integration.alert.common.action.api.GlobalConfigurationModelToConcreteSaveActions) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 67 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailConfigActionTestIT method deleteEmailGlobalConfigTest.

@Test
void deleteEmailGlobalConfigTest() 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"));
    configActions.delete(Long.valueOf(fieldModel.getId()));
    Optional<EmailGlobalConfigModel> staticEmailConfig = emailGlobalConfigAccessor.getConfiguration();
    assertTrue(staticEmailConfig.isEmpty());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailGlobalCrudActions(com.synopsys.integration.alert.channel.email.action.EmailGlobalCrudActions) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 68 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class ConfigActionTestIT method deleteSensitiveFieldFromConfig.

@Test
void deleteSensitiveFieldFromConfig() {
    GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(List.of(), descriptorMap);
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasDeletePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
    Mockito.when(authorizationManager.hasWritePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
    ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, conversionService);
    ConfigurationFieldModel proxyHost = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_HOST);
    proxyHost.setFieldValue("proxyHost");
    ConfigurationFieldModel proxyPort = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_PORT);
    proxyPort.setFieldValue("80");
    ConfigurationFieldModel proxyUsername = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_USERNAME);
    proxyUsername.setFieldValue("username");
    ConfigurationFieldModel proxyPassword = ConfigurationFieldModel.createSensitive(ProxyManager.KEY_PROXY_PWD);
    proxyPassword.setFieldValue("somestuff");
    ConfigurationFieldModel encryptionPassword = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_PWD);
    encryptionPassword.setFieldValue("pants");
    ConfigurationFieldModel encryptionSalt = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT);
    encryptionSalt.setFieldValue("salty pants");
    ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(settingsDescriptorKey, ConfigContextEnum.GLOBAL, Set.of(proxyHost, proxyPort, proxyUsername, proxyPassword, encryptionPassword, encryptionSalt));
    FieldValueModel proxyHostFieldValue = new FieldValueModel(Set.of("proxyHost"), true);
    FieldValueModel proxyPortFieldValue = new FieldValueModel(Set.of("80"), true);
    FieldValueModel proxyUsernameFieldValue = new FieldValueModel(Set.of(), false);
    FieldValueModel proxyPasswordFieldValue = new FieldValueModel(Set.of(), false);
    FieldValueModel encryptionPasswordFieldValue = new FieldValueModel(Set.of("encryptionPassword"), true);
    FieldValueModel encryptionSaltFieldValue = new FieldValueModel(Set.of("sodiumChloride"), true);
    Long longConfigId = configurationModel.getConfigurationId();
    String configId = String.valueOf(longConfigId);
    FieldModel fieldModel = new FieldModel(configId, settingsDescriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), new HashMap<>(Map.of(ProxyManager.KEY_PROXY_HOST, proxyHostFieldValue, ProxyManager.KEY_PROXY_PORT, proxyPortFieldValue, ProxyManager.KEY_PROXY_USERNAME, proxyUsernameFieldValue, ProxyManager.KEY_PROXY_PWD, proxyPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_PWD, encryptionPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT, encryptionSaltFieldValue)));
    ActionResponse<FieldModel> response = configActions.update(longConfigId, fieldModel);
    assertTrue(response.hasContent());
    FieldModel updatedConfig = response.getContent().orElseThrow(() -> new AssertionFailedError("content missing from response."));
    assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_USERNAME).isEmpty(), "Need to remove username in order to remove password as well.");
    assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_PWD).isEmpty(), "Saving an empty values should remove it from DB.");
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) GlobalConfigurationModelToConcreteConversionService(com.synopsys.integration.alert.web.api.config.GlobalConfigurationModelToConcreteConversionService) ConfigActions(com.synopsys.integration.alert.web.api.config.ConfigActions) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AssertionFailedError(junit.framework.AssertionFailedError) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 69 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalValidationActionTest method testValidationSuccess.

@Test
public void testValidationSuccess() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = ChannelKeys.EMAIL;
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setSmtpPassword("password");
    ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
    assertEquals(HttpStatus.OK, response.getHttpStatus());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 70 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class EmailGlobalValidationActionTest method testValidationForbidden.

@Test
public void testValidationForbidden() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = ChannelKeys.EMAIL;
    PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
    Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.NO_PERMISSIONS);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
    EmailGlobalValidationAction validationAction = new EmailGlobalValidationAction(validator, authorizationManager);
    EmailGlobalConfigModel model = new EmailGlobalConfigModel();
    model.setSmtpHost("host");
    model.setSmtpFrom("from");
    model.setSmtpAuth(true);
    model.setSmtpUsername("user");
    model.setSmtpPassword("password");
    ActionResponse<ValidationResponseModel> response = validationAction.validate(model);
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) EmailGlobalConfigurationValidator(com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)83 Test (org.junit.jupiter.api.Test)78 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)49 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)38 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)38 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)20 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)13 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)12 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)9 JiraServerGlobalConfigurationValidator (com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator)8 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)7