summaryrefslogtreecommitdiffstats
path: root/sql-resource
diff options
context:
space:
mode:
authorshashikanth <shashikanth.vh@huawei.com>2017-09-21 19:24:34 +0530
committerShashikanth VH <shashikanth.vh@huawei.com>2017-09-21 14:02:50 +0000
commitc84c0c1761cddac08f28b554809580df1f84d59e (patch)
tree3f40ba1a9d803aa7c6516e84bffb17066111557a /sql-resource
parentd1ed09daa141268d0cb830f5060e9463719d1eba (diff)
Fix Blocker/Critical sonar issues
Fix Blocker/Critical sonar issues in ccsdk/sli/adaptors module https://sonar.onap.org/component_issues?id=org.onap.ccsdk.sli.adaptors%3Accsdk-sli-adaptors#resolved=false|severities=BLOCKER Fixed Close "PreparedStatement". Issue-Id: CCSDK-67 Change-Id: I2d4b42067f3286806f7bca8821ce17328d72091f Signed-off-by: shashikanth.vh <shashikanth.vh@huawei.com>
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);