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());
}
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));
}
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);
}
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());
}
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());
}
Aggregations