如果在Hibernate.cfg.xml配置的用户名和密码配置如下:
<!--连接数据库的用户名-->
<propertyname="connection.username">sa</property>
<!--连接数据库的密码-->
<propertyname="connection.password">123</property>
那怎么感觉都有点不爽,因为如果这样数据库的用户名和密码一下就给别人知道了,有极大的安全隐患,特别是金融系统中,这样的配置更应该避免。
我这里采用对Hibernate的源码进行修改的方式(当然这里的源码最好是和用户当前使用的Hibernate版本相一致,免得到时又引起版本不同的问题),以起到对连接的用户名和密码进行加密码的方式,修改右如下:
<!--连接数据库的用户名-->
<propertyname="connection.username">c92b81768388f76d</property>
<!--连接数据库的密码-->
<propertyname="connection.password">1f65866187612115</property>
准备一个Encode.java,该JAVA实现加密encode和解密方法decode,加密和解密是配对的,先用其加密方法encode对其加密处理,用户名和密码就成了上面的方式,将Encode.java放到org.hibernate.util包下,在类org.hibernate.connection.DriverManagerConnectionProvider的configure方法中,先加上对用户名和密码解密的程序,,加到该方法的最上面,如下:
publicvoidconfigure(Propertiesprops)throwsHibernateException{
Stringuser=props.getProperty(Environment.USER);
Stringpassword=props.getProperty(Environment.PASS);
try{
//对用户名进行解密
props.setProperty(Environment.USER,Encode.decode(user));
//对密码进行解密
props.setProperty(Environment.PASS,Encode.decode(password));
}catch(Exceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
//...
}
这里在后面的处理之前,先解密,就达到了加密解密的效果。
再打包发布就OK了。
分享到:
相关推荐
hibernate.cfg.xml hibernate框架的配置文件
Hibernate配置文件hibernate.cfg.xml中配置信息详解!
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好,可以在项目中放弃hibernate.cfg.xml文件,介绍mappingLocations、mappingDirectoryLocations与mappingJarLocations的用法和区别
Hibernate.cfg.xml配置总结
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
hibernate.cfg.xml文件详细解释收集的一个比较好的hibernate.cfg.xml文件解释
这是Hibernate的配置文件,hibernate.cfg.xml的具体写法,共友友们参考~~谢谢~
hibernate配置文件hibernate.cfg.xml的详细解释
(hibernate调用C3p0)hibernate.cfg.xml
hibernate.cfg.xml中配置信息详解
hibernate.cfg.xml中各节点的所有属性值,取自hibernate官网,纯天然无污染。原装!
NULL 博文链接:https://javawjy.iteye.com/blog/804577
JavaEE spring和Hibernate整合(没有hibernate.cfg.xml)