use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testForbidden.
@Test
public void testForbidden() {
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.NO_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.success("Success"));
assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testValidationSuccess.
@Test
public void testValidationSuccess() {
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));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.success("Success"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class TestHelperConfigurationTest method testMessageWithErrors.
@Test
public void testMessageWithErrors() {
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));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.failure("Failure"));
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.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class AuthorizationManager method updatePermissionsForRole.
public PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix) throws AlertConfigurationException {
PermissionMatrixModel permissionMatrixModel = roleAccessor.updatePermissionsForRole(roleName, permissionMatrix);
updateRoleInCache(roleName, permissionMatrixModel);
return permissionMatrixModel;
}
use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.
the class DefaultRoleAccessorTest method updatePermissionsForRole.
@Test
public void updatePermissionsForRole() throws Exception {
final String roleName = "roleName";
final String contextString = "context-test";
final String descriptorName = "descriptorName";
RoleEntity roleEntity = new RoleEntity(roleName, true);
roleEntity.setId(1L);
ConfigContextEntity configContextEntity = new ConfigContextEntity(contextString);
configContextEntity.setId(1L);
RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L);
registeredDescriptorEntity.setId(1L);
PermissionKey permissionKey = new PermissionKey(contextString, descriptorName);
PermissionMatrixModel permissionMatrix = new PermissionMatrixModel(Map.of(permissionKey, AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit()));
PermissionMatrixRelation permissionMatrixRelation = new PermissionMatrixRelation(roleEntity.getId(), configContextEntity.getId(), registeredDescriptorEntity.getId(), AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit());
Mockito.when(roleRepository.findByRoleName(Mockito.any())).thenReturn(Optional.of(roleEntity));
mockUpdateRoleOperations(permissionMatrixRelation, configContextEntity, registeredDescriptorEntity);
mockCreateModelFromPermission(configContextEntity, registeredDescriptorEntity);
DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository);
PermissionMatrixModel permissionMatrixModel = authorizationUtility.updatePermissionsForRole(roleName, permissionMatrix);
Mockito.verify(permissionMatrixRepository).saveAll(Mockito.any());
assertFalse(permissionMatrixModel.isEmpty());
assertEquals(permissionMatrix, permissionMatrixModel);
}
Aggregations