All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arextest.schedule.beans.DataDesensitizationConfiguration Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package com.arextest.schedule.beans;

import com.arextest.common.model.classloader.RemoteJarClassLoader;
import com.arextest.common.utils.RemoteJarLoaderUtils;
import com.arextest.config.model.dto.system.DesensitizationJar;
import com.arextest.extension.desensitization.DataDesensitization;
import com.arextest.extension.desensitization.DefaultDataDesensitization;
import com.arextest.schedule.service.ConfigurationService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.CollectionUtils;


@Configuration
@Slf4j
public class DataDesensitizationConfiguration {

  @Resource
  ConfigurationService configurationService;

  @Bean
  @ConditionalOnMissingBean(DataDesensitization.class)
  DataDesensitization desensitizationService() {
    List uploaded = configurationService.desensitization();
    if (CollectionUtils.isEmpty(uploaded)) {
      return new DefaultDataDesensitization();
    } else {
      try {
        DesensitizationJar selected = uploaded.get(0);
        RemoteJarClassLoader classLoader = RemoteJarLoaderUtils.loadJar(selected.getJarUrl());
        return RemoteJarLoaderUtils.loadService(DataDesensitization.class, classLoader).get(0);
      } catch (Throwable t) {
        LOGGER.error("Load remote desensitization jar failed, application startup blocked", t);
        throw new RuntimeException("Load remote desensitization jar failed");
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy