Commit 7510b97d by linxu

增加license校验

parent 9cf7e21b
package com.keymobile.sso.conf;
import com.keymobile.crypto.aes.AESUtil;
import com.keymobile.sso.logging.LogConstants;
import com.keymobile.sso.logging.LogManager;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.LocalDate;
import java.util.Base64;
public class LicenseMgr {
public static String generate(String expiredDate) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
SecretKey secretKey = new SecretKeySpec(Base64.getDecoder().decode("NCXgEu++tYgACfaC0zt7E+Ti5CR4AZ3NkTVhfvsgEjc="), "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(Base64.getDecoder().decode("2w6UWLMm0Om7fCAfpfkyeA=="));
return AESUtil.encryptPasswordBased(expiredDate, secretKey, ivParameterSpec);
}
public static void check(String licenseText) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
SecretKey secretKey = new SecretKeySpec(Base64.getDecoder().decode("NCXgEu++tYgACfaC0zt7E+Ti5CR4AZ3NkTVhfvsgEjc="), "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(Base64.getDecoder().decode("2w6UWLMm0Om7fCAfpfkyeA=="));
String expiredDate = AESUtil.decryptPasswordBased(licenseText, secretKey, ivParameterSpec);
LocalDate expired = LocalDate.parse(expiredDate);
System.out.println("License will expire at " + expiredDate + ".");
}
public static void main(String [] args) throws InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
String licenseText = generate("2025-09-01");
System.out.println("licenseText:" + licenseText);
check(licenseText);
}
}
...@@ -36,7 +36,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc ...@@ -36,7 +36,7 @@ public class RESTAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuc
returnStatus = "root not allow login"; returnStatus = "root not allow login";
} }
if (!SystemVariable.isDisableLicenceCheck()) { if (!SystemVariable.isDisableLicenseCheck()) {
try { try {
if (!licenseChecker.check()) { if (!licenseChecker.check()) {
returnStatus = "license expired"; returnStatus = "license expired";
......
...@@ -8,16 +8,16 @@ public class SystemVariable { ...@@ -8,16 +8,16 @@ public class SystemVariable {
private static String licenseFileName = ""; private static String licenseFileName = "";
static { static {
disableLicenceCheck = System.getProperty("disableLicenceCheck"); disableLicenceCheck = System.getProperty("disableLicenseCheck");
licenseFileName = System.getProperty("licenseFile"); licenseFileName = System.getProperty("licenseFile");
System.out.println("------------ SSO Global Settings ------------"); System.out.println("------------ SSO Global Settings ------------");
System.out.println("disableLicenceCheck:" + isDisableLicenceCheck()); System.out.println("disableLicenseCheck:" + isDisableLicenseCheck());
System.out.println("licenseFile:" + getLicenseFileName()); System.out.println("licenseFile:" + getLicenseFileName());
System.out.println("-----------------------------------------------------"); System.out.println("-----------------------------------------------------");
} }
public static boolean isDisableLicenceCheck() { public static boolean isDisableLicenseCheck() {
if (StringUtils.isNotEmpty(disableLicenceCheck) && disableLicenceCheck.equals("true")) { if (StringUtils.isNotEmpty(disableLicenceCheck) && disableLicenceCheck.equals("true")) {
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment