From 73c38a1883ec234438a271ff9428d20cf52a25f1 Mon Sep 17 00:00:00 2001 From: oahzeved Date: Wed, 29 Apr 2020 14:25:51 +0800 Subject: [PATCH 1/3] fix: install --- pom.xml | 2 +- .../java/com/rebuild/server/Application.java | 4 +- .../com/rebuild/server/ServerListener.java | 3 ++ .../java/com/rebuild/server/ServerStatus.java | 7 ++- .../helper/AesPreferencesConfigurer.java | 42 +++++++++++----- .../com/rebuild/server/helper/KVStorage.java | 50 +++++++++---------- .../com/rebuild/server/helper/License.java | 10 ++-- .../server/helper/setup/DatabaseBackup.java | 7 ++- .../server/helper/setup/InstallState.java | 2 +- .../server/helper/setup/Installer.java | 2 +- src/main/webapp/admin/system-general.jsp | 2 +- src/main/webapp/user/login.jsp | 2 +- 12 files changed, 77 insertions(+), 56 deletions(-) diff --git a/pom.xml b/pom.xml index 58628f3ad..5d234cf16 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.rebuild rebuild war - 1.9.0 + 1.9.1 rebuild Building your business-systems free! https://getrebuild.com/ diff --git a/src/main/java/com/rebuild/server/Application.java b/src/main/java/com/rebuild/server/Application.java index 535daf212..ba2af948c 100644 --- a/src/main/java/com/rebuild/server/Application.java +++ b/src/main/java/com/rebuild/server/Application.java @@ -64,10 +64,10 @@ public final class Application { /** Rebuild Version */ - public static final String VER = "1.9.0"; + public static final String VER = "1.9.1"; /** Rebuild Build */ - public static final int BUILD = 1090; + public static final int BUILD = 1091; /** Logging for Global */ diff --git a/src/main/java/com/rebuild/server/ServerListener.java b/src/main/java/com/rebuild/server/ServerListener.java index 8031e79c0..b3ea140ec 100644 --- a/src/main/java/com/rebuild/server/ServerListener.java +++ b/src/main/java/com/rebuild/server/ServerListener.java @@ -8,6 +8,7 @@ See LICENSE and COMMERCIAL in the project root for license information. package com.rebuild.server; import cn.devezhao.commons.CalendarUtils; +import com.rebuild.server.helper.AesPreferencesConfigurer; import com.rebuild.server.helper.ConfigurableItem; import com.rebuild.server.helper.SysConfiguration; import com.rebuild.server.helper.setup.InstallState; @@ -54,6 +55,8 @@ public class ServerListener extends ContextCleanupListener implements InstallSta event.getServletContext().setAttribute("baseUrl", CONTEXT_PATH); try { + AesPreferencesConfigurer.initApplicationProperties(); + if (!checkInstalled()) { eventHold = event; LOG.warn(Application.formatFailure("REBUILD IS WAITING FOR INSTALL ...")); diff --git a/src/main/java/com/rebuild/server/ServerStatus.java b/src/main/java/com/rebuild/server/ServerStatus.java index 20592e5ca..9f7e762ae 100644 --- a/src/main/java/com/rebuild/server/ServerStatus.java +++ b/src/main/java/com/rebuild/server/ServerStatus.java @@ -106,12 +106,11 @@ public final class ServerStatus { return Status.success(name); } - AesPreferencesConfigurer configurer = Application.getBean(AesPreferencesConfigurer.class); try { Connection c = DriverManager.getConnection( - configurer.getItem("db.url"), - configurer.getItem("db.user"), - configurer.getItem("db.passwd")); + AesPreferencesConfigurer.getItem("db.url"), + AesPreferencesConfigurer.getItem("db.user"), + AesPreferencesConfigurer.getItem("db.passwd")); SqlHelper.close(c); } catch (Exception ex) { return Status.error(name, ThrowableUtils.getRootCause(ex).getLocalizedMessage()); diff --git a/src/main/java/com/rebuild/server/helper/AesPreferencesConfigurer.java b/src/main/java/com/rebuild/server/helper/AesPreferencesConfigurer.java index b5ebca9ed..597ceafe2 100644 --- a/src/main/java/com/rebuild/server/helper/AesPreferencesConfigurer.java +++ b/src/main/java/com/rebuild/server/helper/AesPreferencesConfigurer.java @@ -18,17 +18,22 @@ along with this program. If not, see . package com.rebuild.server.helper; -import com.rebuild.server.Application; import com.rebuild.server.helper.setup.InstallState; import com.rebuild.server.helper.setup.SetupException; import com.rebuild.utils.AES; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.support.PropertiesLoaderUtils; +import org.springframework.util.Assert; +import org.springframework.util.ResourceUtils; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.util.Properties; /** @@ -39,12 +44,18 @@ import java.util.Properties; */ public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer implements InstallState { - private Properties propsHold = null; + private static final Log LOG = LogFactory.getLog(AesPreferencesConfigurer.class); + + private static Properties propsHold = null; @Override protected void loadProperties(Properties props) throws IOException { super.loadProperties(props); + + props.putAll(fromInstallFile()); this.afterLoad(props); + LOG.info("Application properties : " + props); + setNullValue(StringUtils.EMPTY); } @@ -52,8 +63,6 @@ public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer i * @param props */ private void afterLoad(Properties props) { - props.putAll(fromInstallFile()); - final Object[] keys = props.keySet().toArray(new Object[0]); for (Object key : keys) { String cleanKey = key.toString(); @@ -87,13 +96,6 @@ public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer i setIfEmpty(props, ConfigurableItem.CachePort, "6379"); propsHold = (Properties) props.clone(); - - if (propsHold.getProperty("db.url").contains("jdbc:h2:")) { - Application.LOG.warn("Using QuickMode with H2 database!"); - } - if (Application.devMode()) { - Application.LOG.info("System properties : " + propsHold); - } } /** @@ -125,13 +127,29 @@ public class AesPreferencesConfigurer extends PreferencesPlaceholderConfigurer i } } + // -- + + /** + * @throws IOException + */ + public static void initApplicationProperties() throws IOException { + if (propsHold != null) return; + File file = ResourceUtils.getFile("classpath:application.properties"); + try (InputStream is = new FileInputStream(file)) { + Properties props = new Properties(); + props.load(is); + new AesPreferencesConfigurer().afterLoad(props); + } + } + /** * 获取配置项 * * @param name * @return */ - public String getItem(String name) { + public static String getItem(String name) { + Assert.notNull(propsHold, "Rebuild unstarted"); return StringUtils.defaultIfBlank(propsHold.getProperty(name), null); } } \ No newline at end of file diff --git a/src/main/java/com/rebuild/server/helper/KVStorage.java b/src/main/java/com/rebuild/server/helper/KVStorage.java index bdf6edf86..ed13638ac 100644 --- a/src/main/java/com/rebuild/server/helper/KVStorage.java +++ b/src/main/java/com/rebuild/server/helper/KVStorage.java @@ -21,7 +21,6 @@ package com.rebuild.server.helper; import cn.devezhao.persist4j.Record; import cn.devezhao.persist4j.engine.ID; import com.rebuild.server.Application; -import com.rebuild.server.helper.cache.CommonCache; import com.rebuild.server.metadata.EntityHelper; import com.rebuild.server.service.bizz.UserService; import org.apache.commons.lang.StringUtils; @@ -88,37 +87,38 @@ public class KVStorage { * @return */ protected static String getValue(final String key, boolean reload, Object defaultValue) { - if (!Application.serversReady()) { - return defaultValue == null ? null : defaultValue.toString(); + String value = null; + if (Application.serversReady()) { + value = Application.getCommonCache().get(key); + if (value != null && !reload) { + return value; + } + + // 1. 首先从数据库 + Object[] fromDb = Application.createQueryNoFilter( + "select value from SystemConfig where item = ?") + .setParameter(1, key) + .unique(); + value = fromDb == null ? null : StringUtils.defaultIfBlank((String) fromDb[0], null); } - String cached = Application.getCommonCache().get(key); - if (cached != null && !reload) { - return cached; - } - - // 1. 首先从数据库 - Object[] fromDb = Application.createQueryNoFilter( - "select value from SystemConfig where item = ?") - .setParameter(1, key) - .unique(); - cached = fromDb == null ? null : StringUtils.defaultIfBlank((String) fromDb[0], null); - - // 2. 从配置文件加载 - if (cached == null) { - cached = Application.getBean(AesPreferencesConfigurer.class).getItem(key); + // 2. 从配置文件/命令行加载 + if (value == null) { + value = AesPreferencesConfigurer.getItem(key); } // 3. 默认值 - if (cached == null && defaultValue != null) { - cached = defaultValue.toString(); + if (value == null && defaultValue != null) { + value = defaultValue.toString(); } - if (cached == null) { - Application.getCommonCache().evict(key); - } else { - Application.getCommonCache().put(key, cached); + if (Application.serversReady()) { + if (value == null) { + Application.getCommonCache().evict(key); + } else { + Application.getCommonCache().put(key, value); + } } - return cached; + return value; } } diff --git a/src/main/java/com/rebuild/server/helper/License.java b/src/main/java/com/rebuild/server/helper/License.java index 4b4fcdbc0..585fdccc7 100644 --- a/src/main/java/com/rebuild/server/helper/License.java +++ b/src/main/java/com/rebuild/server/helper/License.java @@ -41,13 +41,15 @@ public final class License { if (SN == null) { try { - String result = CommonsUtils.get( - String.format("https://getrebuild.com/api/authority/new?k=%s&ver=%s", OSA_KEY, Application.VER)); + String apiUrl = String.format("https://getrebuild.com/api/authority/new?ver=%s&k=%s", Application.VER, OSA_KEY); + String result = CommonsUtils.get(apiUrl); + if (JSONUtils.wellFormat(result)) { - JSONObject data = JSON.parseObject(result); - SN = data.getString("sn"); + JSONObject o = JSON.parseObject(result); + SN = o.getString("sn"); SysConfiguration.set(ConfigurableItem.SN, SN); } + } catch (Exception ignored) { // UNCATCHABLE } diff --git a/src/main/java/com/rebuild/server/helper/setup/DatabaseBackup.java b/src/main/java/com/rebuild/server/helper/setup/DatabaseBackup.java index 801896024..07104ce48 100644 --- a/src/main/java/com/rebuild/server/helper/setup/DatabaseBackup.java +++ b/src/main/java/com/rebuild/server/helper/setup/DatabaseBackup.java @@ -8,7 +8,6 @@ See LICENSE and COMMERCIAL in the project root for license information. package com.rebuild.server.helper.setup; import cn.devezhao.commons.CalendarUtils; -import com.rebuild.server.Application; import com.rebuild.server.helper.AesPreferencesConfigurer; import com.rebuild.server.helper.ConfigurableItem; import com.rebuild.server.helper.SysConfiguration; @@ -41,9 +40,9 @@ public class DatabaseBackup { * @throws IOException */ public File backup() throws IOException { - String url = Application.getBean(AesPreferencesConfigurer.class).getItem("db.url"); - String user = Application.getBean(AesPreferencesConfigurer.class).getItem("db.user"); - String passwd = Application.getBean(AesPreferencesConfigurer.class).getItem("db.passwd"); + String url = AesPreferencesConfigurer.getItem("db.url"); + String user = AesPreferencesConfigurer.getItem("db.user"); + String passwd = AesPreferencesConfigurer.getItem("db.passwd"); url = url.split("\\?")[0].split("//")[1]; String host = url.split(":")[0]; diff --git a/src/main/java/com/rebuild/server/helper/setup/InstallState.java b/src/main/java/com/rebuild/server/helper/setup/InstallState.java index acf600312..eb6f002de 100644 --- a/src/main/java/com/rebuild/server/helper/setup/InstallState.java +++ b/src/main/java/com/rebuild/server/helper/setup/InstallState.java @@ -22,7 +22,7 @@ import java.io.File; public interface InstallState { /** - * 状态文件位置 ~/.rebuild/.rebuild + * 安装文件位置 ~/.rebuild/.rebuild */ String INSTALL_FILE = ".rebuild"; diff --git a/src/main/java/com/rebuild/server/helper/setup/Installer.java b/src/main/java/com/rebuild/server/helper/setup/Installer.java index e1612918a..96157c60d 100644 --- a/src/main/java/com/rebuild/server/helper/setup/Installer.java +++ b/src/main/java/com/rebuild/server/helper/setup/Installer.java @@ -307,7 +307,7 @@ public class Installer implements InstallState { * @return */ public static boolean isUseH2() { - String dbUrl = Application.getBean(AesPreferencesConfigurer.class).getItem("db.url"); + String dbUrl = AesPreferencesConfigurer.getItem("db.url"); return dbUrl.startsWith("jdbc:h2:"); } } diff --git a/src/main/webapp/admin/system-general.jsp b/src/main/webapp/admin/system-general.jsp index c8d94c329..cc3088cfb 100644 --- a/src/main/webapp/admin/system-general.jsp +++ b/src/main/webapp/admin/system-general.jsp @@ -83,7 +83,7 @@ ${MarkWatermark ? "是" : "否"} - 数据库自动备份

