java - Best practice to provide MySQL JDBC driver password -


i have jsp web application deployed in tomcat7 server use mysql database. in database connection i'm providing clear text username , password below.

connection conn = drivermanager.getconnection("jdbc:mysql://hostname:3306/schema", "user", "password"); 

as security requirement cannot use plain text passwords in code , cannot use configuration files store information ether has in database somewhere.

q1 issue can provide hashed input password field in connection string.?

q2 if can't use file based configuration method best way store sensitive information.?

the best approach define jdbc datastore in tomcat , in web application. following samples shamelessly copied tomcat documentation. way not have passwords in applicaion. configuration done tomcat administrator, not web application developer.

context:

<resource name="jdbc/testdb" auth="container" type="javax.sql.datasource"            maxactive="100" maxidle="30" maxwait="10000"            username="javauser" password="javadude"             driverclassname="com.mysql.jdbc.driver"            url="jdbc:mysql://localhost:3306/javatest"/> 

web.xml

<resource-ref>   <description>db connection</description>   <res-ref-name>jdbc/testdb</res-ref-name>   <res-type>javax.sql.datasource</res-type>   <res-auth>container</res-auth> </resource-ref> 

test.jsp

<sql:query var="rs" datasource="jdbc/testdb">    select id, foo, bar testdata </sql:query> 

servlet

context initcontext = new initialcontext(); context envcontext  = (context)initcontext.lookup("java:/comp/env"); datasource ds = (datasource)envcontext.lookup("jdbc/testdb"); connection conn = ds.getconnection(); 

regarding security requirements: harder, because password plaintext there well. can limit access rights web container can read it. encrypting password not work symmetrical ciphers because attacker can them well. , asymmetrical ciphers - can decode key too. must set environment attacker not see content of configuration files. if root, lost anyway.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -