Search in sources :

Example 41 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey in project hub-alert by blackducksoftware.

the class ConfigurationValidationHelperTest method testValidationWithError.

@Test
public void testValidationWithError() {
    AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
    DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
    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));
    ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.generalError("generalError"));
    ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) 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 42 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey in project hub-alert by blackducksoftware.

the class EmailConfigActionTestIT method createEmailAuthorizationManager.

private AuthorizationManager createEmailAuthorizationManager() {
    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);
    return authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
Also used : 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) SettingsDescriptorKey(com.synopsys.integration.alert.component.settings.descriptor.SettingsDescriptorKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)

Example 43 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey in project hub-alert by blackducksoftware.

the class JobConfigActions method validateJobsById.

public ActionResponse<List<JobFieldStatuses>> validateJobsById(JobIdsRequestModel jobIdsValidationModel) {
    List<PermissionKey> keys = gatherPermissionKeys();
    if (!getAuthorizationManager().anyReadPermission(keys)) {
        return ActionResponse.createForbiddenResponse();
    }
    List<UUID> jobIdsToValidate = jobIdsValidationModel.getJobIds();
    if (null == jobIdsToValidate || jobIdsToValidate.isEmpty()) {
        return new ActionResponse<>(HttpStatus.OK, List.of());
    }
    List<DistributionJobModel> distributionJobModels = jobAccessor.getJobsById(jobIdsToValidate);
    List<JobFieldModel> jobFieldModels = new LinkedList<>();
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    return validateJobFieldModels(jobFieldModels);
}
Also used : PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) UUID(java.util.UUID) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) LinkedList(java.util.LinkedList) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Example 44 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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 45 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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

PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)56 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)49 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)43 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)42 Test (org.junit.jupiter.api.Test)38 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)35 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)16 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)12 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)10 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)9 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 PermissionMatrixRelation (com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation)5 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)5 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)3 Map (java.util.Map)3