Skip to content
Merged
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
4 changes: 4 additions & 0 deletions common/src/main/java/com/genexus/util/IniFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public void setPropertyEncrypted(String section, String key, String value) {

public String getPropertyEncrypted(String section, String key) {
String val = getProperty(section, key);
return decryptValue(val, key);
}

public String decryptValue(String val, String key) {
if (val != null) {
int checkSumLength = Encryption.getCheckSumLength();

Expand Down
5 changes: 5 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
<artifactId>opentelemetry-instrumentation-annotations</artifactId>
<version>${io.opentelemetry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>

<build>
Expand Down
53 changes: 53 additions & 0 deletions java/src/main/java/com/genexus/db/EncryptedDataSourceFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.genexus.db;

import com.genexus.specific.java.Connect;
import com.genexus.util.IniFile;
import org.apache.commons.dbcp2.BasicDataSourceFactory;

import javax.naming.Context;
import javax.naming.Name;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;

public class EncryptedDataSourceFactory implements ObjectFactory {

private final static String USERNAME = "username";
private final static String PASSWORD = "password";

@Override
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
if (obj instanceof Reference) {
Reference ref = (Reference) obj;
Properties properties = new Properties();

Enumeration<javax.naming.RefAddr> addresses = ref.getAll();
while (addresses.hasMoreElements()) {
javax.naming.RefAddr addr = addresses.nextElement();
properties.setProperty(addr.getType(), (String) addr.getContent());
}

IniFile config;
try {
Class<?> gxCfg = Class.forName(properties.getProperty("gxcfg"));
Connect.init();
config = com.genexus.ConfigFileFinder.getConfigFile(null, "client.cfg", gxCfg);
}
catch (Exception e) {
System.out.println("ERROR com.genexus.db.EncryptedDataSourceFactory - Could not found gxcfg Class");
return null;
}

String encryptedUsername = properties.getProperty(USERNAME);
properties.setProperty(USERNAME, config.decryptValue(encryptedUsername, "USER_ID"));

String encryptedPassword = properties.getProperty(PASSWORD);
properties.setProperty(PASSWORD, config.decryptValue(encryptedPassword, "USER_PASSWORD"));

return BasicDataSourceFactory.createDataSource(properties);
}
return null;
}
}
Loading