Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuring db username and/or password via qbean configuration file that can be encrypted #43

Merged
merged 4 commits into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/dbsupport/src/main/java/org/jpos/ee/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.hibernate.tool.schema.TargetType;
import org.jpos.core.ConfigurationException;
import org.jpos.ee.support.ModuleUtils;
import org.jpos.space.Space;
import org.jpos.space.SpaceFactory;
import org.jpos.util.Log;
import org.jpos.util.LogEvent;
import org.jpos.util.Logger;
Expand Down Expand Up @@ -480,6 +482,16 @@ private MetadataImplementor getMetadata() throws IOException, ConfigurationExcep
ssrb.applySetting((String) entry.getKey(), entry.getValue());
}
}

// if DBInstantiator has put db user name and/or password in Space, set Hibernate config accordingly
Space sp = SpaceFactory.getSpace("tspace:dbconfig");
String user = (String) sp.inp("connection.username");
String pass = (String) sp.inp("connection.password");
if (user != null)
ssrb.applySetting("hibernate.connection.username", user);
if (pass != null)
ssrb.applySetting("hibernate.connection.password", pass);

MetadataSources mds = new MetadataSources(ssrb.build());
List<String> moduleConfigs = ModuleUtils.getModuleEntries(MODULES_CONFIG_PATH);
for (String moduleConfig : moduleConfigs) {
Expand Down
47 changes: 47 additions & 0 deletions modules/dbsupport/src/main/java/org/jpos/ee/DBInstantiator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* jPOS Project [http://jpos.org]
* Copyright (C) 2000-2017 Alejandro P. Revilla
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.jpos.ee;

import org.jpos.q2.QBeanSupport;
import org.jpos.space.Space;
import org.jpos.space.SpaceFactory;

/**
* @author Sumeet Phadnis
* <p>
* Simple wrapper to instantiate DB class.
* It picks up db user name and password from configuration and puts that in Space.
* DB reads these values from the Space and sets Hibernate configuration properties accordingly.
* Being a qbean its deploy file can be encrypted using Q2.
*/
@SuppressWarnings({"UnusedDeclaration"})
public class DBInstantiator extends QBeanSupport {
public void initService() throws Exception {
super.initService();
Space sp = SpaceFactory.getSpace("tspace:dbconfig");
String usr = cfg.get("dbuser", "UNKNOWN");
String pswd = cfg.get("dbpass", "UNKNOWN");
sp.out("connection.username", usr);
sp.out("connection.password", pswd);
new org.jpos.ee.DB(cfg.get("config-modifiler"));
}
public void startService() throws Exception {
super.startService();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>

<protect>
<initdb name="init-db" class="org.jpos.ee.DBInstantiator" logger="Q2">
<property name="dbuser" value="jpos" />
<property name="dbpass" value="jpos" />
</initdb>
</protect>