[英]Where is DB connection located for JPA using persistence.xml?
I was trying to use jasypt to encrypt/decrypt passwords in my persistence.xml but thats not working too good. 我试图使用jasypt来加密/解密persistence.xml中的密码,但这不能很好地工作。 Sooo.. I figured maybe I can do it myself.
如此..我想也许我可以自己做。 My problem is not knowing where the db account is accessed so I can get a handle to it.
我的问题是不知道在哪里访问数据库帐户,因此我可以处理它。 Here is the password in my persistence.xml:
这是我的persistence.xml中的密码:
<property name="hibernate.connection.password" value="mydbpassword" />
This works find and the app connects to the database. 这可以找到并且应用程序连接到数据库。 When I do a grep of hibernate.connection.password the only hits are the persistence.xml.
当我执行hibernate.connection.password的grep时,唯一的命中是persistence.xml。
Does anyone know where in the code I could get a handle to this to manually decrypt and encrypted password? 有谁知道在代码中的哪个位置可以手动处理解密和加密的密码?
thanks! 谢谢!
UPDATE2 - Got it Working! UPDATE2-可以正常工作! I tried using the JNDI route.
我尝试使用JNDI路由。 Here are the settings to get it to work:
以下是使其生效的设置:
persistence.xml persistence.xml
<persistence-unit name="MyApp" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/myDB</jta-data-source>
<properties>
<property name="hibernate.connection.datasource" value="java:/myDB" />
oracle-ds.xml (in jboss deploy directory) oracle-ds.xml(在jboss部署目录中)
<datasources>
<local-tx-datasource>
<jndi-name>/myDB</jndi-name>
<use-java-context>true</use-java-context>
<connection-url>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=foo.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SID=myDB)))
</connection-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<user-name>user1</user-name>
<password>userpass</password>
Normally you should not set the password in your persistence.xml
but rather doing it over JNDI
and setting it in the container configuration. 通常,您不应在
persistence.xml
设置密码,而应通过JNDI
进行设置并在容器配置中进行设置。 That way the password is not stored in your version control and can be only accessed / changed in the container ( tomcat, jboss, websphere & etc ). 这样,密码就不会存储在版本控制中,并且只能在容器(tomcat,jboss,websphere等)中访问/更改。 See Tomcat JNDI How-To for a sample & details
有关示例和详细信息,请参见Tomcat JNDI How-To 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.