From 064c0975f5efa5d760520f91bfc23cf0814ec2b0 Mon Sep 17 00:00:00 2001 From: lucian Date: Tue, 9 Jun 2020 19:23:00 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-31418=20=E3=80=9010.0.7=E3=80=91?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E8=AE=BE=E8=AE=A1=E8=BF=9E=E6=8E=A5=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=97=B6=EF=BC=8C=E5=85=81?= =?UTF-8?q?=E8=AE=B8=E4=B8=8D=E8=AE=B0=E5=BD=95=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 29 +++++++++++++++++- .../design/actions/file/SwitchExistEnv.java | 9 +++++- .../env/RemoteDesignerWorkspaceInfo.java | 4 ++- .../main/java/com/fr/env/RemoteEnvPane.java | 28 +++++++++++++++-- .../com/fr/design/EnvChangeEntranceTest.java | 30 ++++++++++++++++++- .../fr/design/env/RemoteWorkspaceTest.java | 3 +- 6 files changed, 96 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index 595f812af..687a3fea0 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -8,6 +8,7 @@ import com.fr.design.dialog.FineJOptionPane; import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; +import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.env.RemoteWorkspace; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; @@ -380,15 +381,21 @@ public class EnvChangeEntrance { * 出现对话框,选择使用的工作环境 */ public void chooseEnv() { + chooseEnv(currentEnvName); + } + + public void chooseEnv(final String envName) { final EnvListPane envListPane = new EnvListPane(); final BasicDialog envListDialog = envListPane.showWindow(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame())); - envListPane.populateEnvManager(currentEnvName); + envListPane.populateEnvManager(envName); envListDialog.addDialogActionListener(new DialogActionAdapter() { @Override public void doOk() { envListOkAction(envListPane, PopTipStrategy.LATER); + // 切换完成后清理密码 + updateSelectEnv(envName); } @Override @@ -418,6 +425,8 @@ public class EnvChangeEntrance { FineProcessContext.getParentPipe().fire(new CarryMessageEvent(ReportState.ACTIVE.getValue())); if (!envListOkAction(envListPane, PopTipStrategy.NOW)) { DesignerExiter.getInstance().execute(); + } else { + updateSelectEnv(currentEnvName); } } @@ -429,6 +438,24 @@ public class EnvChangeEntrance { envListDialog.setVisible(true); } + /** + * 切换环境后 刷新远程目录需要忘记密码的情况 + * @param envName 环境名 + */ + private void updateSelectEnv(String envName) { + DesignerEnvManager mgr = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo info = mgr.getWorkspaceInfo(envName); + if (info != null) { + WorkspaceConnectionInfo connection = info.getConnection(); + if (connection != null && !connection.isRememberPwd()) { + + DesignerWorkspaceInfo workspaceInfo = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo( + connection.getUrl(), connection.getUserName(), StringUtils.EMPTY, connection.getCertPath(), connection.getCertSecretKey(), false)); + mgr.putEnv(envName, workspaceInfo); + } + } + } + /** * 提示显示策略 diff --git a/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java index 568e713bb..1e222dd26 100644 --- a/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/main/java/com/fr/design/actions/file/SwitchExistEnv.java @@ -59,7 +59,14 @@ public class SwitchExistEnv extends MenuDef { */ public void actionPerformed(ActionEvent e) { final String envName = getName(); - EnvChangeEntrance.getInstance().switch2Env(envName); + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + if (selectedEnv.getConnection() != null && !selectedEnv.getConnection().isRememberPwd()) { + // 打开配置目录面板 + EnvChangeEntrance.getInstance().chooseEnv(envName); + } else { + EnvChangeEntrance.getInstance().switch2Env(envName); + } } } } diff --git a/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java b/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java index af0b8a01c..0e3f68897 100644 --- a/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java +++ b/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java @@ -72,7 +72,8 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo { String password = SecurityToolbox.defaultDecrypt(reader.getAttrAsString("password", StringUtils.EMPTY).replaceAll(" ", "\r\n")); String certPath = reader.getAttrAsString("certPath", StringUtils.EMPTY); String certSecretKey = reader.getAttrAsString("certSecretKey", StringUtils.EMPTY); - this.connection = new WorkspaceConnectionInfo(url, username, password, certPath, certSecretKey); + boolean rememberPwd = reader.getAttrAsBoolean("rememberPwd", true); + this.connection = new WorkspaceConnectionInfo(url, username, password, certPath, certSecretKey, rememberPwd); } } } @@ -89,6 +90,7 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo { writer.attr("password", SecurityToolbox.defaultEncrypt(connection.getPassword())); writer.attr("certPath", connection.getCertPath()); writer.attr("certSecretKey", connection.getCertSecretKey()); + writer.attr("rememberPwd", connection.isRememberPwd()); writer.end(); } } diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 9ea2f7019..3c481ba30 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -96,6 +96,10 @@ public class RemoteEnvPane extends BasicBeanPane { * 密码 */ private UIPassWordField passwordInput = new UIPassWordField(); + /** + * 是否记住密码 + */ + private UICheckBox rememberPwdCheckbox = new UICheckBox(Toolkit.i18nText("Fine-Design_Basic_Remote_Env_Remember_Password")); /** * https证书路径 */ @@ -212,7 +216,7 @@ public class RemoteEnvPane extends BasicBeanPane { updateHttpsConfigPanel(); remoteWorkspaceURL.setHttps(isHttps); - // reset下url,将勾选状态是否htpps加到url里 + // reset下url,将勾选状态是否https加到url里 remoteWorkspaceURL.resetUrl(); fillRemoteEnvURLField(); @@ -286,6 +290,7 @@ public class RemoteEnvPane extends BasicBeanPane { contentPanel.add(configPanel, BorderLayout.NORTH); contentPanel.add(accountPanel, BorderLayout.CENTER); + contentPanel.add(packRememberPwdConfigPanel(), BorderLayout.SOUTH); JPanel panel = FRGUIPaneFactory.createBorderLayout_S_Pane(); panel.add(contentPanel, BorderLayout.NORTH); panel.add(testPanel, BorderLayout.CENTER); @@ -306,15 +311,18 @@ public class RemoteEnvPane extends BasicBeanPane { String pwd = fromNullable(connection.getPassword()).or(StringUtils.EMPTY); String certPath = fromNullable(connection.getCertPath()).or(StringUtils.EMPTY); String certSecretKey = fromNullable(connection.getCertSecretKey()).or(StringUtils.EMPTY); + boolean rememberPwd = fromNullable(connection.isRememberPwd()).or(true); this.usernameInput.setText(username); this.passwordInput.setText(pwd); this.certPathInput.setText(certPath); this.certSecretKeyInput.setText(certSecretKey); + this.rememberPwdCheckbox.setSelected(rememberPwd); } else { this.remoteWorkspaceURL = RemoteWorkspaceURL.createDefaultURL(); this.usernameInput.setText(StringUtils.EMPTY); this.passwordInput.setText(StringUtils.EMPTY); + this.rememberPwdCheckbox.setSelected(true); } fillRemoteEnvURLField(); @@ -333,6 +341,7 @@ public class RemoteEnvPane extends BasicBeanPane { String url = this.remoteWorkspaceURL.getURL(); String username = this.usernameInput.getText(); String password = new String(this.passwordInput.getPassword()); + boolean rememberPwd = this.rememberPwdCheckbox.isSelected(); DesignerEnvProcessor envProcessor = ExtraDesignClassManager.getInstance().getSingle(DesignerEnvProcessor.XML_TAG); if (envProcessor != null) { url = envProcessor.changeEnvPathBeforeConnect(username, password, url); @@ -342,7 +351,8 @@ public class RemoteEnvPane extends BasicBeanPane { username, password, this.certPathInput.getText(), - new String(this.certSecretKeyInput.getPassword())); + new String(this.certSecretKeyInput.getPassword()), + rememberPwd); return RemoteDesignerWorkspaceInfo.create(connection); } @@ -522,6 +532,20 @@ public class RemoteEnvPane extends BasicBeanPane { accountPanel.add(content, BorderLayout.CENTER); } + private JPanel packRememberPwdConfigPanel() { + + JPanel panel = TableLayoutHelper.createGapTableLayoutPane( + new Component[][]{ + new Component[]{rememberPwdCheckbox} + }, + new double[]{PREFERRED}, + new double[]{PREFERRED}, + 5, + 10 + ); + TableLayoutHelper.modifyTableLayoutIndexHGap(panel, 0, 50); + return panel; + } private JPanel createHttpsCertFileInputPanel() { JPanel inputPanel = FRGUIPaneFactory.createRightFlowInnerContainer_S_Pane(); diff --git a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java index f37c6e73d..672f17e37 100644 --- a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java +++ b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java @@ -2,7 +2,9 @@ package com.fr.design; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; +import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.env.CheckServiceDialog; +import com.fr.invoke.Reflect; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import org.easymock.EasyMock; @@ -19,7 +21,7 @@ import org.powermock.modules.junit4.PowerMockRunner; * @Description: */ @RunWith(PowerMockRunner.class) -@PrepareForTest({FunctionalHttpRequest.class,EnvChangeEntrance.class,CheckServiceDialog.class}) +@PrepareForTest({FunctionalHttpRequest.class,EnvChangeEntrance.class,CheckServiceDialog.class, DesignerEnvManager.class}) public class EnvChangeEntranceTest { @Test @@ -55,4 +57,30 @@ public class EnvChangeEntranceTest { } } + @Test + public void testUpdateSelectEnv() { + + DesignerEnvManager manager = new DesignerEnvManager(); + + PowerMock.mockStatic(DesignerEnvManager.class); + EasyMock.expect(DesignerEnvManager.getEnvManager()).andReturn(manager).anyTimes(); + + PowerMock.replayAll(); + + EnvChangeEntrance entrance = EnvChangeEntrance.getInstance(); + + manager.putEnv("test1", RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", true))); + manager.putEnv("test2", RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", false))); + + Reflect.on(entrance).call("updateSelectEnv", "test1"); + Reflect.on(entrance).call("updateSelectEnv", "test2"); + + + Assert.assertEquals(manager.getWorkspaceInfo("test1").getConnection(), RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "password", "", "", true)).getConnection()); + Assert.assertEquals(manager.getWorkspaceInfo("test2").getConnection(), RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("url", "userName", "", "", "", false)).getConnection()); + + PowerMock.verifyAll(); + + } + } \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/design/env/RemoteWorkspaceTest.java b/designer-base/src/test/java/com/fr/design/env/RemoteWorkspaceTest.java index fe7f365e6..35b18fbf1 100644 --- a/designer-base/src/test/java/com/fr/design/env/RemoteWorkspaceTest.java +++ b/designer-base/src/test/java/com/fr/design/env/RemoteWorkspaceTest.java @@ -38,7 +38,7 @@ public class RemoteWorkspaceTest { EasyMock.replay(workspace, operator); PowerMock.replayAll(); - WorkspaceConnectionInfo info = new WorkspaceConnectionInfo("url", "username", "password", "certPath", "certSecretKey"); + WorkspaceConnectionInfo info = new WorkspaceConnectionInfo("url", "username", "password", "certPath", "certSecretKey", true); RemoteWorkspace remoteWorkspace= new RemoteWorkspace(null, info); @@ -51,4 +51,5 @@ public class RemoteWorkspaceTest { } + } \ No newline at end of file