简体   繁体   中英

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. 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:

 <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.

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! I tried using the JNDI route. Here are the settings to get it to work:

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)

<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. That way the password is not stored in your version control and can be only accessed / changed in the container ( tomcat, jboss, websphere & etc ). See Tomcat JNDI How-To for a sample & details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM