@wenshao 你好,想跟你请教个问题:我实现一个DruidPasswordCallback子类,并配置到dataSource的property中:
<property name="passwordCallback" >
<bean class="utils.DBPasswordCallback" />
</property>
DBPasswordCallback类实现:
public class DBPasswordCallback extends DruidPasswordCallback {
/**
* serialVersionUID
*/
private static final long serialVersionUID = 1L;
@Override
public void setProperties(Properties properties)
{
super.setProperties(properties);
String pwd = properties.getProperty("password");
if (!StringUtil.isTrimEmpty(pwd)) {
try {
setPassword(EncryptUtil.decrypt2AES(pwd).toCharArray());
} catch (Exception e) {
setPassword(pwd.toCharArray());
}
}
}
}
可是无法解密。 调试时发现properties是空的({}),取不到jdbc配置的原始密码,所以后面的操作也就没有意义了。 大家知道正确的做法吗?
Druid版本1.0.2
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
有人知道吗?######
可以扩展Spring的PropertyPlaceholderConfigurer,摘录别人一段代码你参考
public class DecryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
/**
* 重写父类方法,解密指定属性名对应的属性值
*/
@Override
protected String convertProperty(String propertyName,String propertyValue){
if(isEncryptPropertyVal(propertyName)){
return DesUtils.getDecryptString(propertyValue);//调用解密方法
}else{
return propertyValue;
}
}
/**
* 判断属性值是否需要解密,这里我约定需要解密的属性名用encrypt开头
* @param propertyName
* @return
*/
private boolean isEncryptPropertyVal(String propertyName){
if(propertyName.startsWith("encrypt")){
return true;
}else{
return false;
}
}
}
可以扩展Spring的PropertyPlaceholderConfigurer,摘录别人一段代码你参考
public class DecryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{
/**
* 重写父类方法,解密指定属性名对应的属性值
*/
@Override
protected String convertProperty(String propertyName,String propertyValue){
if(isEncryptPropertyVal(propertyName)){
return DesUtils.getDecryptString(propertyValue);//调用解密方法
}else{
return propertyValue;
}
}
/**
* 判断属性值是否需要解密,这里我约定需要解密的属性名用encrypt开头
* @param propertyName
* @return
*/
private boolean isEncryptPropertyVal(String propertyName){
if(propertyName.startsWith("encrypt")){
return true;
}else{
return false;
}
}
}