Browse Source

REPORT-69285 数据连接安全关键字检查拦截,设计器

release/11.0
rinoux 3 years ago
parent
commit
04435927b9
  1. 10
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java
  2. 23
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java
  3. 7
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java
  4. 2
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java

10
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListDialogActionAdapter.java

@ -2,11 +2,15 @@ package com.fr.design.data.datapane.connect;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.editlock.EditLockUtils; import com.fr.design.editlock.EditLockUtils;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import com.fr.report.LockItem; import com.fr.report.LockItem;
import javax.swing.JOptionPane;
/** /**
* @author hades * @author hades
* @version 11.0 * @version 11.0
@ -32,7 +36,13 @@ public class ConnectionListDialogActionAdapter extends DialogActionAdapter {
connectionListDialog.setDoOKSucceed(false); connectionListDialog.setDoOKSucceed(false);
return; return;
} }
try {
connectionManagerPane.update(connectionConfig); connectionManagerPane.update(connectionConfig);
} catch (Exception e) {
connectionListDialog.setDoOKSucceed(false);
FineJOptionPane.showMessageDialog(connectionManagerPane, e.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE);
return;
}
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); DesignerContext.getDesignerBean("databasename").refreshBeanElement();
// 关闭定义数据连接页面,为其解锁 // 关闭定义数据连接页面,为其解锁
EditLockUtils.unlock(LockItem.CONNECTION); EditLockUtils.unlock(LockItem.CONNECTION);

23
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionListPane.java

@ -1,6 +1,7 @@
package com.fr.design.data.datapane.connect; package com.fr.design.data.datapane.connect;
import com.fr.config.RemoteConfigEvent; import com.fr.config.RemoteConfigEvent;
import com.fr.data.core.db.JDBCSecurityChecker;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.ConnectionBean; import com.fr.data.impl.ConnectionBean;
import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JDBCDatabaseConnection;
@ -28,6 +29,7 @@ import com.fr.transaction.WorkerFacade;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import java.awt.Window; import java.awt.Window;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -166,7 +168,7 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
/** /**
* Update. * Update.
*/ */
public void update(ConnectionConfig connectionConfig) { public void update(ConnectionConfig connectionConfig) throws Exception {
// Nameable[]居然不能强转成NameObject[],一定要这么写... // Nameable[]居然不能强转成NameObject[],一定要这么写...
Nameable[] res = this.update(); Nameable[] res = this.update();
Map<String, Connection> updatedMap = new LinkedHashMap<>(); Map<String, Connection> updatedMap = new LinkedHashMap<>();
@ -188,10 +190,27 @@ public class ConnectionListPane extends JListControlPane implements ConnectionSh
} }
}); });
this.checkSecurity(addedOrUpdatedConnections);
this.alterConnections(removedConnNames, addedOrUpdatedConnections); this.alterConnections(removedConnNames, addedOrUpdatedConnections);
} }
private void checkSecurity(List<ConnectionBean> addedOrUpdatedConnections) throws Exception {
for (ConnectionBean connectionBean : addedOrUpdatedConnections) {
Connection connection = connectionBean.getConnection();
if (connection instanceof JDBCDatabaseConnection) {
try {
JDBCSecurityChecker.checkURL(((JDBCDatabaseConnection) connection).getURL());
JDBCSecurityChecker.checkValidationQuery(((JDBCDatabaseConnection) connection).getDbcpAttr().getValidationQuery());
} catch (SQLException e) {
throw new SQLException(Toolkit.i18nText("Fine-Design_Basic_Database_Connection_Invalid_Config", connectionBean.getName()) + ", " + e.getMessage(), e.getCause());
}
}
}
}
private void alterConnections(List<String> removedConnNames, List<ConnectionBean> addedOrUpdatedConnections) { private void alterConnections(List<String> removedConnNames, List<ConnectionBean> addedOrUpdatedConnections) {
try { try {

7
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionManagerPane.java

@ -4,9 +4,8 @@ import com.fr.design.gui.frpane.LoadingBasicPane;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import javax.swing.JPanel;
import javax.swing.*; import java.awt.BorderLayout;
import java.awt.*;
import java.util.HashMap; import java.util.HashMap;
public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane { public class ConnectionManagerPane extends LoadingBasicPane implements ConnectionShowPane {
@ -39,7 +38,7 @@ public class ConnectionManagerPane extends LoadingBasicPane implements Connectio
this.connectionListPane.populate(datasourceManager); this.connectionListPane.populate(datasourceManager);
} }
public void update(ConnectionConfig datasourceManager) { public void update(ConnectionConfig datasourceManager) throws Exception {
this.connectionListPane.update(datasourceManager); this.connectionListPane.update(datasourceManager);
} }

2
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionShowPane.java

@ -7,7 +7,7 @@ import com.fr.file.ConnectionConfig;
* 数据链接显示面板 * 数据链接显示面板
*/ */
public interface ConnectionShowPane { public interface ConnectionShowPane {
void update(ConnectionConfig connectionConfig); void update(ConnectionConfig connectionConfig) throws Exception;
void populate(ConnectionConfig connectionConfig); void populate(ConnectionConfig connectionConfig);

Loading…
Cancel
Save