Search in sources :

Example 6 with PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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 PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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 PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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 PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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 PermissionKey

use of com.synopsys.integration.alert.common.persistence.model.PermissionKey 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

PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)56 PermissionMatrixModel (com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel)49 AuthenticationTestUtils (com.synopsys.integration.alert.test.common.AuthenticationTestUtils)43 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)42 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)16 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)9 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)6 PermissionMatrixRelation (com.synopsys.integration.alert.database.authorization.PermissionMatrixRelation)5 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)5 RegisteredDescriptorEntity (com.synopsys.integration.alert.database.configuration.RegisteredDescriptorEntity)5 HashMap (java.util.HashMap)4 UUID (java.util.UUID)4 RoleEntity (com.synopsys.integration.alert.database.user.RoleEntity)3 Map (java.util.Map)3