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