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);
}
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));
}
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);
}
Aggregations