Browse Source

Pull request #2183: REPORT-37262 远程设计账号密码安全增强

Merge in DESIGN/design from ~YVAN/design:release/10.0 to release/10.0

* commit '2e2c32dbc6755ecaba6e497943ad6883c2186dd6':
  REPORT-37262 远程设计账号密码安全增强 1. 做的是这个迭代任务中的子任务,功能为:密码输入时可显示长度,再次打开时隐藏密码长度,统一显示为8位的加密字符,点击密码输入框做输入或编辑密码动作时,先清空密码,再输入内容,保存后生效 2. 写了一个UIPasswordField的子类,相比UIPasswordField增加了上述功能 3. 将目标场景中的密码框替换为新的UIPasswordFieldWithFixedLength 4. 修改一些导包问题
feature/big-screen
Yvan 4 years ago
parent
commit
017a61a4a4
  1. 18
      designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java
  2. 106
      designer-base/src/main/java/com/fr/design/gui/ipasswordfield/UIPasswordFieldWithFixedLength.java
  3. 17
      designer-base/src/main/java/com/fr/env/RemoteEnvPane.java

18
designer-base/src/main/java/com/fr/design/data/datapane/connect/JDBCDefPane.java

@ -8,7 +8,7 @@ import com.fr.design.border.UITitledBorder;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icombobox.UIComboBox;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPassWordField;
import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.layout.FRGUIPaneFactory;
@ -24,8 +24,18 @@ import com.fr.general.ComparatorUtils;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
@ -108,7 +118,7 @@ public class JDBCDefPane extends JPanel {
urlTextField = new UITextField(15);
userNameTextField = new UITextField(15);
userNameTextField.setName(USER_NAME);
passwordTextField = new UIPassWordField(15);
passwordTextField = new UIPasswordFieldWithFixedLength(15);
dbtypeButton = new UIButton(".");
dbtypeButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Click_Get_Default_URL"));
dbtypeButton.addActionListener(dbtypeButtonActionListener);

106
designer-base/src/main/java/com/fr/design/gui/ipasswordfield/UIPasswordFieldWithFixedLength.java

@ -0,0 +1,106 @@
package com.fr.design.gui.ipasswordfield;
import com.fr.stable.StringUtils;
import org.jetbrains.annotations.NotNull;
import javax.swing.text.Document;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* @author Yvan
* @version 10.0
* Created by Yvan on 2020-08-11
* 有固定长度的"*"回显的密码框避免泄露密码长度
*/
public class UIPasswordFieldWithFixedLength extends UIPassWordField {
/**
* 展示密码为固定8位长度的特殊字符"*"组成
*/
private static final String DISPLAY_PASSWORD = "********";
/**
* 实际密码
*/
private String realPassword;
/**
* 用于判断是否清空密码
*/
private boolean clearPassword;
public UIPasswordFieldWithFixedLength() {
this(null, null, 0);
}
public UIPasswordFieldWithFixedLength(String text) {
this(null, text, 0);
}
public UIPasswordFieldWithFixedLength(int columns) {
this(null, null, columns);
}
public UIPasswordFieldWithFixedLength(String text, int columns) {
this(null, text, columns);
}
public UIPasswordFieldWithFixedLength(Document doc, String txt, int columns) {
super(doc, txt, columns);
initRealPassword(txt);
}
/**
* 为realPassword赋初值并添加一个鼠标单击事件
*/
public void initRealPassword(String text) {
this.realPassword = text == null ? StringUtils.EMPTY : text;
this.clearPassword = true;
addShowFixedLengthPasswordListener();
}
/**
* 当鼠标点击密码框第一次做出键入动作时清空显示密码与实际密码用户需要重新输入密码
*/
private void addShowFixedLengthPasswordListener() {
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
UIPasswordFieldWithFixedLength.this.clearPassword = true;
}
});
this.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (clearPassword) {
UIPasswordFieldWithFixedLength.this.setText(StringUtils.EMPTY);
UIPasswordFieldWithFixedLength.this.clearPassword = false;
UIPasswordFieldWithFixedLength.this.updateUI();
}
}
});
}
@Override
public void setText(@NotNull String t) {
this.realPassword = t;
// 看到代码中有些场景是将密码置为空字符串的,所以在这里加个判断
if (StringUtils.isEmpty(t)) {
super.setText(t);
} else {
super.setText(DISPLAY_PASSWORD);
}
}
@Override
public char[] getPassword() {
//如果用户刚清空密码框,并输入了新密码,则返回输入内容,否则返回realPassword
String text = new String(super.getPassword());
if (!StringUtils.isEmpty(text) && StringUtils.isEmpty(realPassword)) {
return text.toCharArray();
}
return realPassword.toCharArray();
}
}

17
designer-base/src/main/java/com/fr/env/RemoteEnvPane.java vendored

@ -13,6 +13,7 @@ import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.ipasswordfield.UIPassWordField;
import com.fr.design.gui.ipasswordfield.UIPasswordFieldWithFixedLength;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory;
@ -26,7 +27,17 @@ import com.fr.workspace.WorkContext;
import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.exception.WorkspaceAuthException;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@ -96,7 +107,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
/**
* 密码
*/
private UIPassWordField passwordInput = new UIPassWordField();
private UIPassWordField passwordInput = new UIPasswordFieldWithFixedLength();
/**
* 是否记住密码
*/
@ -108,7 +119,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
/**
* https密钥
*/
private UIPassWordField certSecretKeyInput = new UIPassWordField();
private UIPassWordField certSecretKeyInput = new UIPasswordFieldWithFixedLength();
/**
* 选择证书文件按钮
*/

Loading…
Cancel
Save