On 27/03/2025 14:54, William Crowell wrote:
Sebastian,
Thanks for your reply. I did know about environment variables. I would be
concerned about someone doing a “ps -ef” on the box and getting the password
from the command line arguments. I will keep looking.
Write a small class that implements IntrospectionUtils.PropertySource
and reads your property file.
Configure as per:
https://tomcat.apache.org/tomcat-11.0-doc/config/systemprops.html#Property_replacements
Might be sufficiently generally useful to add to the other
implementations in org.apache.tomcat.util.digester
Note that catalina.properties is read and the properties are added as
system properties. The SystemPropertySource then finds them for the
Digester.
Mark
Regards,
William Crowell
From: Sebastian Trost <m...@sebastiantrost.de.INVALID>
Date: Thursday, March 27, 2025 at 9:53 AM
To: users@tomcat.apache.org <users@tomcat.apache.org>
Subject: Re: Additional Property File For Substitution Variables
William,
On 27.03.2025 14:39, William Crowell wrote:
Is there a way to add an additional properties file to the startup of Apache
Tomcat, so that server.xml and context.xml can reference the values like we do
with catalina.properties?
For instance:
application.properties:
my.user=foo
my.password=bar
context.xml:
…
<Resource … " type="javax.sql.DataSource" … username="${my.user}"
password="${my.password}” …
/>
…
[...]
You can use environment variables (and setenv.sh/.bat). Example:
Set your environment variable:
> export USER_NAME=user1
Modify / create setenv.sh:
JAVA_OPTS=-Dcustom_user_name=${USER_NAME}
Modify your context.xml:
[...] <Resource … " type="javax.sql.DataSource" …
username="${custom_user_name}" [...]
I didn't test it, but it should work like this.
Reference:
https://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F44761831%2Ftomcat-8-context-xml-use-environment-variable-in-datasource&data=05%7C02%7CWCrowell%40perforce.com%7Ce2e937739a6740052d3608dd6d36b2e1%7C95b666d19a7549ab95a38969fbcdc08c%7C0%7C0%7C638786803907292634%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=WSI4V4Kpep8wXy295CZ%2BeNseW7a1Scd9%2B5dc3YYKf9k%3D&reserved=0<https://stackoverflow.com/questions/44761831/tomcat-8-context-xml-use-environment-variable-in-datasource>
Sebastian
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
CAUTION: This email originated from outside of the organization. Do not click
on links or open attachments unless you recognize the sender and know the
content is safe.
This e-mail may contain information that is privileged or confidential. If you
are not the intended recipient, please delete the e-mail and any attachments
and notify us immediately.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org