use of com.tremolosecurity.provisioning.core.providers.BasicDB in project OpenUnison by TremoloSecurity.
the class LoadFromDatabaseTarget method validate.
@Override
public String validate(String value, HttpFilterRequest request) throws Exception {
BasicDB db = (BasicDB) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
Connection con = db.getDS().getConnection();
try {
PreparedStatement stmt = con.prepareStatement(this.exactSQL);
stmt.setString(1, value);
ResultSet rs = stmt.executeQuery();
String error = null;
if (!rs.next()) {
error = this.errorMessage;
}
rs.close();
stmt.close();
return error;
} catch (SQLException sqlException) {
logger.error("Unable to validate against '" + this.exactSQL + "'");
throw sqlException;
} finally {
if (con != null) {
con.close();
}
}
}
use of com.tremolosecurity.provisioning.core.providers.BasicDB in project OpenUnison by TremoloSecurity.
the class LoadFromDatabaseTarget method getSourceList.
@Override
public List<NVP> getSourceList(HttpFilterRequest request) throws Exception {
if (request.getParameter("search") == null) {
BasicDB db = (BasicDB) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
Connection con = db.getDS().getConnection();
try {
ArrayList<NVP> toReturn = new ArrayList<NVP>();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(noParamSQL);
while (rs.next()) {
toReturn.add(new NVP(rs.getString(nameField), rs.getString(valueField)));
if (this.maxEntries > 0 && toReturn.size() > this.maxEntries) {
rs.close();
stmt.close();
break;
}
}
return toReturn;
} finally {
if (con != null) {
con.close();
}
}
} else {
BasicDB db = (BasicDB) GlobalEntries.getGlobalEntries().getConfigManager().getProvisioningEngine().getTarget(this.targetName).getProvider();
Connection con = db.getDS().getConnection();
try {
ArrayList<NVP> toReturn = new ArrayList<NVP>();
PreparedStatement stmt = con.prepareStatement(this.paramSQL);
stmt.setString(1, "%" + request.getParameter("search").getValues().get(0) + "%");
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
toReturn.add(new NVP(rs.getString(nameField), rs.getString(valueField)));
if (this.maxEntries > 0 && toReturn.size() > this.maxEntries) {
rs.close();
stmt.close();
break;
}
}
return toReturn;
} finally {
if (con != null) {
con.close();
}
}
}
}
use of com.tremolosecurity.provisioning.core.providers.BasicDB in project OpenUnison by TremoloSecurity.
the class DBTargetDynamicWF method generateWorkflows.
@Override
public List<Map<String, String>> generateWorkflows(WorkflowType wf, ConfigManager cfg, HashMap<String, Attribute> params) throws ProvisioningException {
String target = params.get("target").getValues().get(0);
String SQL = params.get("sql").getValues().get(0);
Connection con = null;
ResultSet rs = null;
Statement s = null;
try {
con = ((BasicDB) cfg.getProvisioningEngine().getTarget(target).getProvider()).getDS().getConnection();
s = con.createStatement();
rs = s.executeQuery(SQL);
List<Map<String, String>> wfParams = new ArrayList<Map<String, String>>();
while (rs.next()) {
HashMap<String, String> row = new HashMap<String, String>();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
if (rs.getObject(rs.getMetaData().getColumnLabel(i + 1)) != null) {
row.put(rs.getMetaData().getColumnLabel(i + 1), rs.getObject(rs.getMetaData().getColumnLabel(i + 1)).toString());
}
}
wfParams.add(row);
}
return wfParams;
} catch (SQLException e) {
throw new ProvisioningException("Could not get workflow data", e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
}
if (s != null) {
try {
s.close();
} catch (SQLException e) {
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
}
}
}
}
Aggregations