use of com.synopsys.integration.alert.common.enumeration.AccessOperation in project hub-alert by blackducksoftware.
the class DescriptorMetadataActions method createDescriptorMetadata.
private Optional<DescriptorMetadata> createDescriptorMetadata(DescriptorKey descriptorKey, ConfigContextEnum context, DescriptorType descriptorType) {
if (authorizationManager.hasPermissions(context, descriptorKey)) {
Set<AccessOperation> operations = gatherDescriptorContextOperations(context, descriptorKey);
boolean readOnly = authorizationManager.isReadOnly(context, descriptorKey);
DescriptorMetadata descriptorMetadata = new DescriptorMetadata(descriptorKey, descriptorType, context, operations, readOnly);
return Optional.of(descriptorMetadata);
}
return Optional.empty();
}
use of com.synopsys.integration.alert.common.enumeration.AccessOperation in project hub-alert by blackducksoftware.
the class DescriptorMetadataActionsTest method getDescriptorsWithoutPermissionTest.
@Test
public void getDescriptorsWithoutPermissionTest() {
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.doReturn(true).when(authorizationManager).hasPermissions(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
Mockito.doReturn(false).when(authorizationManager).hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
DescriptorMetadataActions actions = new DescriptorMetadataActions(descriptors, authorizationManager);
ActionResponse<DescriptorsResponseModel> response = actions.getDescriptorsByPermissions(null, null, null);
assertTrue(response.isSuccessful());
assertTrue(response.hasContent());
List<AccessOperation> allAccessOperations = response.getContent().stream().map(DescriptorsResponseModel::getDescriptors).flatMap(Set::stream).map(DescriptorMetadata::getOperations).flatMap(Set::stream).collect(Collectors.toList());
assertEquals(0, allAccessOperations.size());
}
Aggregations