summaryrefslogtreecommitdiffstats
path: root/sql-resource
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-09-22 19:48:31 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-22 19:48:31 +0000
commitbb8927cc8d8249bc8aadd78c3f8105cf3e309bb7 (patch)
tree4d2d71f04f63c0c6f9a914ca1eec3b218cec5a41 /sql-resource
parentb63efd06002c1956b638a70fa0eec6bf571b640c (diff)
parentc84c0c1761cddac08f28b554809580df1f84d59e (diff)
Merge "Fix Blocker/Critical sonar issues"
Diffstat (limited to 'sql-resource')
-rw-r--r--sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java101
1 files changed, 35 insertions, 66 deletions
diff --git a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java
index 78d92d09..df3d8132 100644
--- a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java
+++ b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java
@@ -382,72 +382,41 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin {
return (executeSqlWrite(key, ctx));
}
- private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) {
- String strValue = new String(colValue);
-
- if (StringUtils.isAsciiPrintable(strValue)) {
-
- // If printable, not encrypted
- return (strValue);
- } else {
- PreparedStatement stmt = null;
- Connection conn = null;
- ResultSet results = null;
- try {
- // CachedRowSet results =
- // dblibSvc.getData("SELECT
- // CAST(AES_DECRYPT('"+strValue+"','"+CRYPT_KEY+"') AS CHAR(50))
- // FROM DUAL",
- // null, null);
- conn = ((DBResourceManager) dblibSvc).getConnection();
-
- stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL");
-
- stmt.setBytes(1, colValue);
- stmt.setString(2, getCryptKey());
-
- results = stmt.executeQuery();
-
- if ((results != null) && results.next()) {
- strValue = results.getString(1);
- LOG.debug("Decrypted value is " + strValue);
- } else {
- LOG.warn("Cannot decrypt " + tableName + "." + colName);
- }
- } catch (Exception e) {
- LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e);
- } finally {
- try {
- if (results != null) {
- results.close();
- results = null;
- }
- } catch (Exception exc) {
-
- }
-
- try {
- if (stmt != null) {
- stmt.close();
- stmt = null;
- }
- } catch (Exception exc) {
-
- }
-
- try {
- if (conn != null) {
- conn.close();
- conn = null;
- }
- } catch (Exception exc) {
-
- }
-
- }
- }
- return (strValue);
- }
+ private String decryptColumn(String tableName, String colName, byte[] colValue, DbLibService dblibSvc) {
+ String strValue = new String(colValue);
+
+ if (StringUtils.isAsciiPrintable(strValue)) {
+
+ // If printable, not encrypted
+ return (strValue);
+ } else {
+ ResultSet results = null;
+ try (Connection conn = ((DBResourceManager) dblibSvc).getConnection();
+ PreparedStatement stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL")) {
+
+ stmt.setBytes(1, colValue);
+ stmt.setString(2, getCryptKey());
+ results = stmt.executeQuery();
+
+ if ((results != null) && results.next()) {
+ strValue = results.getString(1);
+ LOG.debug("Decrypted value is " + strValue);
+ } else {
+ LOG.warn("Cannot decrypt " + tableName + "." + colName);
+ }
+ } catch (Exception e) {
+ if (results != null) {
+ try {
+ results.close();
+ } catch (SQLException ignored) {
+
+ }
+ }
+ LOG.error("Caught exception trying to decrypt " + tableName + "." + colName, e);
+ }
+ }
+ return (strValue);
+ }
public static String getCryptKey() {
return (CRYPT_KEY);