WASdev / standards.jsr352.jbatch

Home of 'jbatch', a compatible implementation of the Jakarta Batch specification (and the former Reference Implementation for the JSR 352, Batch Applications for the Java Platform specification).
Other
21 stars 18 forks source link

How to provide database username and password in SE mode? #72

Closed m1h43l closed 3 years ago

m1h43l commented 3 years ago

It seems that in SE mode the only way to set the username and password for the database config is the provide the creds in the batch-config.properties file.

I would rather have them additionally read from System Properties or environment variables.

How to provide the credentials for database access in a flexible way without the need to hardcode it in a properties file and repackage the application?

scottkurz commented 3 years ago

Hi @m1h43l ,

I don't think there is a way to do this currently as-is.

I'm hesitant to add new config options since the options that exist are already one-off options unique to the jbatch impl and not especially following any common, well-known patterns.

One option a user could do would be to configure the jbatch runtime themselves programmatically using its SPI.

E.g. you could extend DatabaseConfigurationBean with MyDatabaseConfigurationBeanExt and do something like this

        BatchSPIManager batchSPIManager = BatchSPIManager.getInstance();
        DatabaseConfigurationBean databaseConfigurationBean = new MyDatabaseConfigurationBeanExt();
        batchSPIManager.registerDatabaseConfigurationBean(databaseConfigurationBean);

If you do this early, before jbatch "hardens" its initialization based on its config you should be able to implement a bean providing userid/password from env vars or sysprops.

How does that sound?

m1h43l commented 3 years ago

implement a bean providing userid/password from env vars or sysprops.

Actually this is one of the options I was also thinking about. Thanks for confirming this approach.