Search in sources :

Example 11 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class DescriptorMetadataActionsTest method getDescriptorsWithTypeAndContextTest.

@Test
public void getDescriptorsWithTypeAndContextTest() {
    DescriptorType type1 = DescriptorType.CHANNEL;
    ConfigContextEnum context1 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response1 = actions.getDescriptorsByPermissions(null, type1.name(), context1.name());
    int expectedSize = descriptors.size() / (DescriptorType.values().length);
    assertTrue(response1.isSuccessful());
    assertTrue(response1.hasContent());
    Set<DescriptorMetadata> descriptorMetadata1 = response1.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata1.size());
    DescriptorType type2 = DescriptorType.COMPONENT;
    ConfigContextEnum context2 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response2 = actions.getDescriptorsByPermissions(null, type2.name(), context2.name());
    assertTrue(response2.isSuccessful());
    assertTrue(response2.hasContent());
    Set<DescriptorMetadata> descriptorMetadata2 = response2.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata2.size());
    DescriptorType type3 = DescriptorType.PROVIDER;
    ConfigContextEnum context3 = ConfigContextEnum.GLOBAL;
    ActionResponse<DescriptorsResponseModel> response3 = actions.getDescriptorsByPermissions(null, type3.name(), context3.name());
    assertTrue(response3.isSuccessful());
    assertTrue(response3.hasContent());
    Set<DescriptorMetadata> descriptorMetadata3 = response3.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata3.size());
    DescriptorType type4 = DescriptorType.CHANNEL;
    ConfigContextEnum context4 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response4 = actions.getDescriptorsByPermissions(null, type4.name(), context4.name());
    assertTrue(response4.isSuccessful());
    assertTrue(response4.hasContent());
    Set<DescriptorMetadata> descriptorMetadata4 = response4.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata4.size());
    DescriptorType type5 = DescriptorType.COMPONENT;
    ConfigContextEnum context5 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response5 = actions.getDescriptorsByPermissions(null, type5.name(), context5.name());
    assertTrue(response5.isSuccessful());
    assertTrue(response5.hasContent());
    Set<DescriptorMetadata> descriptorMetadata5 = response5.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata5.size());
    DescriptorType type6 = DescriptorType.PROVIDER;
    ConfigContextEnum context6 = ConfigContextEnum.DISTRIBUTION;
    ActionResponse<DescriptorsResponseModel> response6 = actions.getDescriptorsByPermissions(null, type6.name(), context6.name());
    assertTrue(response6.isSuccessful());
    assertTrue(response6.hasContent());
    Set<DescriptorMetadata> descriptorMetadata6 = response6.getContent().get().getDescriptors();
    assertEquals(expectedSize, descriptorMetadata6.size());
}
Also used : DescriptorType(com.synopsys.integration.alert.common.enumeration.DescriptorType) DescriptorMetadata(com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) DescriptorsResponseModel(com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel) Test(org.junit.jupiter.api.Test)

Example 12 with ConfigContextEnum

use of com.synopsys.integration.alert.common.enumeration.ConfigContextEnum in project hub-alert by blackducksoftware.

the class AuthorizationManager method getOperations.

public final Set<Integer> getOperations(ConfigContextEnum context, DescriptorKey descriptorKey) {
    PermissionKey permissionKey = new PermissionKey(context.name(), descriptorKey.getUniversalKey());
    Collection<String> roleNames = getCurrentUserRoleNames();
    return roleNames.stream().filter(permissionCache::containsKey).map(permissionCache::get).map(object -> object.getOperations(permissionKey)).collect(Collectors.toSet());
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) UserModel(com.synopsys.integration.alert.common.persistence.model.UserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) AlertForbiddenOperationException(com.synopsys.integration.alert.common.exception.AlertForbiddenOperationException) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Map(java.util.Map) UserDetails(org.springframework.security.core.userdetails.UserDetails) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Logger(org.slf4j.Logger) AccessOperation(com.synopsys.integration.alert.common.enumeration.AccessOperation) Collection(java.util.Collection) Set(java.util.Set) ConfigContextEnum(com.synopsys.integration.alert.common.enumeration.ConfigContextEnum) PermissionMatrixModel(com.synopsys.integration.alert.common.persistence.model.PermissionMatrixModel) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) RoleAccessor(com.synopsys.integration.alert.common.descriptor.accessor.RoleAccessor) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) UserRoleModel(com.synopsys.integration.alert.common.persistence.model.UserRoleModel) Authentication(org.springframework.security.core.Authentication) PermissionKey(com.synopsys.integration.alert.common.persistence.model.PermissionKey)

Aggregations

ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)12 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 Test (org.junit.jupiter.api.Test)5 DescriptorMetadata (com.synopsys.integration.alert.common.descriptor.config.ui.DescriptorMetadata)4 DescriptorsResponseModel (com.synopsys.integration.alert.web.api.metadata.model.DescriptorsResponseModel)4 Optional (java.util.Optional)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4 DescriptorType (com.synopsys.integration.alert.common.enumeration.DescriptorType)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 DefinedFieldModel (com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 ConfigContextEntity (com.synopsys.integration.alert.database.configuration.ConfigContextEntity)3 DefinedFieldEntity (com.synopsys.integration.alert.database.configuration.DefinedFieldEntity)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 StringUtils (org.apache.commons.lang3.StringUtils)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)2 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)2