每日0点备份到数据目录,请预留足够磁盘空间

+ 数据库自动备份

每日 0 点备份到数据目录,请预留足够磁盘空间

${DBBackupsEnable ? "是" : "否"} diff --git a/src/main/webapp/user/login.jsp b/src/main/webapp/user/login.jsp index a4853a59d..90669de40 100644 --- a/src/main/webapp/user/login.jsp +++ b/src/main/webapp/user/login.jsp @@ -102,7 +102,7 @@
${bundle.lang('NoAccountYet')} ${bundle.lang('SignupNow')}
-
+
From 691b594afd488c5cf53e2a07a6edc4bae594dd84 Mon Sep 17 00:00:00 2001 From: oahzeved Date: Wed, 29 Apr 2020 19:10:24 +0800 Subject: [PATCH 2/3] Use blank when ecrypting error --- src/main/java/com/rebuild/utils/AES.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rebuild/utils/AES.java b/src/main/java/com/rebuild/utils/AES.java index 3b9a13bf4..7ad670578 100644 --- a/src/main/java/com/rebuild/utils/AES.java +++ b/src/main/java/com/rebuild/utils/AES.java @@ -18,10 +18,11 @@ along with this program. If not, see . package com.rebuild.utils; -import com.rebuild.server.Application; import com.rebuild.server.RebuildException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; @@ -33,7 +34,9 @@ import javax.crypto.spec.SecretKeySpec; * @since 2017-1-2 */ public class AES { - + + private static final Log LOG = LogFactory.getLog(AES.class); + /** * @param input * @return @@ -51,14 +54,14 @@ public class AES { */ public static String encrypt(String input, String key) throws RebuildException { key = StringUtils.leftPad(key, 16, "0").substring(0, 16); - byte[] crypted = null; + byte[] crypted; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skey); crypted = cipher.doFinal(input.getBytes()); } catch (Exception ex) { - throw new RebuildException("加密失败", ex); + throw new RebuildException("Encrypting error : " + input, ex); } return new String(Base64.encodeBase64(crypted)); } @@ -80,14 +83,14 @@ public class AES { */ public static String decrypt(String input, String key) throws RebuildException { key = StringUtils.leftPad(key, 16, "0").substring(0, 16); - byte[] output = null; + byte[] output; try { SecretKeySpec skey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, skey); output = cipher.doFinal(Base64.decodeBase64(input)); } catch (Exception ex) { - throw new RebuildException("Decrypting Error", ex); + throw new RebuildException("Decrypting error : " + input, ex); } return new String(output); } @@ -100,8 +103,8 @@ public class AES { try { return decrypt(input); } catch (RebuildException ex) { - Application.LOG.warn("Decrypting Error! Use input: " + input); - return input; + LOG.warn("Decrypting error (Use blank input) : " + input); + return StringUtils.EMPTY; } } From d5bca262d2ace27dd4ae4a544945659bde289565 Mon Sep 17 00:00:00 2001 From: oahzeved Date: Wed, 29 Apr 2020 19:17:44 +0800 Subject: [PATCH 3/3] fix: debug mode --- src/main/java/com/rebuild/server/Application.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rebuild/server/Application.java b/src/main/java/com/rebuild/server/Application.java index ba2af948c..e954bf40b 100644 --- a/src/main/java/com/rebuild/server/Application.java +++ b/src/main/java/com/rebuild/server/Application.java @@ -18,6 +18,7 @@ import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.ToStringSerializer; import com.rebuild.api.ApiGateway; import com.rebuild.api.BaseApi; +import com.rebuild.server.helper.AesPreferencesConfigurer; import com.rebuild.server.helper.ConfigurableItem; import com.rebuild.server.helper.SysConfiguration; import com.rebuild.server.helper.cache.CommonCache; @@ -193,7 +194,8 @@ public final class Application { if (APPLICATION_CTX == null) { debugMode = true; LOG.info("Rebuild Booting in DEBUG mode ..."); - + + AesPreferencesConfigurer.initApplicationProperties(); long at = System.currentTimeMillis(); ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "application-ctx.xml" }); new Application(ctx).init(at);