package cn.component.listener;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 在项目启动时安装证书
 */

@Component
@ConfigurationProperties(prefix = "license")
@PropertySource(value = {"classpath:config/system/license.properties"})
public class LicenseCheckListener implements ApplicationListener<ContextRefreshedEvent> 
{
	
	private String subject;
	private String publicAlias;
	private String storePass;
	private String licensePath;
	private String publicKeysStorePath;

	@Override
	public void onApplicationEvent(ContextRefreshedEvent event)
	{/*OK
		ApplicationContext context = event.getApplicationContext().getParent();
		if(IsUtil.isNull(context))
		{
			
			if(StringUtils.isNotBlank(licensePath)){
				LogUtil.info("++++++++ 开始安装证书 ++++++++");
				LicenseVerifyParam param = new LicenseVerifyParam();
				param.setSubject(subject);
				param.setPublicAlias(publicAlias);
				param.setStorePass(storePass);
				param.setLicensePath(sysConfig.getAuthPath() + licensePath);
				param.setPublicKeysStorePath(sysConfig.getAuthPath() + publicKeysStorePath);
				LicenseVerifyManager licenseVerify = new LicenseVerifyManager();
				LicenseContent result = licenseVerify.install(param);
				if(IsUtil.isNull(result)) {
					LogUtil.info("++++++++ 证书安装失败  ++++++++");
				}
				else {
					LogUtil.info("++++++++ 证书安装结束 ++++++++");
				}
				
			}
		}*/
	}
	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getPublicAlias() {
		return publicAlias;
	}

	public void setPublicAlias(String publicAlias) {
		this.publicAlias = publicAlias;
	}

	public String getStorePass() {
		return storePass;
	}

	public void setStorePass(String storePass) {
		this.storePass = storePass;
	}

	public String getLicensePath() {
		return licensePath;
	}

	public void setLicensePath(String licensePath) {
		this.licensePath = licensePath;
	}

	public String getPublicKeysStorePath() {
		return publicKeysStorePath;
	}

	public void setPublicKeysStorePath(String publicKeysStorePath) {
		this.publicKeysStorePath = publicKeysStorePath;
	}
}
