Search in sources :

Example 6 with PermissionMatrixModel

use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testDeleteForbidden.

@Test
public void testDeleteForbidden() {
    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));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.delete(() -> true, () -> {
    });
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 7 with PermissionMatrixModel

use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testGetOneHasContent.

@Test
public void testGetOneHasContent() {
    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, 255);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.getOne(() -> createOptionalDefault());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
    assertTrue(response.hasContent());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 8 with PermissionMatrixModel

use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testDeleteSuccess.

@Test
public void testDeleteSuccess() {
    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));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.delete(() -> true, () -> {
    });
    assertEquals(HttpStatus.NO_CONTENT, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 9 with PermissionMatrixModel

use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testUpdateSuccess.

@Test
public void testUpdateSuccess() {
    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));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.update(() -> ValidationResponseModel.success(), () -> true, () -> createDefault());
    assertEquals(HttpStatus.OK, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Example 10 with PermissionMatrixModel

use of com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel in project hub-alert by blackducksoftware.

the class ConfigurationCrudHelperTest method testGetOneForbidden.

@Test
public void testGetOneForbidden() {
    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, 0);
    AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
    ConfigurationCrudHelper configurationHelper = new ConfigurationCrudHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
    ActionResponse response = configurationHelper.getOne(() -> createOptionalDefault());
    assertEquals(HttpStatus.FORBIDDEN, response.getHttpStatus());
}
Also used : PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) ChannelKey(com.synopsys.integration.alert.descriptor.api.model.ChannelKey) AuthenticationTestUtils(com.synopsys.integration.alert.test.common.AuthenticationTestUtils) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) Test(org.junit.jupiter.api.Test)

Aggregations

PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)53 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)48 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)43 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)41 Test (org.junit.jupiter.api.Test)38 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)35 ChannelKey (com.synopsys.integration.alert.descriptor.api.model.ChannelKey)23 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)17 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)12 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)12 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)10 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)10 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 UserRoleModel (com.synopsys.integration.alert.common.persistence.model.UserRoleModel)4 PermissionMatrixRelation (com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation)4 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)4 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)3 HashMap (java.util.HashMap)3