Remove base64 encoding of password from models 49/112749/3
authorRam Krishna Verma <ram_krishna.verma@bell.ca>
Wed, 16 Sep 2020 14:21:36 +0000 (10:21 -0400)
committerRam Krishna Verma <ram_krishna.verma@bell.ca>
Wed, 16 Sep 2020 18:14:40 +0000 (14:14 -0400)
Remove base64 encoding of db password from models.
This will have impact on the defaultConfig of API & PAP component.
Seperate reviews are raised for those repos.

Issue-ID: POLICY-2550
Change-Id: I258f76d01c21893bb40b4095a82e56ed51bd1377
Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java

index bcf9ec1..e2784b0 100644 (file)
@@ -2,6 +2,7 @@
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,7 +40,7 @@ import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
  * defaults to {@link DatabasePolicyModelsProviderImpl} and may not be null
  * <li>databaseUrl: The JDBC URL for the database, mandatory.
  * <li>databaseUser: The user id to use for connecting to the database, optional, defaults to null.
- * <li>databasePassword: The password to use for connecting to the database encoded in Base64, optional,
+ * <li>databasePassword: The password to use for connecting to the database, optional,
  * defaults to null.
  * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
  * to the database, mandatory.
index 77a72ad..e27b9a4 100644 (file)
@@ -22,7 +22,6 @@
 
 package org.onap.policy.models.provider.impl;
 
-import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 import java.util.Properties;
@@ -95,15 +94,12 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
         daoParameters.setPluginClass(DefaultPfDao.class.getName());
         daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
 
-        // Decode the password using Base64
-        String decodedPassword = new String(Base64.getDecoder().decode(getValue(parameters.getDatabasePassword())));
-
         // @formatter:off
         Properties jdbcProperties = new Properties();
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER,   parameters.getDatabaseDriver());
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL,      parameters.getDatabaseUrl());
         jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_USER,     parameters.getDatabaseUser());
-        jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, decodedPassword);
+        jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_PASSWORD, parameters.getDatabasePassword());
         // @formatter:on
 
         daoParameters.setJdbcProperties(jdbcProperties);
@@ -120,13 +116,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
         }
     }
 
-    private String getValue(final String value) {
-        if (value != null && value.startsWith("${") && value.endsWith("}")) {
-            return System.getenv(value.substring(2, value.length() - 1));
-        }
-        return value;
-    }
-
     @Override
     public void close() throws PfModelException {
         LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
index ac42304..d8b6a83 100644 (file)
@@ -28,7 +28,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import java.util.ArrayList;
-import java.util.Base64;
 import java.util.Date;
 import java.util.List;
 import org.junit.Before;
@@ -87,7 +86,7 @@ public class DatabasePolicyModelsProviderTest {
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
-        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setDatabasePassword("P01icY");
         parameters.setPersistenceUnit("ToscaConceptTest");
     }
 
index d6f0d85..a42aae4 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +26,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.net.URISyntaxException;
-import java.util.Base64;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -78,7 +78,7 @@ public class PolicyToscaPersistenceTest {
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
-        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setDatabasePassword("P01icY");
         parameters.setPersistenceUnit("ToscaConceptTest");
 
         databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
@@ -248,6 +248,7 @@ public class PolicyToscaPersistenceTest {
 
         for (int i = 0; i < 10; i++) {
             new Thread() {
+                @Override
                 public void run() {
                     assertThatCode(() -> databaseProvider.createPolicies(serviceTemplate)).doesNotThrowAnyException();
                     assertThatCode(() -> databaseProvider.updatePolicies(serviceTemplate)).doesNotThrowAnyException();
index a808105..61bf13a 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Base64;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
@@ -64,7 +64,7 @@ public class PolicyTypePersistenceTest {
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
-        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setDatabasePassword("P01icY");
         parameters.setPersistenceUnit("ToscaConceptTest");
 
         databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
@@ -114,6 +114,7 @@ public class PolicyTypePersistenceTest {
 
         for (int i = 0; i < 10; i++) {
             new Thread() {
+                @Override
                 public void run() {
                     assertThatCode(() -> databaseProvider.createPolicyTypes(serviceTemplate))
                         .doesNotThrowAnyException();
index 5f4a1cd..c107f12 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +24,6 @@ package org.onap.policy.models.provider.revisionhierarchy;
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
 
-import java.util.Base64;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -48,7 +48,7 @@ public class HierarchyFetchTest {
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
-        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setDatabasePassword("P01icY");
         parameters.setPersistenceUnit("ToscaConceptTest");
     }