-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: How to keep database password out of configuration files
PostPosted: Thu Jan 31, 2008 6:33 pm 
Newbie

Joined: Thu Jan 31, 2008 6:18 pm
Posts: 4
Hi,

I have been building my first hibernate app and can't seem to find any references to secure password policies. It seems that everyone just puts their passwords in the configuration file.

We can't do this as our source control is viewable by many users - so my question is can I put a {placeholder} for a password in the config file(s) and populate them programmatically before invoking hibernate?

Thanks,

P


Top
 Profile  
 
 Post subject: Re: How to keep database password out of configuration files
PostPosted: Thu Jan 31, 2008 6:56 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
How about using a place holder? If you really need to use hibernate connection pool then you could put Ant style place holder and have ant filter those values for you at the build time.


Farzad-


Top
 Profile  
 
 Post subject: Re: How to keep database password out of configuration files
PostPosted: Thu Jan 31, 2008 6:58 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
farzad wrote:
How about using a place holder?


I meant how about a data source? My apologies.


Farzad-


Top
 Profile  
 
 Post subject: Re: How to keep database password out of configuration files
PostPosted: Sat Feb 02, 2008 8:07 am 
Newbie

Joined: Thu Jan 31, 2008 6:18 pm
Posts: 4
farzad wrote:
farzad wrote:
How about using a place holder?


I meant how about a data source? My apologies.


Farzad-


OK I've found some example fragments and it looks like I can use JNDI as follows:

Code:
Jdbc3PoolingDataSource source = new Jdbc3PoolingDataSource();
source.setDataSourceName("A Data Source");
source.setServerName("localhost");
source.setDatabaseName("test");
source.setUser("testuser");
source.setPassword("testpassword");
source.setMaxConnections(10);
new InitialContext().rebind("DataSource", source);
Then code to use a connection from the pool might look like this:
Connection con = null;
try {
    DataSource [color=brown]source [/color]= (DataSource)new InitialContext().lookup("DataSource");
    con = source.getConnection();
    // use connection
} catch (SQLException e) {
    // log error
} catch (NamingException e) {
    // DataSource wasn't found in JNDI
} finally {
    if (con != null) {
        try { con.close(); } catch (SQLException e) {}
    }
}



with hibernate config:

Code:
<session-factory
   name=java:comp/hibernate/SessionFactory">
   <property name="connection.datasource">
      jdbc/myDataSource
   </property>


My question is how to I get the hibernate config to see the reference I programmatically created to source?

Can you give example or amend my code.

Thanks

P


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 9:48 am 
Newbie

Joined: Tue Jan 15, 2008 10:07 am
Posts: 14
You need access to a JNDI service provider. Either run the application inside an application server of use a stand-alone JNDI service provider to bind and retrieve the datasource.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 02, 2008 11:27 am 
Newbie

Joined: Thu Jan 31, 2008 6:18 pm
Posts: 4
JelleKlap wrote:
You need access to a JNDI service provider. Either run the application inside an application server of use a stand-alone JNDI service provider to bind and retrieve the datasource.


How do I do that? I've not written an application server before (not even that confident what one is). Sounds like a stand-alone service provider is what I'd prefer (is this lighter?) - can you point me to how to use it this way and/or post an example.

Thanks,

P


Top
 Profile  
 
 Post subject: Re: How to keep database password out of configuration files
PostPosted: Sat Feb 02, 2008 4:23 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Why do you need to make is so complicate? If I understand correctly you just need to keep your password away from your version control repository. In that case just store passwords locally and have ant replace it for you at the build time.

Farzad-


Top
 Profile  
 
 Post subject: Re: How to keep database password out of configuration files
PostPosted: Sat Feb 02, 2008 7:06 pm 
Newbie

Joined: Thu Jan 31, 2008 6:18 pm
Posts: 4
farzad wrote:
Why do you need to make is so complicate? If I understand correctly you just need to keep your password away from your version control repository. In that case just store passwords locally and have ant replace it for you at the build time.

Farzad-


I can't deploy the password either - our production directories are again visible to many people. We have a secure mechanism for obtaining passwords from shell scripts and typically pass the usernames/passwords as environment variables into our program on invocation from autosys (all this is batch program by-the-way).

Slightly off topic but passwords are not the only things we might want to change. e.g. I write a lot of configuratable arguments to the scripts (using getopts) that provide target database servers (dev, test, qa, prod), logging level, target email notifications etc. We use spring and bind parameters to defer configuration options to allow use to alter application behaviour as needed, and we can use a single Spring application config file. I am essentially looking for the same pattern with Hibernate (for example I might want to switch off sql logging to focus on other activity).

Passwords is the most import however. Our environment as I say is (intentionally) open, so security around passwords is tightly controlled through the use of production IDs, so we need to be able to defer using passwords till the very last moment.

If we can configure a data source in java then 'inject' this into hibernate that would be the most ideal solution for us - hence the reason for this thread.

I'm not trying to over-complicate, if anything I want to avoid using application servers and other heavyweight approaches, but I still want the flexibility of allowing config from the command line, combined with the efficiencies of using Hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.