jiazx0107@163.com
2023-11-04 43ce77a85d8297a53dc25430fff10ead57296167
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.ld.igds.web;
 
import com.bstek.bdf2.core.controller.IController;
import com.ld.license.LicenseVerify;
import com.ld.license.LicenseVerifyParam;
import de.schlichtherle.license.LicenseContent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
 
/**
 * 安装证书,支持匿名访问 方位路径:http://127.0.0.1:8080/igds/installLicense.action
 */
@Component
@Slf4j
public class InstallLicenseAction implements IController {
    @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 String getUrl() {
        return "/installLicense";
    }
 
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        log.info("++++++++ 开始安装证书 ++++++++");
        LicenseVerifyParam param = new LicenseVerifyParam();
        param.setSubject(this.subject);
        param.setPublicAlias(this.publicAlias);
        param.setStorePass(this.storePass);
        param.setLicensePath(this.licensePath);
        param.setPublicKeysStorePath(this.publicKeysStorePath);
        LicenseVerify licenseVerify = new LicenseVerify();
        LicenseContent content = licenseVerify.install(param);
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF8");
        PrintWriter writer = response.getWriter();
        if(content != null){
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            writer.write(MessageFormat.format("证书安装成功,证书有效期:{0} - {1}", format.format(content.getNotBefore()), format.format(content.getNotAfter())));
            writer.close();
        }else{
            writer.write("证书安装失败!情联系管理员");
            writer.close();
        }
        log.info("++++++++ 证书安装结束 ++++++++");
    }
 
    @Override
    public boolean anonymousAccess() {
        return false;
    }
 
    @Override
    public boolean isDisabled() {
        return false;
    }
 
}