Commit 568549f7 authored by Marc Boorshtein's avatar Marc Boorshtein
Browse files

* Added SPML Support for JDBC LDAP

* Added SPML and DSMLv2 support in the browser
* Added support JDBC connections in the browser
* Added export to CVS support in the browser
* If the JLDAP binary used doesn't support SPML or JLDAP, the browser won't support
* Fixed a bug with ignoring commit/rollback ITS 3600
parent 9e308af2
......@@ -51,7 +51,12 @@ public class AttributesList implements IStructuredContentProvider {
base = " ";
}
sql = "SELECT * FROM objectScope;" + base;
if (! browser.isSpml) {
sql = "SELECT * FROM objectScope;" + base;
} else {
sql = "SELECT view FROM objectScope;" + base;
}
......
......@@ -58,6 +58,13 @@ public class BrowserPrefs {
size.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
size.setText(Integer.toString(JdbcLdapBrowserApp.app.sizeLimit));
l = new Label(top,SWT.NONE);
l.setText("JDBC Drivers Path : ");
final Text driversPath = new Text(top,SWT.BORDER);
driversPath.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
driversPath.setText(JdbcLdapBrowserApp.app.driversDir);
l = new Label(top,SWT.NONE);
l.setText("Maximum Time Per Operation : ");
......@@ -65,12 +72,20 @@ public class BrowserPrefs {
time.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
time.setText(Integer.toString(JdbcLdapBrowserApp.app.timeLimit));
l = new Label(top,SWT.NONE);
l.setText("Number of statements to store in history : ");
final Text history = new Text(top,SWT.BORDER);
history.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
history.setText(Integer.toString(JdbcLdapBrowserApp.app.historyLimit));
l = new Label(top,SWT.NONE);
l.setText("Auto execute SQL from dialogs : ");
final Button autoExecute = new Button(top,SWT.CHECK);
autoExecute.setSelection(JdbcLdapBrowserApp.app.autoExec);
Button ok = new Button(top,SWT.PUSH);
ok.setText(" OK ");
ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
......@@ -80,6 +95,8 @@ public class BrowserPrefs {
JdbcLdapBrowserApp.app.sizeLimit = Integer.parseInt(size.getText());
JdbcLdapBrowserApp.app.timeLimit = Integer.parseInt(time.getText());
JdbcLdapBrowserApp.app.autoExec = autoExecute.getSelection();
JdbcLdapBrowserApp.app.driversDir = driversPath.getText();
JdbcLdapBrowserApp.app.historyLimit = Integer.parseInt(history.getText());
JdbcLdapBrowserApp.app.setPrefs();
shell.close();
......
......@@ -57,7 +57,7 @@ public class ConfigStore {
}
}
public void saveConfig(String label,String user, String pass, String host, String port,String base,boolean isDSML,boolean followReferrals, boolean isSSL) throws Exception {
public void saveConfig(String label,String user, String pass, String host, String port,String base,boolean isDSML,boolean followReferrals, boolean isSSL, boolean isSpml, boolean isJdbc, String extraUrl) throws Exception {
ConnectionStore cs = new ConnectionStore();
Element svr = null;
NodeList nl = doc.getDocumentElement().getElementsByTagName("server");
......@@ -86,6 +86,9 @@ public class ConfigStore {
cs.isDsml = isDSML;
svr.setAttribute("isDSML",Boolean.toString(isDSML));
cs.isSpml = isSpml;
svr.setAttribute("isSPML",Boolean.toString(isSpml));
cs.isSSL = isSSL;
svr.setAttribute("isSSL",Boolean.toString(isSSL));
......@@ -101,6 +104,11 @@ public class ConfigStore {
cs.user = user;
svr.setAttribute("user",user);
cs.isJDBC = isJdbc;
svr.setAttribute("isJDBC",Boolean.toString(isJdbc));
cs.extraUrl = extraUrl;
svr.setAttribute("extraUrl",cs.extraUrl);
this.configs.put(label,cs);
this.storeConfigs();
......@@ -129,11 +137,15 @@ public class ConfigStore {
tmp = svr.getAttribute("isSSL");
cs.isSSL = tmp.equals("1") || tmp.equalsIgnoreCase("true");
tmp = svr.getAttribute("isJDBC");
cs.isJDBC = tmp.equals("1") || tmp.equalsIgnoreCase("true");
cs.pass = svr.getAttribute("pass");
cs.port = svr.getAttribute("port");
cs.server = svr.getAttribute("server");
cs.user = svr.getAttribute("user");
cs.base = svr.getAttribute("base");
cs.extraUrl = svr.getAttribute("extraUrl");
this.configs.put(label,cs);
}
}
......
......@@ -28,4 +28,7 @@ class ConnectionStore {
boolean followReferrals;
boolean isDsml;
boolean isSSL;
public boolean isSpml;
public boolean isJDBC;
public String extraUrl;
}
......@@ -49,7 +49,7 @@ public class DirTree implements ITreeContentProvider {
JndiLdapConnection con = null;
try {
con = browser.getConnection();
con = (JndiLdapConnection) browser.getConnection();
}
catch (SQLException e) {
MessageDialog.openError(browser.tabs.getShell(),"Error",e.toString());
......@@ -143,7 +143,7 @@ public class DirTree implements ITreeContentProvider {
//System.out.println("retrieving sql");
while (rs.next()) {
TreeObject nto = new TreeObject(rs.getString(dnAttrib),to,con.getBaseDN());
TreeObject nto = new TreeObject(rs.getString(1),to,con.getBaseDN());
nto.setConId(to.getConId());
children.add(nto);
}
......
......@@ -24,6 +24,7 @@ import org.eclipse.swt.events.*;
import java.sql.*;
import com.octetstring.jdbcLdap.jndi.*;
import java.util.*;
import java.util.prefs.Preferences;
......@@ -38,8 +39,8 @@ import java.io.*;
*
*/
public class JdbcLdapBrowserApp {
public static final String VERSION = "2.0";
public static final String BUILD = "6031M";
public static final String VERSION = "2.1";
public static final String BUILD = "6117M";
static JdbcLdapBrowserApp app;
......@@ -64,11 +65,15 @@ public class JdbcLdapBrowserApp {
static Image copy;
static Image refresh;
static Image search;
static Image db;
Font tabFont;
int sizeLimit;
int timeLimit;
public boolean autoExec;
public String driversDir;
public int historyLimit;
static Image ws;
public JdbcLdapBrowserApp() throws Exception {
app = this;
this.loadPrefs();
......@@ -87,6 +92,8 @@ public class JdbcLdapBrowserApp {
copy = new Image(display,JdbcLdapBrowserApp.class.getResourceAsStream("copy.gif"));
refresh = new Image(display,JdbcLdapBrowserApp.class.getResourceAsStream("refresh.gif"));
search = new Image(display,JdbcLdapBrowserApp.class.getResourceAsStream("search.gif"));
db = new Image(display,JdbcLdapBrowserApp.class.getResourceAsStream("db.gif"));
ws = new Image(display,JdbcLdapBrowserApp.class.getResourceAsStream("ws.gif"));
browsers = new HashMap();
......@@ -230,6 +237,12 @@ public class JdbcLdapBrowserApp {
toLdifItem.setImage(toLdif);
toLdifItem.addSelectionListener(new ToLdif(this));
ToolItem toCsvItem = new ToolItem(toolBar,SWT.PUSH);
toCsvItem.setToolTipText("Export Current Qury To CSV");
toCsvItem.setText("To CSV");
toCsvItem.setImage(toLdif);
toCsvItem.addSelectionListener(new ToCSV(this));
toolBar.pack();
//coolBar.pack();
......@@ -281,20 +294,43 @@ public class JdbcLdapBrowserApp {
con.showWindow(display);
if (! con.doOpen) return;
JdbcLdapBrowser w =
new JdbcLdapBrowser(
con.sserver,
con.sport,
con.sbase,
con.suser,
con.spassword,con.bfollowReferrals,con.bIsDSML,con.bSsl);
JdbcLdapBrowser w = null;
if (! con.bjdbc) {
w = new JdbcLdapBrowser(
con.sserver,
con.sport,
con.sbase,
con.suser,
con.spassword,con.bfollowReferrals,con.bIsDSML,con.bSsl,con.bspml,con.textraURL);
} else {
w = new JdbcLdapBrowser(
con.sserver,
con.sport,
con.suser,
con.spassword);
}
w.setName(con.sname);
if (this.browsers.containsKey(con.sname)) throw new Exception(con.sname + " Already Exists");
CTabItem ti = new CTabItem(tabs,SWT.NONE);
ti.setText(con.sname);
ti.setImage(ldap);
if (con.bjdbc) {
ti.setImage(db);
} else if (con.bIsDSML || con.bspml) {
ti.setImage(ws);
}
else {
ti.setImage(ldap);
}
Composite c = new Composite(tabs,SWT.NONE);
ti.setControl(c);
......@@ -507,7 +543,8 @@ public class JdbcLdapBrowserApp {
this.sizeLimit = Integer.parseInt(prefs.get("JDBC_LDAP_SIZE_LIMIT","0"));
this.timeLimit = Integer.parseInt(prefs.get("JDBC_LDAP_TIME_LIMIT","0"));
this.autoExec = prefs.getBoolean("JDBC_LDAP_AUTO_EXEC",true);
this.driversDir = prefs.get("JDBC_LDAP_DRIVER_PATH",System.getProperty("user.home") + File.separator + "jdbcDrivers");
this.historyLimit = Integer.parseInt(prefs.get("JDBC_LDAP_HIST_LIMIT","16"));
}
public void setPrefs() {
......@@ -515,7 +552,8 @@ public class JdbcLdapBrowserApp {
prefs.put("JDBC_LDAP_SIZE_LIMIT",Integer.toString(this.sizeLimit));
prefs.put("JDBC_LDAP_TIME_LIMIT",Integer.toString(this.timeLimit));
prefs.put("JDBC_LDAP_AUTO_EXEC",Boolean.toString(this.autoExec));
prefs.put("JDBC_LDAP_DRIVER_PATH",this.driversDir);
prefs.putInt("JDBC_LDAP_HIST_LIMIT",this.historyLimit);
}
}
......@@ -689,8 +727,13 @@ class LoadRebind extends SelectionAdapter {
JdbcLdapBrowser browser = ((Browser) app.browsers.get(tab.getText())).browser;
if (browser.isDB) {
MessageDialog.openError(app.shell,"Can not Rebinf","Rebind can only be performed on directory services");
return;
}
try {
Rebind rebind = new Rebind(browser.getConnection(),(ConnectionStore) browser.reffedCons.get(0),app.display);
Rebind rebind = new Rebind((JndiLdapConnection) browser.getConnection(),(ConnectionStore) browser.reffedCons.get(0),app.display);
} catch (SQLException e) {
e.printStackTrace();
......@@ -715,6 +758,11 @@ class ToLdif extends SelectionAdapter {
JdbcLdapBrowser browser = ((Browser) app.browsers.get(app.tabs.getSelection().getText())).browser;
if (browser.isDB) {
MessageDialog.openError(app.shell,"Can not generate LDIF","LDIF can only be generated by directory services");
return;
}
String SQL = browser.SQL.getText();
if (SQL == null || ! SQL.toLowerCase().startsWith("select")) {
......@@ -729,7 +777,7 @@ class ToLdif extends SelectionAdapter {
String saveTo = fd.getFileName();
try {
JndiLdapConnection con = browser.getConnection();
JndiLdapConnection con = (JndiLdapConnection) browser.getConnection();
con.setExpandRow(false);
con.setConcatAtts(true);
SQL = browser.insertScope(SQL);
......@@ -750,6 +798,81 @@ class ToLdif extends SelectionAdapter {
}
class ToCSV extends SelectionAdapter {
JdbcLdapBrowserApp app;
public ToCSV (JdbcLdapBrowserApp app) {
this.app = app;
}
public void widgetSelected(SelectionEvent event) {
if (app.tabs.getSelection() == null) {
MessageDialog.openError(app.shell,"Error","No Browsers Oppened");
return;
}
JdbcLdapBrowser browser = ((Browser) app.browsers.get(app.tabs.getSelection().getText())).browser;
String SQL = browser.SQL.getText().replace('\n',' ');
if (SQL == null || ! SQL.toLowerCase().startsWith("select")) {
MessageDialog.openError(app.shell,"Error","No Query Entered");
return;
}
FileDialog fd = new FileDialog(app.shell,SWT.SAVE);
fd.setFilterExtensions(new String[] {"csv"});
fd.setText("Save CSV To");
fd.open();
String saveTo = fd.getFileName();
try {
Connection con = browser.getConnection();
if (con instanceof JndiLdapConnection) {
((JndiLdapConnection) con).setExpandRow(false);
((JndiLdapConnection)con).setConcatAtts(true);
SQL = browser.insertScope(SQL);
((JndiLdapConnection)con).setExpandRow(true);
((JndiLdapConnection)con).setConcatAtts(false);
}
ResultSet rs = con.createStatement().executeQuery(SQL);
//System.out.println(fd.getFilterPath() + "/" + fd.getFileName());
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(fd.getFilterPath() + "/" + fd.getFileName()))));
ResultSetMetaData md = rs.getMetaData();
for (int i=1,m=md.getColumnCount();i<=m;i++) {
pw.print("\"" + md.getColumnName(i) + "\"");
if (i<m) {
pw.print(",");
}
}
pw.println();
while (rs.next()) {
for (int i=1,m=md.getColumnCount();i<=m;i++) {
pw.print("\"" + rs.getString(md.getColumnName(i)) + "\"");
if (i<m) {
pw.print(",");
}
}
pw.println();
}
pw.flush();
pw.close();
}
catch (Exception e) {
MessageDialog.openError(app.shell,"Query Could Not Be Executed",e.toString());
}
}
}
class CopyName extends SelectionAdapter {
JdbcLdapBrowserApp app;
......
/* **************************************************************************
*
* Copyright (C) 2005 Marc Boorshtein. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM OCTET STRING, INC.,
* COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
******************************************************************************/
package com.octetstring.jdbcLdap.browser;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class JdbcMetaDataView implements IStructuredContentProvider,ITableLabelProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object arg0) {
try {
JdbcTreeObject treeObj = (JdbcTreeObject) arg0;
Connection con = treeObj.getBrowser().jdbcCon;
ArrayList rows = new ArrayList();
ResultSet rs = con.getMetaData().getColumns(null,treeObj.getParentName(),treeObj.getName(),"%");
String tmp = null;
while (rs.next()) {
String[] meta = new String[4];
tmp = rs.getString("COLUMN_NAME");
meta[0] = tmp != null ? tmp : "";
tmp = rs.getString("TYPE_NAME");
meta[1] = tmp != null ? tmp : "";
tmp = rs.getString("COLUMN_SIZE");
meta[2] = tmp != null ? tmp : "";
tmp = rs.getString("REMARKS");
meta[3] = tmp != null ? tmp : "";
rows.add(meta);
}
return rows.toArray();
} catch (Exception e) {
e.printStackTrace();
return new Object[0];
}
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
*/
public Image getColumnImage(Object arg0, int arg1) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
public String getColumnText(Object arg0, int arg1) {
return ((String[]) arg0)[arg1];
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void addListener(ILabelProviderListener arg0) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
*/
public boolean isLabelProperty(Object arg0, String arg1) {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
*/
public void removeListener(ILabelProviderListener arg0) {
// TODO Auto-generated method stub
}
}
/* **************************************************************************
*
* Copyright (C) 2005 Marc Boorshtein. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
* TREATIES. USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT
* TO VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS
* AVAILABLE AT HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE"
* IN THE TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION
* OF THIS WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP
* PUBLIC LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM OCTET STRING, INC.,
* COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
******************************************************************************/
package com.octetstring.jdbcLdap.browser;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class JdbcTree implements ITreeContentProvider,ILabelProvider {
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
*/
public Object[] getChildren(Object arg0) {
try {
JdbcTreeObject treeObj = (JdbcTreeObject) arg0;
switch (treeObj.getType()) {
case JdbcTreeObject.ROOT :
Object[] ret = this.getSchemas(treeObj);
if (ret == null) {
return this.getTables(null,treeObj);
} else {
return ret;
}
case JdbcTreeObject.SCHEMA :
return this.getTables(treeObj.getName(),treeObj);
case JdbcTreeObject.TABLE : return new Object[0];
}
} catch (Exception e) {
e.printStackTrace();
return new Object[0];
}
return new Object[0];
}
private Object[] getSchemas(JdbcTreeObject treeObj) throws SQLException {
Connection con = treeObj.getBrowser().jdbcCon;
ResultSet rs = con.getMetaData().getSchemas();
ArrayList schems = new ArrayList();
if (rs == null || ! rs.next()) {
return null;
} else {
do {
String name = rs.getString("TABLE_SCHEM");
schems.add(new JdbcTreeObject(JdbcTreeObject.SCHEMA,name,treeObj.getBrowser()));
} while (rs.next());
return schems.toArray();
}
}
private Object[] getTables(String schema,JdbcTreeObject treeObj) throws SQLException {
Connection con = treeObj.getBrowser().jdbcCon;