diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java index 764e0f34..bfb36895 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/AuthenticationPanel.java @@ -46,4 +46,6 @@ public abstract class AuthenticationPanel extends JPanel { public Iterable getButtons() { return ImmutableList.of(); } + + public abstract void reset(); } diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java index aa755f27..98c7a899 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/GUI.java @@ -21,6 +21,7 @@ import com.google.common.base.Charsets; import com.google.common.io.*; import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.util.TypeUtils; +import com.lyndir.masterpassword.MasterKey; import java.io.*; import java.net.URI; import java.net.URL; @@ -103,12 +104,16 @@ public class GUI implements UnlockFrame.SignInCallback { public boolean signedIn(final User user) { if (!user.hasKey()) return false; - user.getKey(); + try { + user.getKey(); + passwordFrame = newPasswordFrame( user ); - passwordFrame = newPasswordFrame( user ); - - open(); - return true; + open(); + return true; + } catch (MasterKeyException e) { + JOptionPane.showMessageDialog( null, e.getLocalizedMessage(), "Sign In Failed", JOptionPane.ERROR_MESSAGE ); + return false; + } } protected PasswordFrame newPasswordFrame(final User user) { diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java index 3f6cfb5a..27ac0975 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/IncognitoAuthenticationPanel.java @@ -64,6 +64,11 @@ public class IncognitoAuthenticationPanel extends AuthenticationPanel implements return fullNameField; } + @Override + public void reset() { + masterPasswordField.setText( "" ); + } + @Override protected User getSelectedUser() { return new IncognitoUser( fullNameField.getText(), new String( masterPasswordField.getPassword() ) ); diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/MasterKeyException.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/MasterKeyException.java new file mode 100644 index 00000000..0b3862ae --- /dev/null +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/MasterKeyException.java @@ -0,0 +1,11 @@ +package com.lyndir.masterpassword.gui; + +/** + * @author lhunath, 14-12-17 + */ +public class MasterKeyException extends Exception { + + public MasterKeyException(final String message) { + super( message ); + } +} diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java index 6042527f..050f923c 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelAuthenticationPanel.java @@ -144,6 +144,11 @@ public class ModelAuthenticationPanel extends AuthenticationPanel implements Ite } ); } + @Override + public void reset() { + masterPasswordField.setText( "" ); + } + private ModelUser[] readConfigUsers() { return FluentIterable.from( MPUserFileManager.get().getUsers() ).transform( new Function() { @Nullable diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java index d8e94f40..a21fe83d 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/ModelUser.java @@ -52,13 +52,13 @@ public class ModelUser extends User { @NotNull @Override - public MasterKey getKey() { + public MasterKey getKey() throws MasterKeyException { MasterKey key = super.getKey(); if (!model.hasKeyID()) { model.setKeyID( key.getKeyID() ); MPUserFileManager.get().save(); } else if (!model.hasKeyID( key.getKeyID() )) - throw new IllegalStateException( strf( "Incorrect master password for user: %s", getFullName() ) ); + throw new MasterKeyException( strf( "Incorrect master password for user: %s", getFullName() ) ); return key; } diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java index 7818187a..d3d4a29e 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/UnlockFrame.java @@ -14,12 +14,13 @@ import javax.swing.border.*; */ public class UnlockFrame extends JFrame { - private final SignInCallback signInCallback; - private final JPanel root; - private final JButton signInButton; - private final JPanel authenticationContainer; - private boolean incognito; - public User user; + private final SignInCallback signInCallback; + private final JPanel root; + private final JButton signInButton; + private final JPanel authenticationContainer; + private AuthenticationPanel authenticationPanel; + private boolean incognito; + public User user; public UnlockFrame(final SignInCallback signInCallback) throws HeadlessException { @@ -64,7 +65,6 @@ public class UnlockFrame extends JFrame { private void createAuthenticationPanel() { authenticationContainer.removeAll(); - final AuthenticationPanel authenticationPanel; if (incognito) { authenticationPanel = new IncognitoAuthenticationPanel( this ); } else { @@ -125,13 +125,11 @@ public class UnlockFrame extends JFrame { } void trySignIn(final JComponent... signInComponents) { - if (!checkSignIn()) { + if (!checkSignIn()) return; - } - for (JComponent signInComponent : signInComponents) { + for (JComponent signInComponent : signInComponents) signInComponent.setEnabled( false ); - } signInButton.setEnabled( false ); signInButton.setText( "Signing In..." ); @@ -149,10 +147,10 @@ public class UnlockFrame extends JFrame { return; } + authenticationPanel.reset(); signInButton.setText( "Sign In" ); - for (JComponent signInComponent : signInComponents) { + for (JComponent signInComponent : signInComponents) signInComponent.setEnabled( true ); - } checkSignIn(); } } ); diff --git a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java index aacceafc..40eb7b92 100644 --- a/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java +++ b/MasterPassword/Java/masterpassword-gui/src/main/java/com/lyndir/masterpassword/gui/User.java @@ -3,8 +3,8 @@ package com.lyndir.masterpassword.gui; import static com.lyndir.lhunath.opal.system.util.StringUtils.*; import com.lyndir.masterpassword.MasterKey; +import java.security.KeyException; import javax.annotation.Nonnull; -import org.jetbrains.annotations.NotNull; /** @@ -27,12 +27,11 @@ public abstract class User { return key != null || (masterPassword != null && !masterPassword.isEmpty()); } - @NotNull @Nonnull - public MasterKey getKey() { + public MasterKey getKey() throws MasterKeyException { if (key == null) { if (!hasKey()) - throw new IllegalStateException( strf( "Master password unknown for user: %s", getFullName() ) ); + throw new MasterKeyException( strf( "Master password unknown for user: %s", getFullName() ) ); key = new MasterKey( getFullName(), getMasterPassword() ); }