Search in sources :

Example 1 with Configuration

use of com.icthh.xm.commons.config.domain.Configuration 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)

Example 2 with Configuration

use of com.icthh.xm.commons.config.domain.Configuration in project xm-ms-entity by xm-online.

the class EntityCustomPrivilegeService method updateCustomPrivileges.

@SneakyThrows
private void updateCustomPrivileges(Map<String, TypeSpec> specs, String privilegesPath, Configuration customPrivileges, String tenantKey) {
    val privileges = getPrivilegesConfig(customPrivileges);
    addCustomPrivileges(specs, privileges, tenantKey);
    String content = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(privileges);
    if (DigestUtils.sha1Hex(content).equals(sha1Hex(customPrivileges))) {
        log.info("Privileges configuration not changed");
        return;
    }
    commonConfigRepository.updateConfigFullPath(new Configuration(privilegesPath, content), sha1Hex(customPrivileges));
}
Also used : lombok.val(lombok.val) Configuration(com.icthh.xm.commons.config.domain.Configuration) SneakyThrows(lombok.SneakyThrows)

Example 3 with Configuration

use of com.icthh.xm.commons.config.domain.Configuration in project xm-ms-entity by xm-online.

the class XmEntitySpecServiceUnitTest method testUpdateCustomerPrivileges.

private void testUpdateCustomerPrivileges(String customPrivileges, String expectedCustomPrivileges) {
    String privilegesPath = PRIVILEGES_PATH;
    Map<String, Configuration> configs = of(privilegesPath, new Configuration(privilegesPath, customPrivileges));
    when(commonConfigRepository.getConfig(isNull(), eq(List.of(privilegesPath)))).thenReturn(configs);
    when(roleService.getRoles("TEST")).thenReturn(of("TEST_ROLE", new Role()));
    xmEntitySpecService.getTypeSpecs();
    verify(commonConfigRepository).getConfig(isNull(), eq(List.of(privilegesPath)));
    ArgumentCaptor<Configuration> captor = ArgumentCaptor.forClass(Configuration.class);
    verify(commonConfigRepository).updateConfigFullPath(captor.capture(), eq(sha1Hex(customPrivileges)));
    assertEquals(privilegesPath, captor.getValue().getPath());
    assertEquals(expectedCustomPrivileges, captor.getValue().getContent());
    verifyNoMoreInteractions(commonConfigRepository);
}
Also used : Role(com.icthh.xm.commons.permission.domain.Role) Configuration(com.icthh.xm.commons.config.domain.Configuration)

Aggregations

Configuration (com.icthh.xm.commons.config.domain.Configuration)3 IgnoreLogginAspect (com.icthh.xm.commons.logging.aop.IgnoreLogginAspect)1 Role (com.icthh.xm.commons.permission.domain.Role)1 XmEntityTenantConfig (com.icthh.xm.ms.entity.config.XmEntityTenantConfigService.XmEntityTenantConfig)1 HashMap (java.util.HashMap)1 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1