Browse Source

Merge pull request #8900 in DESIGN/design from feature/10.0 to feature/big-screen

* commit '055e943726f13e44e6f5a98a711ef28432fb6865':
  REPORT-69285 数据连接安全关键字检查拦截
  REPORT-69285 数据连接安全关键字检查拦截
  REPORT-69285 数据连接安全关键字检查拦截
  REPORT-68607 数据连接配置操作放事务
feature/big-screen
superman 3 years ago
parent
commit
b36178147e
  1. 16
      designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java
  2. 33
      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
  5. 20
      designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java

16
designer-base/src/main/java/com/fr/design/data/datapane/connect/ConnectionComboBoxPanel.java

@ -8,10 +8,12 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.server.ConnectionListAction; import com.fr.design.actions.server.ConnectionListAction;
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.ConnectionLockChangeChecker; import com.fr.design.editlock.ConnectionLockChangeChecker;
import com.fr.design.editlock.EditLockUtils; import com.fr.design.editlock.EditLockUtils;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UILockButton; import com.fr.design.gui.ibutton.UILockButton;
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;
@ -22,6 +24,7 @@ import com.fr.transaction.WorkerFacade;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.server.connection.DBConnectAuth; import com.fr.workspace.server.connection.DBConnectAuth;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -32,6 +35,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* 选择数据连接的下拉框 * 选择数据连接的下拉框
@ -145,10 +149,16 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
connectionListDialog.setDoOKSucceed(false); connectionListDialog.setDoOKSucceed(false);
return; return;
} }
AtomicBoolean saved = new AtomicBoolean(true);
Configurations.modify(new WorkerFacade(ConnectionConfig.class) { Configurations.modify(new WorkerFacade(ConnectionConfig.class) {
@Override @Override
public void run() { public void run() {
try {
connectionListPane.update(connectionConfig); connectionListPane.update(connectionConfig);
} catch (Exception e) {
saved.set(false);
FineJOptionPane.showMessageDialog(connectionListPane, e.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE);
}
} }
}.addCallBack(new CallBackAdaptor() { }.addCallBack(new CallBackAdaptor() {
@Override @Override
@ -159,9 +169,13 @@ public class ConnectionComboBoxPanel extends ItemEditableComboBoxPanel {
@Override @Override
public void afterCommit() { public void afterCommit() {
if (saved.get()) {
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); DesignerContext.getDesignerBean("databasename").refreshBeanElement();
// 关闭定义数据连接页面,为其解锁 // 定义数据连接弹窗关闭后,解锁
EditLockUtils.unlock(LockItem.CONNECTION); EditLockUtils.unlock(LockItem.CONNECTION);
} else {
connectionListDialog.setDoOKSucceed(false);
}
} }
})); }));

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

@ -1,5 +1,6 @@
package com.fr.design.data.datapane.connect; package com.fr.design.data.datapane.connect;
import com.fr.data.core.db.JDBCSecurityChecker;
import com.fr.data.impl.Connection; import com.fr.data.impl.Connection;
import com.fr.data.impl.JDBCDatabaseConnection; import com.fr.data.impl.JDBCDatabaseConnection;
import com.fr.data.impl.JNDIDatabaseConnection; import com.fr.data.impl.JNDIDatabaseConnection;
@ -22,6 +23,7 @@ import com.fr.stable.StringUtils;
import com.fr.stable.core.PropertyChangeAdapter; import com.fr.stable.core.PropertyChangeAdapter;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
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;
@ -157,24 +159,49 @@ 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<>();
Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject())); Arrays.stream(res).map(n -> (NameObject) n).forEach(no -> updatedMap.put(no.getName(), (Connection) no.getObject()));
List<String> removedConnNames = new ArrayList<>();
Map<String, Connection> addedOrUpdatedConnections = new LinkedHashMap<>();
MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> { MapCompareUtils.contrastMapEntries(populatedConnectionsSnapshot, updatedMap, (entryEventKind, s, connection) -> {
switch (entryEventKind) { switch (entryEventKind) {
case REMOVED: case REMOVED:
connectionConfig.removeConnection(s); removedConnNames.add(s);
break; break;
case ADDED: case ADDED:
case UPDATED: case UPDATED:
connectionConfig.addConnection(s, connection); addedOrUpdatedConnections.put(s, connection);
default: default:
break; break;
} }
}); });
this.checkSecurity(addedOrUpdatedConnections);
alterConnections(removedConnNames, addedOrUpdatedConnections);
}
private void alterConnections(List<String> removedConnNames, Map<String, Connection> addedOrUpdatedConnections) {
removedConnNames.forEach(n -> ConnectionConfig.getInstance().removeConnection(n));
addedOrUpdatedConnections.forEach((name, conn) -> ConnectionConfig.getInstance().addConnection(name, conn));
}
private void checkSecurity(Map<String, Connection> addedOrUpdatedConnections) throws Exception {
for (Map.Entry<String, Connection> entry : addedOrUpdatedConnections.entrySet()) {
Connection connection = entry.getValue();
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", entry.getKey()) + ", " + e.getMessage(), e.getCause());
}
}
}
} }
@Override @Override

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);

