57 lines
1.9 KiB
Java
57 lines
1.9 KiB
Java
package com.zhgd.xmgl.config;
|
|
|
|
import com.zhgd.xmgl.modules.basicdata.entity.ComputerAuth;
|
|
import com.zhgd.xmgl.modules.basicdata.mapper.ComputerAuthMapper;
|
|
import com.zhgd.xmgl.util.ComputerInfo;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.BeansException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContextAware;
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: wisdomSite
|
|
* @description: 校验服务器
|
|
* @author: Mr.Peng
|
|
* @create: 2021-04-23 16:39
|
|
**/
|
|
@Component
|
|
@Order(value = 1)
|
|
@Slf4j
|
|
public class CheckMac implements CommandLineRunner, ApplicationContextAware {
|
|
@Autowired
|
|
private ComputerAuthMapper computerAuthMapper;
|
|
|
|
private ApplicationContext context;
|
|
|
|
@Value("${checkAuthEnable}")
|
|
private boolean checkAuthEnable;
|
|
|
|
@Override
|
|
public void run(String... args) throws Exception {
|
|
if (checkAuthEnable) {
|
|
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) context;
|
|
List<String> macList = ComputerInfo.getMd5MacAddress();
|
|
ComputerAuth auth = computerAuthMapper.getOneComputerAuth();
|
|
if (auth != null) {
|
|
if (!macList.contains(auth.getAddress())) {
|
|
log.info("---------------服务器未授权,请联系管理员----------------");
|
|
ctx.close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
context = applicationContext;
|
|
}
|
|
}
|