Search in sources :

Example 1 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class XmEntitySpecServiceUnitTest method disableDynamicPrivilegesGeneration.

private void disableDynamicPrivilegesGeneration() {
    XmEntityTenantConfig config = new XmEntityTenantConfig();
    config.setDisableDynamicPrivilegesGeneration(true);
    when(tenantConfig.getXmEntityTenantConfig("TEST")).thenReturn(config);
}
Also used : XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)

Example 2 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class XmEntitySpecServiceUnitTest method enableDynamicPermissionCheck.

private void enableDynamicPermissionCheck() {
    XmEntityTenantConfig config = new XmEntityTenantConfig();
    when(tenantConfig.getXmEntityTenantConfig("TEST")).thenReturn(config);
    config.getEntityFunctions().setDynamicPermissionCheckEnabled(true);
}
Also used : XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)

Example 3 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class FunctionServiceImplUnitTest method setUp.

@Before
public void setUp() {
    xmEntitySpecService = Mockito.mock(XmEntitySpecService.class);
    xmEntityService = Mockito.mock(XmEntityService.class);
    functionExecutorService = Mockito.mock(FunctionExecutorService.class);
    functionContextService = Mockito.mock(FunctionContextService.class);
    dynamicPermissionCheckService = Mockito.mock(DynamicPermissionCheckService.class);
    xmEntityTenantConfigService = Mockito.mock(XmEntityTenantConfigService.class);
    jsonValidationService = spy(new JsonValidationService(new ObjectMapper()));
    functionService = new FunctionServiceImpl(xmEntitySpecService, xmEntityService, functionExecutorService, functionContextService, dynamicPermissionCheckService, jsonValidationService, xmEntityTenantConfigService);
    xmEntityTenantConfig = new XmEntityTenantConfig();
    when(xmEntityTenantConfigService.getXmEntityTenantConfig()).thenReturn(xmEntityTenantConfig);
}
Also used : XmEntityService(com.icthh.xm.ms.entity.service.XmEntityService) DynamicPermissionCheckService(com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService) XmEntitySpecService(com.icthh.xm.ms.entity.service.XmEntitySpecService) JsonValidationService(com.icthh.xm.ms.entity.service.JsonValidationService) FunctionContextService(com.icthh.xm.ms.entity.service.FunctionContextService) XmEntityTenantConfigService(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService) FunctionExecutorService(com.icthh.xm.ms.entity.service.FunctionExecutorService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)

Example 4 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class XmEntitySpecService method extendDataSpec.

@SneakyThrows
private void extendDataSpec(TypeSpec type, TypeSpec parentType, String tenant) {
    XmEntityTenantConfig entityTenantConfig = this.tenantConfigService.getXmEntityTenantConfig(tenant);
    Boolean isInheritanceEnabled = entityTenantConfig.getEntitySpec().getEnableDataSpecInheritance();
    if (isFeatureEnabled(isInheritanceEnabled, type.getDataSpecInheritance()) && hasDataSpec(type, parentType)) {
        ObjectMapper objectMapper = new ObjectMapper();
        var target = objectMapper.readValue(type.getDataSpec(), Map.class);
        var parent = objectMapper.readValue(parentType.getDataSpec(), Map.class);
        if (parent.containsKey("additionalProperties")) {
            parent.put("additionalProperties", true);
        }
        target.put(XM_ENTITY_DEFINITION, Map.of(parentType.getKey(), parent));
        target.put("$ref", "#/" + XM_ENTITY_DEFINITION + "/" + parentType.getKey());
        String mergedJson = objectMapper.writeValueAsString(target);
        type.setDataSpec(mergedJson);
    } else {
        type.setDataSpec(type.getDataSpec() != null ? type.getDataSpec() : parentType.getDataSpec());
    }
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig) SneakyThrows(lombok.SneakyThrows)

Example 5 with XmEntityTenantConfig

use of com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig in project xm-ms-entity by xm-online.

the class EntityCustomPrivilegeService method onEntitySpecUpdate.

@IgnoreLogginAspect
@Override
public void onEntitySpecUpdate(Map<String, TypeSpec> specs, String tenantKey) {
    XmEntityTenantConfig xmEntityTenantConfig = tenantConfigService.getXmEntityTenantConfig(tenantKey);
    Boolean disableDynamicPrivilegesGeneration = xmEntityTenantConfig.getDisableDynamicPrivilegesGeneration();
    if (Boolean.TRUE.equals(disableDynamicPrivilegesGeneration)) {
        log.warn("Dynamic privilege generation disabled.");
        return;
    }
    String privilegesPath = resolvePathWithTenant(tenantKey, CUSTOMER_PRIVILEGES_PATH);
    log.info("Get config from {}", privilegesPath);
    List<String> paths = asList(privilegesPath);
    Map<String, Configuration> configs = commonConfigRepository.getConfig(null, paths);
    configs = configs == null ? new HashMap<>() : configs;
    updateCustomPrivileges(specs, privilegesPath, configs.get(privilegesPath), tenantKey);
}
Also used : Configuration(com.icthh.xm.commons.config.domain.Configuration) HashMap(java.util.HashMap) XmEntityTenantConfig(com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig) IgnoreLogginAspect(com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)

Aggregations

XmEntityTenantConfig (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SneakyThrows (lombok.SneakyThrows)2 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 Configuration (com.icthh.xm.commons.config.domain.Configuration)1 IgnoreLogginAspect (com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)1 XmEntityTenantConfigService (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService)1 DynamicPermissionCheckService (com.icthh.xm.ms.entity.security.access.DynamicPermissionCheckService)1 FunctionContextService (com.icthh.xm.ms.entity.service.FunctionContextService)1 FunctionExecutorService (com.icthh.xm.ms.entity.service.FunctionExecutorService)1 JsonValidationService (com.icthh.xm.ms.entity.service.JsonValidationService)1 XmEntityService (com.icthh.xm.ms.entity.service.XmEntityService)1 XmEntitySpecService (com.icthh.xm.ms.entity.service.XmEntitySpecService)1 HashMap (java.util.HashMap)1