20
designer-base/src/main/java/com/fr/design/os/impl/DatabaseDialogAction.java

@ -3,19 +3,26 @@ package com.fr.design.os.impl;
import com.fr.design.data.datapane.connect.ConnectionManagerPane; import com.fr.design.data.datapane.connect.ConnectionManagerPane;
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.design.mainframe.DesignerFrame; import com.fr.design.mainframe.DesignerFrame;
import com.fr.file.ConnectionConfig; import com.fr.file.ConnectionConfig;
import com.fr.report.LockItem;
import com.fr.stable.os.support.OSBasedAction; import com.fr.stable.os.support.OSBasedAction;
import com.fr.transaction.CallBackAdaptor; import com.fr.transaction.CallBackAdaptor;
import com.fr.transaction.Configurations; import com.fr.transaction.Configurations;
import com.fr.transaction.WorkerFacade; import com.fr.transaction.WorkerFacade;
import com.fr.report.LockItem;
import javax.swing.JOptionPane;
import java.util.concurrent.atomic.AtomicBoolean;
import static com.fr.design.actions.server.ConnectionListAction.doWithDatasourceManager; import static com.fr.design.actions.server.ConnectionListAction.doWithDatasourceManager;
/** /**
* 数据连接窗口 * 数据连接窗口
*
* @author pengda * @author pengda
* @date 2019/10/9 * @date 2019/10/9
*/ */
@ -52,10 +59,17 @@ public class DatabaseDialogAction implements OSBasedAction {
databaseListDialog.setDoOKSucceed(false); databaseListDialog.setDoOKSucceed(false);
return; return;
} }
AtomicBoolean saved = new AtomicBoolean(true);
Configurations.modify(new WorkerFacade(ConnectionConfig.class) { Configurations.modify(new WorkerFacade(ConnectionConfig.class) {
@Override @Override
public void run() { public void run() {
try {
databaseManagerPane.update(datasourceManager); databaseManagerPane.update(datasourceManager);
} catch (Exception e) {
saved.set(false);
FineJOptionPane.showMessageDialog(databaseManagerPane, e.getMessage(), Toolkit.i18nText("Fine-Design_Basic_Error"), JOptionPane.ERROR_MESSAGE);
}
} }
}.addCallBack(new CallBackAdaptor() { }.addCallBack(new CallBackAdaptor() {
@Override @Override
@ -66,9 +80,13 @@ public class DatabaseDialogAction implements OSBasedAction {
@Override @Override
public void afterCommit() { public void afterCommit() {
if (saved.get()) {
DesignerContext.getDesignerBean("databasename").refreshBeanElement(); DesignerContext.getDesignerBean("databasename").refreshBeanElement();
// 定义数据连接弹窗关闭后,解锁 // 定义数据连接弹窗关闭后,解锁
EditLockUtils.unlock(LockItem.CONNECTION); EditLockUtils.unlock(LockItem.CONNECTION);
} else {
databaseListDialog.setDoOKSucceed(false);
}
} }
})); }));
} }

Loading…
Cancel
Save