Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions maven-dbdeploy-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>dbdeploy-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File;

import org.apache.maven.plugin.AbstractMojo;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;

import com.dbdeploy.DbDeploy;
import com.dbdeploy.database.DelimiterType;
import com.dbdeploy.database.LineEnding;
import org.apache.maven.plugin.AbstractMojo;

import java.io.File;

/**
* Abstract class that all dbdeploy database goals should extend.
Expand Down Expand Up @@ -121,7 +123,7 @@ protected DbDeploy getConfiguredDbDeploy() {
dbDeploy.setScriptdirectory(scriptdirectory);
dbDeploy.setDriver(driver);
dbDeploy.setUrl(url);
dbDeploy.setPassword(password);
dbDeploy.setPassword(getPassword());
dbDeploy.setUserid(userid);

if (encoding != null) {
Expand Down Expand Up @@ -150,4 +152,35 @@ protected DbDeploy getConfiguredDbDeploy() {

return dbDeploy;
}

private String getPassword() {
return isEncrypted(password) ? unwrapAndDecrypt(password) : password;
}

private boolean isEncrypted(String password) {
return password != null && password.startsWith("ENC(") && password.endsWith(")");
}

private String unwrapAndDecrypt(String password) {
return decrypt(unwrap(password));
}

private String unwrap(String password) {
return password.substring(4, password.length() - 1);
}

private String decrypt(String encrypted) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
String encryptionKey = System.getProperty("encryptionKey");
if (encryptionKey == null || encryptionKey.trim().isEmpty()) {
throw new IllegalArgumentException("VM property 'encryptionKey' must be set when using encrypted password.");
}
encryptor.setPassword(encryptionKey);

try {
return encryptor.decrypt(encrypted);
} catch (Exception e) {
throw new RuntimeException("There was an error decrypting the password. Make sure it is a valid encrypted password.", e);
}
}
}