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>
* ============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.
* 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.
package org.onap.policy.models.provider.impl;
-import java.util.Base64;
import java.util.Date;
import java.util.List;
import java.util.Properties;
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);
}
}
- 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(),
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;
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");
}
/*-
* ============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.
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;
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);
for (int i = 0; i < 10; i++) {
new Thread() {
+ @Override
public void run() {
assertThatCode(() -> databaseProvider.createPolicies(serviceTemplate)).doesNotThrowAnyException();
assertThatCode(() -> databaseProvider.updatePolicies(serviceTemplate)).doesNotThrowAnyException();
/*-
* ============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.
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;
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);
for (int i = 0; i < 10; i++) {
new Thread() {
+ @Override
public void run() {
assertThatCode(() -> databaseProvider.createPolicyTypes(serviceTemplate))
.doesNotThrowAnyException();
/*-
* ============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.
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;
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");
}