服务器:JBOSS 5.x 以下功能是用我的会话 bean 编写的(ejb3 架构)
@Remote(OracleDsInteractionRemote.class)
@Local(OracleDsInteractionLocal.class)
@Stateless
@RemoteBinding(jndiBinding="OracleDsInteractionBean/remote")
@LocalBinding(jndiBinding="OracleDsInteractionBean/local")
public class OracleDsInteractionBean implements OracleDsInteractionRemote,OracleDsInteractionLocal
{
@EJB
@Resource(mappedName="java:/EncryptedDS")
private DataSource ds1;
public int getAllValues() throws Exception
{
System.out.println("************************* ");
Connection conn = ds1.getConnection();
Statement st = conn.createStatement();
String query = "SELECT count(*) FROM DETAILS_DATA";
ResultSet rs = st.executeQuery(query);
while (rs.next())
{
return rs.getInt(1);
}
return -1;
}
}
此函数使用 jdbc 连接从 details_data 表中检索行数。数据源对象 ds1 映射为“EncryptedDS”。“EncryptedDS”的条目在 oracle-ds.xml 中定义如下。
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===================================================================== -->
<!-- -->
<!-- JBoss Server Configuration -->
<datasources>
<xa-datasource>
<jndi-name>EncryptedDS</jndi-name>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:oracle:thin:@182.158.93.26:1521:dbSid</xa-datasource-property>
<xa-datasource-property name="User">Test</xa-datasource-property>
<xa-datasource-property name="Password">pass123</xa-datasource-property>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>Oracle11g</type-mapping>
</metadata>
</xa-datasource>
</datasources>
但问题是任何人都可以进入 $JBOSS_HOME/server/default/deploy 目录并从 oracle-ds.xml 中找到“EncryptedDS”配置。(在 oracle-ds.xml 中,完整的数据库信息以文本形式写入(DatabaseServerIP,Port ,Sid,SchemaName,SchemaPassword))... 如何在 oracle-ds.xml 中存储加密的数据库信息?我的 java 代码将如何解码以建立 jdbc 连接?