IDEA-159737 Clear message to user about old password db migration

This commit is contained in:
Vladimir Krivosheev
2016-08-12 14:12:07 +02:00
parent 3e5540c22a
commit 163eaf60b5
4 changed files with 15 additions and 149 deletions
@@ -17,7 +17,6 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
@@ -30,24 +29,15 @@ public class EnterPasswordComponent extends PasswordComponentBase {
private final Function<String, Boolean> myPasswordConsumer;
public EnterPasswordComponent(@NotNull Function<String, Boolean> passwordConsumer) {
super("Enter");
myPasswordConsumer = passwordConsumer;
myPromptLabel.setText("<html><br>Master password is required to unlock the password database to convert it to a new format.</html>");
UIUtil.setEnabled(myNewPasswordPanel, false, true);
myNewPasswordPanel.setVisible(false);
myPromptLabel.setText("Master password is required to convert saved password.");
if (ApplicationManager.getApplication().isUnitTestMode()) {
myPasswordField.setText("pass");
}
}
@Override
public ValidationInfo doValidate() {
return null;
}
@Override
public ValidationInfo apply() {
// enter password — only and only old key, so, we use EncryptionUtil.genPasswordKey
@@ -18,78 +18,40 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.List;
/**
* The dialog used to prompt for the master password to the password database
*/
public class MasterPasswordDialog extends DialogWrapper {
private final static int NUMBER_OF_RETRIES = 5;
private final JPanel myRootPanel = new JPanel(new CardLayout());
private final List<PasswordComponentBase> myComponents = ContainerUtil.newArrayList();
private final DialogWrapperAction myCardAction;
private final JPanel myRootPanel;
private final PasswordComponentBase myComponent;
private int myRetriesCount;
public MasterPasswordDialog(@NotNull PasswordComponentBase component) {
super(false);
myComponent = component;
setResizable(false);
myComponents.add(component);
myRootPanel.add(component.getComponent(), component.getTitle());
myCardAction = new DialogWrapperAction("") {
@Override
protected void doAction(ActionEvent e) {
show(getNextComponent(getSelectedComponent()));
}
};
show(myComponents.get(0));
myRootPanel = component.getComponent();
setTitle("Password Manager Database Updated");
getOKAction().putValue(Action.NAME, "Convert");
getCancelAction().putValue(Action.NAME, "Clear Passwords");
init();
}
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return getSelectedComponent().getPreferredFocusedComponent();
return myComponent.getPreferredFocusedComponent();
}
@Nullable
@Override
protected String getHelpId() {
return getSelectedComponent().getHelpId();
}
private CardLayout getLayout() {
return (CardLayout)myRootPanel.getLayout();
}
private PasswordComponentBase getSelectedComponent() {
for (PasswordComponentBase component : myComponents) {
if (component.getComponent().isVisible()) return component;
}
throw new AssertionError("no visible components");
}
@NotNull
private PasswordComponentBase getNextComponent(@NotNull PasswordComponentBase component) {
int idx = myComponents.indexOf(component);
int next = idx < myComponents.size() - 1 ? idx + 1 : 0;
return myComponents.get(next);
}
private void show(@NotNull PasswordComponentBase component) {
setTitle(component.getTitle() + " Master Password");
getLayout().show(myRootPanel, component.getTitle());
myCardAction.putValue(Action.NAME, getNextComponent(component).getTitle() + "...");
component.getPreferredFocusedComponent().requestFocus();
return myComponent.getHelpId();
}
@Override
@@ -97,29 +59,9 @@ public class MasterPasswordDialog extends DialogWrapper {
return myRootPanel;
}
@NotNull
@Override
protected Action[] createActions() {
Action[] result = {
getHelpAction(),
getOKAction(),
getCancelAction()};
if (myComponents.size() > 1) {
return ArrayUtil.append(result, myCardAction);
}
return result;
}
@Nullable
@Override
protected ValidationInfo doValidate() {
return getSelectedComponent().doValidate();
}
@Override
public void doOKAction() {
PasswordComponentBase component = getSelectedComponent();
ValidationInfo info = component.apply();
ValidationInfo info = myComponent.apply();
if (info == null) {
super.doOKAction();
}
@@ -31,7 +31,7 @@
<grid row="4" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="89256" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="89256" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="3" col-span="2" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -41,50 +41,6 @@
<size top="0" left="10" bottom="10" right="0"/>
</border>
<children>
<grid id="1920e" binding="myNewPasswordPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="2" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="true"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="77a6b" class="javax.swing.JLabel" binding="myNewPasswordLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="49e2"/>
<text value="&amp;New password"/>
</properties>
</component>
<component id="49e2" class="javax.swing.JPasswordField" binding="myNewPasswordField" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="4fa5f" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="ebb15"/>
<text value="&amp;Confirm password"/>
</properties>
</component>
<component id="ebb15" class="javax.swing.JPasswordField" binding="myConfirmPasswordField" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
</children>
</grid>
<grid id="a4f86" binding="myPasswordPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
@@ -18,32 +18,23 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Arrays;
/**
* @author gregsh
*/
public abstract class PasswordComponentBase {
private final String myTitle;
private JPanel myRootPanel;
private JLabel myIconLabel;
protected JLabel myPromptLabel;
protected JPanel myPasswordPanel;
protected JPanel myNewPasswordPanel;
protected JPasswordField myPasswordField;
protected JPasswordField myNewPasswordField;
protected JPasswordField myConfirmPasswordField;
protected JLabel myPasswordLabel;
protected JLabel myNewPasswordLabel;
public PasswordComponentBase(@NotNull String title) {
myTitle = title;
public PasswordComponentBase() {
myIconLabel.setText("");
myIconLabel.setIcon(AllIcons.General.PasswordLock);
myIconLabel.setDisabledIcon(AllIcons.General.PasswordLock);
@@ -51,25 +42,12 @@ public abstract class PasswordComponentBase {
myPromptLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
}
public JComponent getComponent() {
public JPanel getComponent() {
return myRootPanel;
}
public JComponent getPreferredFocusedComponent() {
if (myPasswordField.isEnabled()) return myPasswordField;
else if (myNewPasswordField.isEnabled()) return myNewPasswordField;
throw new AssertionError("no visible fields found");
}
public String getTitle() {
return myTitle;
}
public ValidationInfo doValidate() {
if (myNewPasswordField.isEnabled() && !Arrays.equals(myNewPasswordField.getPassword(), myConfirmPasswordField.getPassword())) {
return new ValidationInfo("New passwords do not match", myConfirmPasswordField);
}
return null;
return myPasswordField;
}
@Nullable