Search in sources :

Example 81 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class DistributionActionsTest method createDistributionActions.

private DistributionActions createDistributionActions(Comparator<DistributionWithAuditInfo> sorter) {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(true);
    DistributionAccessor defaultDistributionAccessor = Mockito.mock(DistributionAccessor.class);
    Mockito.when(defaultDistributionAccessor.getDistributionWithAuditInfo(Mockito.anyInt(), Mockito.anyInt(), Mockito.anyString(), Mockito.any(), Mockito.anySet())).thenReturn(createDistributionInfo(sorter));
    DistributionActions distributionActions = new DistributionActions(defaultDistributionAccessor, authorizationManager, descriptorMap);
    return distributionActions;
}
Also used : DistributionAccessor(com.synopsys.integration.alert.common.persistence.accessor.DistributionAccessor) 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)

Example 82 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager in project hub-alert by blackducksoftware.

the class DescriptorMetadataActionsTest method createDescriptorController.

private DescriptorMetadataActions createDescriptorController() {
    AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
    Mockito.doReturn(true).when(authorizationManager).isReadOnly(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasPermissions(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasDeletePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasWritePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasCreatePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasExecutePermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class));
    Mockito.doReturn(true).when(authorizationManager).hasReadPermission(Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(true).when(authorizationManager).hasDeletePermission(Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(true).when(authorizationManager).hasWritePermission(Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(true).when(authorizationManager).hasCreatePermission(Mockito.anyString(), Mockito.anyString());
    Mockito.doReturn(true).when(authorizationManager).hasExecutePermission(Mockito.anyString(), Mockito.anyString());
    DescriptorMetadataActions actions = new DescriptorMetadataActions(descriptors, authorizationManager);
    return actions;
}
Also used : 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)

Example 83 with AuthorizationManager

use of com.synopsys.integration.alert.common.security.authorization.AuthorizationManager 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

AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)83 Test (org.junit.jupiter.api.Test)78 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)49 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)38 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)38 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)38 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)27 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)26 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)20 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)13 ConfigurationTestResult (com.synopsys.integration.alert.common.message.model.ConfigurationTestResult)12 EmailChannelMessagingService (com.synopsys.integration.alert.channel.email.distribution.EmailChannelMessagingService)9 JavamailPropertiesFactory (com.synopsys.integration.alert.service.email.JavamailPropertiesFactory)9 JiraServerGlobalConfigurationValidator (com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator)8 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)7