Commit cfa63cd5 by hy

添加LicenseProperties

parent 60560651
package com.tbyf.license;
public class Constants {
public static final String LICENSE_FILE_NAME = "hip.lic";
}
......@@ -30,9 +30,8 @@ public class LicenseInstallationServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Part filePart = req.getPart("license");
String fileName = filePart.getSubmittedFileName();
try (InputStream is = filePart.getInputStream()) {
Path dest = Paths.get(properties.getLocation(), fileName).toAbsolutePath().normalize();
Path dest = Paths.get(properties.getLocation(), Constants.LICENSE_FILE_NAME).toAbsolutePath().normalize();
Files.copy(is, dest, StandardCopyOption.REPLACE_EXISTING);
this.licenseManager.install(dest.toString());
resp.setStatus(HttpStatus.OK.value());
......
......@@ -9,9 +9,15 @@ import global.namespace.truelicense.api.LicenseValidationException;
import global.namespace.truelicense.core.passwd.ObfuscatedPasswordProtection;
import global.namespace.truelicense.obfuscate.ObfuscatedString;
import global.namespace.truelicense.v4.V4;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class LicenseManager {
public class LicenseManager implements InitializingBean {
private static final String SUBJECT = "HIP";
private static final String KEY_STORE_FILE = "public.ks";
......@@ -24,6 +30,9 @@ public class LicenseManager {
volatile ConsumerLicenseManager _manager;
@Autowired
LicenseProperties licenseProperties;
private static void verifyMAC(Object MAC) throws LicenseValidationException {
if (MAC == null || !NetUtil.containsMAC(MAC.toString())) {
throw new LicenseValidationException(Messages.message("Invalid License"));
......@@ -39,13 +48,13 @@ public class LicenseManager {
return _managementContext
.consumer()
.encryption()
.protection(protection(new long[]{0x9d823a2b21bef869L, 0x4f4790eaa895d3d8L}))
.up()
.protection(protection(new long[]{0x9d823a2b21bef869L, 0x4f4790eaa895d3d8L}))
.up()
.authentication()
.alias("standard")
.loadFromResource(KEY_STORE_FILE)
.storeProtection(protection(new long[]{0x10111721aeba73dcL, 0x1aba2dc58b17fdbeL, 0x126b920ac6703949L}))
.up()
.alias("standard")
.loadFromResource(KEY_STORE_FILE)
.storeProtection(protection(new long[]{0x10111721aeba73dcL, 0x1aba2dc58b17fdbeL, 0x126b920ac6703949L}))
.up()
.storeInUserPreferences(getClass())
.build();
}
......@@ -73,4 +82,14 @@ public class LicenseManager {
period.setExpirationTime(license.getNotAfter());
return period;
}
@Override
public void afterPropertiesSet() throws Exception {
Path dir = Paths.get(this.licenseProperties.getLocation()).toAbsolutePath().normalize();
Files.createDirectories(dir);
Path licensePath = dir.resolve(Constants.LICENSE_FILE_NAME);
if (Files.isRegularFile(licensePath) && Files.exists(licensePath)) {
install(licensePath.toString());
}
}
}
package com.tbyf.license;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import global.namespace.fun.io.api.NoContentException;
import global.namespace.truelicense.api.LicenseManagementException;
import global.namespace.truelicense.api.LicenseValidationException;
......@@ -15,6 +17,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class LicenseValidationFilter extends OncePerRequestFilter {
......@@ -40,16 +43,17 @@ public class LicenseValidationFilter extends OncePerRequestFilter {
// Invalid License
private final static String INVALID_LICENSE =
new ObfuscatedString(new long[]{
0x49e5266592028869L, 0x9315b379de60a1beL, 0xe1fde0262ab5ed27L,
0xde54ce8a8e5d4e19L, 0x42880fae5dbb8a13L, 0x7dc34d7fb839ec0dL,
0x99a3515ef60c84a5L, 0xc708fcab8319dfb3L}).toString();
0xf028f58c58a58b70L, 0x8e3687628cabf715L, 0x1d7b18d3be15ee3cL,
0x6484235954092864L, 0x1d0c5795e106b625L, 0x85bd4fc5f74c1953L,
0xbd8ecfc20bd71d2L, 0x43a6f39da2c77092L, 0xdb66a1baf052acdL,
0x5289ce404edb39b2L}).toString();
// No License
private final static String NO_LICENSE =
new ObfuscatedString(new long[]{
0x8cb7df8f04d69f43L, 0xd616159bdf90a5eL, 0x508a735a1546f8bcL,
0x7925f6557e460d53L, 0x4667e92ce4bcef22L, 0x359b5eefb590ca78L,
0x239eba55236200f0L}).toString();
0xc8eb6c067584a44fL, 0x3b927f424d2f8b3dL, 0x63b037cacbc18631L,
0xea641540f5303384L, 0xf74c5ed8383e8a2aL, 0x58e83b8ba2f4d29dL,
0xa87739551ba09b21L, 0x388b360692cb587L, 0x9a270e40ae793a05L}).toString();
public void setLicenseManager(LicenseManager licenseManager) {
this.licenseManager = licenseManager;
......@@ -94,7 +98,4 @@ public class LicenseValidationFilter extends OncePerRequestFilter {
return false;
}
public static void main(String[] args) {
System.out.println(ObfuscatedString.obfuscate("/license/uninstall"));
}
}
......@@ -2,11 +2,9 @@ package com.tbyf.license;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class NetUtil {
......@@ -41,7 +39,7 @@ public class NetUtil {
allMACs.add(String.join("-", MAC));
}
}
System.out.println(allMACs);
System.out.println("本地MAC地址为: " + allMACs);
return allMACs;
}
catch (SocketException e) {
......
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