You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by vinbr88 <vi...@googlemail.com> on 2012/05/29 15:16:18 UTC

Get database password for persistence.xml from external file

Hello,

my application is using the persistence.xml for connecting to our Oracle
test database. The password is inserted there like this:

<properties>
	<property name="openjpa.ConnectionDriverName"
		value="oracle.jdbc.driver.OracleDriver" />
	<property name="openjpa.ConnectionURL"
		value="jdbc:oracle:thin:@XX.XXX.XXX.XXX:XXXX:DBNAME " />
	<property name="openjpa.ConnectionUserName" value="ADMIN" />
	<property name="openjpa.ConnectionPassword" value="test" />
</properties>

On the target system, the database password changes every 90 days. The
system automatically creates a property file for every user on the Linux
file system with his new password in there. Our applications read and use
the password of this property file on the file system.

Is there a possibility to use this file for connecting to the database via
openJPA/Oracle JDBC driver. Or do you know a possibility to import the
password of the property file into the persistence.xml?

Thank you in advance.

Vince


--
View this message in context: http://openjpa.208410.n2.nabble.com/Get-database-password-for-persistence-xml-from-external-file-tp7579412.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Get database password for persistence.xml from external file

Posted by vinbr88 <vi...@googlemail.com>.
Hi,

I didn't try the Encryption Provider method, but the map method solved my
problem:

Map<String, String> dbProperties = new HashMap<String, String>();

dbProperties.put("openjpa.ConnectionUserName", dbUserName);
dbProperties.put("openjpa.ConnectionPassword", dbPassword);

EntityManagerFactory factory =
Persistence.createEntityManagerFactory(ENTITY_MANAGER_FACTORY,
dbProperties);

Here you can find an example:
http://foobar.lu/wp/2010/12/30/change-jpa-entitymanager-connection-properties-at-runtime/

Thank you all for your help.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Get-database-password-for-persistence-xml-from-external-file-tp7579412p7580268.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Get database password for persistence.xml from external file

Posted by vinbr88 <vi...@googlemail.com>.
Creating an EntityManagerFactory with properties Map will solve my problem I
think.

But will try the EncryptionProvider Method. I think this brings a few
advantages, but I've never done this before. I hope I find an example or
something like that.

The resutls will be posted here.

Thanks.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Get-database-password-for-persistence-xml-from-external-file-tp7579412p7579796.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Get database password for persistence.xml from external file

Posted by vinbr88 <vi...@googlemail.com>.
Creating an EntityManagerFactory with properties Map will solve my problem I
think.

But will try the EncryptionProvider Method. I think this brings a few
advantages, but I've never done this before. I hope I find an example or
something like that.

The resutls will be posted here.

Thanks.

--
View this message in context: http://openjpa.208410.n2.nabble.com/Get-database-password-for-persistence-xml-from-external-file-tp7579412p7579797.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Get database password for persistence.xml from external file

Posted by Rick Curtis <cu...@gmail.com>.
Vince -

Take a look at the encryption provider[1]. You wouldn't be using it as
intended, but it think it could do the trick.

You'll need to implement the
org.apache.openjpa.lib.encryption.EncryptionProvider interface and whenever
.decrypt(...) is called, go find your properties file and return the
password String value.

Let us know how it goes.

Thanks,
Rick

[1]
http://openjpa.apache.org/builds/latest/docs/docbook/manual.html#ref_guide_encryption

On Tue, May 29, 2012 at 8:16 AM, vinbr88 <vi...@googlemail.com> wrote:

> Hello,
>
> my application is using the persistence.xml for connecting to our Oracle
> test database. The password is inserted there like this:
>
> <properties>
>        <property name="openjpa.ConnectionDriverName"
>                value="oracle.jdbc.driver.OracleDriver" />
>        <property name="openjpa.ConnectionURL"
>                value="jdbc:oracle:thin:@XX.XXX.XXX.XXX:XXXX:DBNAME " />
>        <property name="openjpa.ConnectionUserName" value="ADMIN" />
>        <property name="openjpa.ConnectionPassword" value="test" />
> </properties>
>
> On the target system, the database password changes every 90 days. The
> system automatically creates a property file for every user on the Linux
> file system with his new password in there. Our applications read and use
> the password of this property file on the file system.
>
> Is there a possibility to use this file for connecting to the database via
> openJPA/Oracle JDBC driver. Or do you know a possibility to import the
> password of the property file into the persistence.xml?
>
> Thank you in advance.
>
> Vince
>
>
> --
*Rick Curtis*

Re: Get database password for persistence.xml from external file

Posted by Georgi Naplatanov <go...@oles.biz>.
Hi.

You can mix properties in persistence.xml file and additional 
properties. Look at

public static EntityManagerFactory createEntityManagerFactory(String 
persistenceUnitName,Map properties)

method.

HTH

Best regards
Georgi

On 05/29/2012 04:16 PM, vinbr88 wrote:
> Hello,
>
> my application is using the persistence.xml for connecting to our Oracle
> test database. The password is inserted there like this:
>
> <properties>
> 	<property name="openjpa.ConnectionDriverName"
> 		value="oracle.jdbc.driver.OracleDriver" />
> 	<property name="openjpa.ConnectionURL"
> 		value="jdbc:oracle:thin:@XX.XXX.XXX.XXX:XXXX:DBNAME " />
> 	<property name="openjpa.ConnectionUserName" value="ADMIN" />
> 	<property name="openjpa.ConnectionPassword" value="test" />
> </properties>
>
> On the target system, the database password changes every 90 days. The
> system automatically creates a property file for every user on the Linux
> file system with his new password in there. Our applications read and use
> the password of this property file on the file system.
>
> Is there a possibility to use this file for connecting to the database via
> openJPA/Oracle JDBC driver. Or do you know a possibility to import the
> password of the property file into the persistence.xml?
>
> Thank you in advance.
>
> Vince
>
>
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Get-database-password-for-persistence-xml-from-external-file-tp7579412.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.