When developing enterprise applications it is best practice check in the source code into a version control system. Additionally to the code also configuration settings and credentials are often checked in.
This is usually no problem for test environments, but configurations for the production environments perhaps should not be readable for everyone having access to the version control system.
This can be solved using some type of access control on the version control system.
Or the credentials can be entered as parameters during the build or deployment for production. That is only a feasible solution for one or two credentials.
An other solution is to encrypt the confidential data and decrypt it with a master password. This solution is supported by the java library jasypt.
Credits for the basic implementation with ant goes to my former colleague Mr. Wiedemann. I have adapted the solution for the use with Maven.
Jasypt doesn’t provide a Maven plugin. That’s why we need some type of glue code to use the jasypt library. We use the language groovy to write the glue code. For Maven there exists a plugin to execute groovy code in an easy way. The final solutions looks like this:
If the property jasypt.encryption.password is not set the plugin prints an info message and does nothing. Otherwise the plugin decrypts every encrypted property and replaces the value with the decrypted value. The encryption of the value can be done with the command line. The encrypted value has to be embedded into ENC(). Finally the property looks like this:
At the dependencies section we add the library of jasypt. The plugin should run during the validate phase.