Hi Randy,

I'm using TomEE substitution in tomee.xml for this, here is some example:

<Resource id="someDS" type="javax.sql.DataSource">
        JdbcDriver   = org.postgresql.Driver
        JdbcUrl      = ${SOME_DS_URL}
        UserName     = ${SOME_DS_USER}
        Password     = ${SOME_DS_PASSWORD}
        //all other data source config properties
    </Resource>

Where SOME_DS_URL, SOME_DS_USER and SOME_DS_PASSWORD are env variables 
available for the TomEE process.

Cheers,
Dmitry

-----Original Message-----
From: randygalbraith [mailto:regalbra...@aetna.com.INVALID] 
Sent: Monday, December 2, 2019 12:59 PM
To: users@tomee.apache.org
Subject: Supplying a JDBC password at run-time.

I am looking for advice on the best way to supply an Oracle password at 
run-time. When our application connects to Oracle it uses a password that is 
provided from a password store. The password itself is updated every 60 days.

My current WEB-INF/resources.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <Resource id="ID" type="javax.sql.DataSource">
      JdbcDriver = oracle.jdbc.OracleDriver
      JdbcUrl = jdbc:oracle:thin:@HOST:PORT:DBNAME
      JtaManaged = true
      UserName = TheUserId
      Password = PlainTextPassword
  </Resource>
</resources>


My test.jsp test harness within my .war file looks like this:

<%@ taglib 
uri="https://urldefense.com/v3/__http://java.sun.com/jsp/jstl/sql__;!LLC3CZw_jFA!M-74VSVl1d3oPky2Z3L3OvGfe57WrO0A_yKFRaotilRPddsn-tUCzLQLntpKoX8kbnHS$
 " prefix="sql" %> <%@ taglib 
uri="https://urldefense.com/v3/__http://java.sun.com/jsp/jstl/core__;!LLC3CZw_jFA!M-74VSVl1d3oPky2Z3L3OvGfe57WrO0A_yKFRaotilRPddsn-tUCzLQLntpKoQCuEW1q$
 " prefix="c" %>

<sql:query var="rs" dataSource="ID">
select col1, col2 from schema.table where id > 3081915 </sql:query>

<html>
  <head>
    <title>DB Test</title>
  </head>
  <body>

<c:forEach var="row" items="${rs.rows}">
    row.col1=${row.col1}<br/>
    row.col2=${row.col2}<br/>
</c:forEach>

  </body>
</html>

This all works. What I now need to do is supply the value of PlainTextPassword 
dynamically at run-time. I have added code to test.jsp that demonstrates my 
ability to retrieve the password from our custom password store. Alas, I am 
unsure how to apply it to the dataSource.

Reading through the TomEE documentation suggests I need to understand how to 
use JNDI to access the dataSource resource. Then I should be able to 
dynamically provide the password. I will begin to push in that direction.

Thanks in advance to any who respond. If my research lands on a solution I will 
drop by and document what I find.

Version info (from catalina.out):

Server version: Apache Tomcat (TomEE)/9.0.12 (8.0.0-M2)
Server built:   Sep 4 2018 22:13:41 UTC
Server number:  9.0.12.0
OS Name:        Linux
OS Version:     3.10.0-1062.1.2.el7.x86_64
Architecture:   amd64
Java Home:      /path-on-host/jdk-11.0.2
JVM Version:    11.0.2+7

Kind regards,
-Randy Galbraith




--
Sent from: 
https://urldefense.com/v3/__http://tomee-openejb.979440.n4.nabble.com/TomEE-Users-f979441.html__;!LLC3CZw_jFA!M-74VSVl1d3oPky2Z3L3OvGfe57WrO0A_yKFRaotilRPddsn-tUCzLQLntpKoQic8ZAp$
 

Reply via email to