yangys
2025-02-17 74355e14088df2c60da6e9a2b026fa0513709de9
增加授权认证。
已修改4个文件
已添加5个文件
281 ■■■■ 文件已修改
smart-man-boot/pom.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/config/InterceptorConfig.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/interceptor/LicenseCheckInterceptor.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/license/LicenseWrapper.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/runner/InitRunner.java 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/smis/service/impl/WorkstationServiceImpl.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/workinghour/controller/LicenseTestController.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/workinghour/controller/PartWorkHourController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/resources/application.yml 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/pom.xml
@@ -134,16 +134,7 @@
            <artifactId>smart-starter-social</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!--
        
        -->
        <!--
        -->
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-ui</artifactId>
@@ -397,6 +388,13 @@
            <!--<version>1.1.0-SNAPSHOT</version>-->
            <version>1.0.4</version>
        </dependency>
        <!--千文密钥认证-->
        <dependency>
            <groupId>com.qianwen</groupId>
            <artifactId>license-common</artifactId>
            <version>1.0.0</version>
        </dependency>
        <!-- å›¾ç‰‡åŽ‹ç¼© -->
        <dependency>
            <groupId>net.coobird</groupId>
@@ -511,6 +509,14 @@
            <artifactId>jfreechart</artifactId>
            <version>1.5.5</version>
        </dependency>
        <!--lincense验证-->
        <dependency>
            <groupId>de.schlichtherle.truelicense</groupId>
            <artifactId>truelicense-core</artifactId>
            <version>1.33</version>
        </dependency>
    </dependencies>
    
  <build>
smart-man-boot/src/main/java/com/qianwen/smartman/common/config/InterceptorConfig.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,19 @@
package com.qianwen.smartman.common.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.qianwen.smartman.common.interceptor.LicenseCheckInterceptor;
@Configuration
public class InterceptorConfig implements WebMvcConfigurer{
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LicenseCheckInterceptor());
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/common/interceptor/LicenseCheckInterceptor.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,39 @@
package com.qianwen.smartman.common.interceptor;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.qianwen.license.common.LicenseVerify;
/**
 * license校验拦截
 */
public class LicenseCheckInterceptor extends HandlerInterceptorAdapter{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        LicenseVerify licenseVerify = new LicenseVerify();
        //校验证书是否有效
        boolean verifyResult = licenseVerify.verify();
        if(verifyResult){
            return true;
        }else{
            response.setContentType("application/json;charset=utf8");
            response.setCharacterEncoding("utf-8");
            Map<String,String> result = new HashMap<>(1);
            result.put("success", "false");
            result.put("msg","您的证书无效,请核查服务器是否取得授权或重新申请证书!");
            response.getWriter().write(JSON.toJSONString(result));//throw new ServiceException("您的证书无效,请核查服务器是否取得授权或重新申请证书!");
            return false;
        }
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/common/license/LicenseWrapper.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,27 @@
package com.qianwen.smartman.common.license;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONValidator;
import com.qianwen.license.common.LicenseExtraModel;
import com.qianwen.license.common.LicenseVerify;
@Component
public class LicenseWrapper {
    //@Autowired
    //private LicenseVerify licenseVerify;
    public long getWorkstationAmount() {
        LicenseVerify licenseVerify = new LicenseVerify();
        LicenseExtraModel model = (LicenseExtraModel)licenseVerify.getContent().getExtra();
        if(JSONValidator.from(model.getExtData()).validate()) {
            JSONObject jsonObj = JSONObject.parseObject(model.getExtData()) ;
            return jsonObj.getLong("workstationAmount");
        }else {
            return 0;
        }
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/common/runner/InitRunner.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,65 @@
package com.qianwen.smartman.common.runner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import com.qianwen.license.common.LicenseVerify;
import com.qianwen.license.common.LicenseVerifyParam;
@Component
public class InitRunner implements ApplicationRunner {
    private static final Logger log = LoggerFactory.getLogger(InitRunner.class);
    @Value("${license.subject}")
    private String subject;
    /**
     * å…¬é’¥åˆ«ç§°
     */
    @Value("${license.publicAlias}")
    private String publicAlias;
    /**
     * è®¿é—®å…¬é’¥åº“的密码
     */
    @Value("${license.storePass}")
    private String storePass;
    /**
     * è¯ä¹¦ç”Ÿæˆè·¯å¾„
     */
    @Value("${license.licensePath}")
    private String licensePath;
    /**
     * å¯†é’¥åº“存储路径
     */
    @Value("${license.publicKeysStorePath}")
    private String publicKeysStorePath;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //安装证书
        initLicense();
    }
    void initLicense() {
        LicenseVerifyParam param = new LicenseVerifyParam();
        param.setSubject(subject);
        param.setPublicAlias(publicAlias);
        param.setStorePass(storePass);
        param.setLicensePath(licensePath);
        param.setPublicKeysStorePath(publicKeysStorePath);
        LicenseVerify licenseVerify = new LicenseVerify();
        //安装证书
        licenseVerify.install(param);
        log.info("++++++++ è¯ä¹¦å®‰è£…结束 ++++++++");
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/smis/service/impl/WorkstationServiceImpl.java
@@ -29,6 +29,7 @@
import com.alibaba.excel.write.merge.AbstractMergeStrategy;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -42,10 +43,11 @@
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.oss.model.BladeFile;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.tool.utils.CollectionUtil;
import com.qianwen.core.tool.utils.DateUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.core.tool.utils.StringUtil;
import com.qianwen.license.common.LicenseExtraModel;
import com.qianwen.license.common.LicenseVerify;
import com.qianwen.smartman.common.cache.DictCache;
import com.qianwen.smartman.common.cache.cps.WorkstationCache;
import com.qianwen.smartman.common.constant.CalendarConstant;
@@ -59,6 +61,7 @@
import com.qianwen.smartman.common.enums.DictEnum;
import com.qianwen.smartman.common.enums.StatusType;
import com.qianwen.smartman.common.enums.WcsDataTypeEnums;
import com.qianwen.smartman.common.license.LicenseWrapper;
import com.qianwen.smartman.common.mqtt.MqttMessageSender;
import com.qianwen.smartman.common.utils.Lambda;
import com.qianwen.smartman.common.utils.MessageUtils;
@@ -147,6 +150,8 @@
    private MqttMessageSender mqttMsgSender;
    @Autowired
    private WorkstationDatapointsService wsDpService;
    @Autowired
    private LicenseWrapper licenseWrapper;
    
    private final String NAME = "默认工作台";
    private final Integer SORT = 1;
@@ -186,6 +191,9 @@
    @Override 
    @Transactional(rollbackFor = {Exception.class})
    public WorkstationVO submit(WorkstationSubmitVO workstationSubmitVO) {
        checkLicenseCount();
        checkWorkstation(workstationSubmitVO);
        if (Func.isEmpty(workstationSubmitVO.getId())) {
            checkUnableWorkstation(workstationSubmitVO);
@@ -229,6 +237,18 @@
        }
        return workstationVO;
    }
    void checkLicenseCount() {
        Wrapper<Workstation> wrapper = Wrappers.lambdaQuery(Workstation.class).eq(Workstation::getIsDeleted, 0);
        Long count = workstationMapper.selectCount(wrapper);
        Long machineAmount = licenseWrapper.getWorkstationAmount();
        if(count >= machineAmount) {
            throw new ServiceException("工位数超过许可上限数:"+ machineAmount);
        }
    }
    /*
    private void submitWorkstationFtpDirectory(WorkstationSubmitVO workstationSubmitVO, Workstation workstation) {
        if (Func.isEmpty(workstationSubmitVO.getId()) && Func.isNotEmpty(workstationSubmitVO.getFtpDirectoryType())) {
smart-man-boot/src/main/java/com/qianwen/smartman/modules/workinghour/controller/LicenseTestController.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,40 @@
package com.qianwen.smartman.modules.workinghour.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.tenant.annotation.NonDS;
import com.qianwen.core.tool.api.R;
import com.qianwen.license.common.LicenseExtraModel;
import com.qianwen.license.common.LicenseVerify;
import de.schlichtherle.license.LicenseContent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(value = "工时分析", tags = {"工时分析"})
@RestController
@ApiResource({"test"})
@NonDS
@Validated
public class LicenseTestController extends BladeController {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    @GetMapping({"/licmcount"})
    @ApiOperation("测试授权")
    public R<Object> licmcount() {
        LicenseVerify licenseVerify = new LicenseVerify();
        LicenseContent model = licenseVerify.getContent();
        return R.data(model.getExtra());
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/workinghour/controller/PartWorkHourController.java
@@ -68,7 +68,7 @@
        try {
            return R.data(partWorkingHourExportService.export(id));
        } catch (Exception e) {
            log.error("导出公式数据错误",e);
            log.error("导出公时数据错误",e);
            
            return R.fail(e.getMessage());
        }
smart-man-boot/src/main/resources/application.yml
@@ -17,6 +17,12 @@
    name: smartman-api
  banner:
    location: classpath:smartbanner.txt
  resources:
    static-locations: static
  thymeleaf:
    cache: false
  mvc:
    static-path-pattern: classpath:/static/**
  redis:
    ##redis å•机环境配置
    host: ${redis.host}
@@ -275,6 +281,7 @@
      - /blade-cps/group/groupWorkstation/jimu
      - /blade-fms/order/process/issued
      - /blade-cps/test/**
      - /test/*
    #授权认证配置
    auth:
      - method: ALL
@@ -349,36 +356,12 @@
      - FlowMapper
      - SuperNewCollectMapper
# rocketmq é…ç½®é¡¹ï¼Œå¯¹åº” RocketMQProperties é…ç½®ç±»
rocketmq:
  name-server: ${rocketmq-name-server} # RocketMQ Namesrv
  # Producer é…ç½®é¡¹
  producer:
    group: masterlink-default-producer-group # é»˜è®¤ç”Ÿäº§è€…分组,最好使用各自明确分组
    send-message-timeout: 3000 # å‘送消息超时时间,单位:毫秒。默认为 3000 ã€‚
    compress-message-body-threshold: 4096 # æ¶ˆæ¯åŽ‹ç¼©é˜€å€¼ï¼Œå½“æ¶ˆæ¯ä½“çš„å¤§å°è¶…è¿‡è¯¥é˜€å€¼åŽï¼Œè¿›è¡Œæ¶ˆæ¯åŽ‹ç¼©ã€‚é»˜è®¤ä¸º 4 * 1024B
    max-message-size: 4194304 # æ¶ˆæ¯ä½“的最大允许大小。。默认为 4 * 1024 * 1024B
    retry-times-when-send-failed: 2 # åŒæ­¥å‘送消息时,失败重试次数。默认为 2 æ¬¡ã€‚
    retry-times-when-send-async-failed: 2 # å¼‚步发送消息时,失败重试次数。默认为 2 æ¬¡ã€‚
    retry-next-server: false # å‘送消息给 Broker æ—¶ï¼Œå¦‚果发送失败,是否重试另外一台 Broker ã€‚默认为 false
    enable-msg-trace: true # æ˜¯å¦å¼€å¯æ¶ˆæ¯è½¨è¿¹åŠŸèƒ½ã€‚é»˜è®¤ä¸º true å¼€å¯ã€‚
    customized-trace-topic: BLADE_RMQ_SYS_TRACE_TOPIC # è‡ªå®šä¹‰æ¶ˆæ¯è½¨è¿¹çš„ Topic ã€‚默认为 RMQ_SYS_TRACE_TOPIC ã€‚
  message:
    posting:
      workstation-aggregate:
        topic: workstation-aggregate-topic
        consumer: workstation-aggregate-comsumer
---
spring:
  resources:
    static-locations: static
  thymeleaf:
    cache: false
  mvc:
    static-path-pattern: classpath:/static/**
license:
  subject: user #主体 - æ³¨æ„ä¸»ä½“要与生成证书的主体一致一致,不然验证通过不了
  publicAlias: publiccert #公钥别称
  storePass: a1b2c3 #访问公钥库的密码
  licensePath: D:\lictest\ctest.lic #license位置
  publicKeysStorePath: D:\lictest\publicCerts.store #公钥位置
forest:
  bean-id: config0 # åœ¨spring上下文中bean的id, é»˜è®¤å€¼ä¸ºforestConfiguration
  backend: okhttp3 # åŽç«¯HTTP API: okhttp3 ã€æ”¯æŒ`okhttp3`/`httpclient`】