Skip to content

Commit

Permalink
Merge pull request #231 from ThalesGroup/redshift
Browse files Browse the repository at this point in the history
Redshift CRDP examples and other code optimizations along with GCP po…
  • Loading branch information
anugram authored Jul 16, 2024
2 parents 8d6fb7f + 2b7db0c commit b035a2a
Show file tree
Hide file tree
Showing 21 changed files with 3,586 additions and 158 deletions.
12 changes: 5 additions & 7 deletions database/bigquery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
<groupId>Thales</groupId>
<artifactId>CADP-GCP-BigQuery-UDF</artifactId>
<version>0.0.2-SNAPSHOT</version>






<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand All @@ -30,7 +24,6 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down Expand Up @@ -80,6 +73,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.functions</groupId>
Expand Down
Binary file not shown.
5 changes: 5 additions & 0 deletions database/redshift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static void main(String[] args) throws Exception {
String cmip = args[2];
String usersetid = args[3];
String filePath = args[4];
// CMUserSetHelper("716f01a6-5cab-4799-925a-6dc2d8712fc1","20.241.70.238");

//CMUserSetHelper("32d89a8d-efac-4c50-9b53-f51d0c03413e",
CMUserSetHelper cmusersetHelper = new CMUserSetHelper(usersetid,
cmip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* to protect sensitive data in a column. This example uses
* Format Preserve Encryption (FPE) to maintain the original format of the data
* so applications or business intelligence tools do not have to change in order
* to use these columns. There is no need to deploy a function to run it.
* to use these columns.
*
* Note: This source code is only to be used for testing and proof of concepts.
* Not production ready code. Was not tested for all possible data sizes and
Expand Down Expand Up @@ -113,7 +113,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// 1 will return cipher text
// null will return error.
String returnciphertextforuserwithnokeyaccess = System.getenv("returnciphertextforuserwithnokeyaccess");
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.matches("-?\\d+"); // Using regular
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.equalsIgnoreCase("yes");

// usersetlookup = should a userset lookup be done on the user from Big Query? 1
// = true 0 = false.
Expand All @@ -124,7 +124,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// is
// the userset in CM but could be a memcache or other in memory db.
String userSetLookupIP = System.getenv("usersetlookupip");
boolean usersetlookupbool = usersetlookup.matches("-?\\d+");
boolean usersetlookupbool = usersetlookup.equalsIgnoreCase("yes");

try {

Expand All @@ -138,26 +138,14 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
redshiftreturndata.append(" \"results\": [");

if (usersetlookupbool) {
// Convert the string to an integer
int num = Integer.parseInt(usersetlookup);
// make sure cmuser is in Application Data Protection Clients Group
if (num >= 1) {
boolean founduserinuserset = true;
try {
founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);
// make sure cmuser is in Application Data Protection Clients Group

}
boolean founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);

else
usersetlookupbool = false;
} else {
usersetlookupbool = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* to protect sensitive data in a column. This example uses
* Format Preserve Encryption (FPE) to maintain the original format of the data
* so applications or business intelligence tools do not have to change in order
* to use these columns. There is no need to deploy a function to run it.
* to use these columns.
*
* Note: This source code is only to be used for testing and proof of concepts.
* Not production ready code. Was not tested for all possible data sizes and
Expand Down Expand Up @@ -139,7 +139,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// 1 will return cipher text
// null will return error.
String returnciphertextforuserwithnokeyaccess = System.getenv("returnciphertextforuserwithnokeyaccess");
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.matches("-?\\d+"); // Using regular
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.equalsIgnoreCase("yes");

// usersetlookup = should a userset lookup be done on the user from Big Query? 1
// = true 0 = false.
Expand All @@ -150,7 +150,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// is
// the userset in CM but could be a memcache or other in memory db.
String userSetLookupIP = System.getenv("usersetlookupip");
boolean usersetlookupbool = usersetlookup.matches("-?\\d+");
boolean usersetlookupbool = usersetlookup.equalsIgnoreCase("yes");
int batchsize = Integer.parseInt(System.getenv("BATCHSIZE"));
if (batchsize >= BATCHLIMIT)
batchsize = BATCHLIMIT;
Expand Down Expand Up @@ -178,26 +178,14 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
redshiftreturndatasb.append(" \"results\": [");

if (usersetlookupbool) {
// Convert the string to an integer
int num = Integer.parseInt(usersetlookup);
// make sure cmuser is in Application Data Protection Clients Group
if (num >= 1) {
boolean founduserinuserset = true;
try {
founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);
// make sure cmuser is in Application Data Protection Clients Group

}
boolean founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);

else
usersetlookupbool = false;
} else {
usersetlookupbool = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* to protect sensitive data in a column. This example uses
* Format Preserve Encryption (FPE) to maintain the original format of the data
* so applications or business intelligence tools do not have to change in order
* to use these columns. There is no need to deploy a function to run it.
* to use these columns.
*
* Note: This source code is only to be used for testing and proof of concepts.
* Not production ready code. Was not tested for all possible data sizes and
Expand Down Expand Up @@ -112,7 +112,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// 1 will return cipher text
// null will return error.
String returnciphertextforuserwithnokeyaccess = System.getenv("returnciphertextforuserwithnokeyaccess");
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.matches("-?\\d+"); // Using regular
boolean returnciphertextbool = returnciphertextforuserwithnokeyaccess.equalsIgnoreCase("yes");

// usersetlookup = should a userset lookup be done on the user from Big Query? 1
// = true 0 = false.
Expand All @@ -123,7 +123,7 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
// is
// the userset in CM but could be a memcache or other in memory db.
String userSetLookupIP = System.getenv("usersetlookupip");
boolean usersetlookupbool = usersetlookup.matches("-?\\d+");
boolean usersetlookupbool = usersetlookup.equalsIgnoreCase("yes");

try {

Expand All @@ -137,26 +137,14 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
redshiftreturndata.append(" \"results\": [");

if (usersetlookupbool) {
// Convert the string to an integer
int num = Integer.parseInt(usersetlookup);
// make sure cmuser is in Application Data Protection Clients Group
if (num >= 1) {
boolean founduserinuserset = true;
try {
founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);
// make sure cmuser is in Application Data Protection Clients Group

}
boolean founduserinuserset = findUserInUserSet(redshiftuserstr, userName, password, usersetID,
userSetLookupIP);
// System.out.println("Found User " + founduserinuserset);
if (!founduserinuserset)
throw new CustomException("1001, User Not in User Set", 1001);

else
usersetlookupbool = false;
} else {
usersetlookupbool = false;
}
Expand Down Expand Up @@ -292,7 +280,7 @@ public String doTransform(Cipher encryptCipher, JsonArray redshiftdata, StringBu
byte[] outbuf = encryptCipher.doFinal(sensitive.getBytes());
encdata = new String(outbuf);

System.out.println("Sensitive data: " + sensitive);

}
}
} else {
Expand Down
Loading

0 comments on commit b035a2a

Please sign in to comment.