Encrypt tool and Decrypt

This commit is contained in:
xiaoyu830411
2012-08-31 13:57:44 +08:00
parent 6290be2561
commit e19def644d
5 changed files with 41 additions and 33 deletions
@@ -67,10 +67,24 @@ import java.util.Properties;
* <property name="connectionProperties" value="config.file=http://localhost:8080/remote.propreties; />
* </bean>
*
* [使用系统属性配置远程文件]
* java -Ddruid.config.file=file:/home/test/my.properties ...
*
* 远程配置文件格式:
* 1. 其他的属性KEY请查看 @see com.alibaba.druid.pool.DruidDataSourceFactory
* 2. config filter 相关设置:
* config.xxxxx=yyyyy
* #远程文件路径
* config.file=http://xxxxx(http://开头或者file:开头)
*
* #AES解密, key不指定, 使用默认的
* config.decrypt=AES
* config.decrypt.key=abcdfeg
*
* #RSA解密, Key不指定, 使用默认的
* config.decrypt=RSA
* config.decrypt.key=密钥字符串
* config.decrypt.keyFile=密钥文件路径
* config.decrypt.x509File=证书路径
*
* </pre>
*/
@@ -78,9 +92,11 @@ public class ConfigFilter extends FilterAdapter {
private static Log log = LogFactory.getLog(ConfigFilter.class);
public final static String CONFIG_FILE = "config.file";
public static final String CONFIG_FILE = "config.file";
public final static String CONFIG_DECRYPT = "config.decrypt";
public static final String CONFIG_DECRYPT = "config.decrypt";
public static final String SYS_PROP_CONFIG_FILE = "druid.config.file";
public ConfigFilter(){
}
@@ -97,7 +113,12 @@ public class ConfigFilter extends FilterAdapter {
//获取远程配置文件
String protocol = connectinProperties.getProperty(CONFIG_FILE);
if (protocol != null) {
//如果系统参数有指定
if (protocol == null) {
protocol = System.getProperty(SYS_PROP_CONFIG_FILE);
}
if (protocol != null && protocol.length() > 0) {
if (log.isDebugEnabled()) {
log.debug("Config file will be load from [" + protocol + "].");
}
@@ -23,7 +23,6 @@ public class FileConfigLoader implements ConfigLoader {
private static Log LOG = LogFactory.getLog(FileConfigLoader.class);
public static final String PROTOCOL_PREFIX = "file:";
public static final String SYS_PROP_CONFIG_FILE = "druid.config.file";
@Override
public String getId() {
@@ -80,11 +79,7 @@ public class FileConfigLoader implements ConfigLoader {
String getFilePath(String protocol) {
String filePath = null;
if(protocol == null) {
filePath = System.getProperty(SYS_PROP_CONFIG_FILE);
} else {
filePath = protocol.substring(PROTOCOL_PREFIX.length());
}
filePath = protocol.substring(PROTOCOL_PREFIX.length());
return filePath;
}
@@ -95,10 +90,6 @@ public class FileConfigLoader implements ConfigLoader {
@Override
public boolean isSupported(String protocol) {
if (protocol == null) {
return System.getProperty(SYS_PROP_CONFIG_FILE) != null;
}
return protocol.toLowerCase().startsWith(PROTOCOL_PREFIX);
}
}