How to store sensitive data in Java configuration files?

I have a code that I want to publish. The code sends e-mail through servers, connects to databases and other tasks requiring usernames / passwords.

I would like to store passwords, etc. in a separate configuration file, so I don’t need to sanitize my code with every commit.

How can i do this? This would be easy to do in C using #define, but I'm not sure how to do it in Java.

EDIT: The environment I use is Glassfish

+3
source share
2 answers

Properties . J2EE, , .

, , , , J2EE, . "" , javadoc load().

+8

, . . JDBC Resources , . jdbc/myappname.

J2EE5 :

@Resource (mappedName = "jdbc/myappname" ) DataSource myDS;

. , , :

conn = myDS.getConnection();

. , . , , , , EJB, , JSF bean.

+1

Source: https://habr.com/ru/post/1775322/


All Articles