Search in sources :

Example 1 with AccessOperation

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();
}
Also used : AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)

Example 2 with AccessOperation

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());
}
Also used : AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Aggregations

DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)2 AccessOperation (com.synopsys.integration.alert.common.enumeration.AccessOperation)2 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)1 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)1 Test (org.junit.jupiter.api.Test)1