2
0

Improve reliability with regards to bad config files.

This commit is contained in:
Maarten Billemont 2014-06-14 23:33:00 -04:00
parent be0ae7ff45
commit c38920f238
2 changed files with 20 additions and 29 deletions

View File

@ -1,5 +1,7 @@
package com.lyndir.lhunath.masterpassword;
import static com.lyndir.lhunath.opal.system.util.ObjectUtils.ifNotNullElse;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@ -8,6 +10,7 @@ import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Iterator;
import java.util.NoSuchElementException;
import javax.swing.*;
@ -45,13 +48,9 @@ public class ConfigAuthenticationPanel extends AuthenticationPanel implements It
return (User) userField.getSelectedItem();
}
@Override
public String getHelpText() {
return "<html>"
+ "Reads users from ~/.mpw<br><br>"
+ "Use the following syntax:<br>"
+ "My Name:mymasterpassword<br><br>"
+ "Make sure the read permissions<br>to the file are safe!";
return "Reads users from ~/.mpw, the following syntax applies:\nUser Name:masterpassword"
+ "\n\nEnsure the file's permissions make it only readable by you!";
}
public static boolean hasConfigUsers() {
@ -75,11 +74,21 @@ public class ConfigAuthenticationPanel extends AuthenticationPanel implements It
return Iterables.toArray( users.build(), User.class );
}
catch (FileNotFoundException e) {
return null;
JOptionPane.showMessageDialog( this, "First create the config file at:\n" + mpwConfig.getAbsolutePath() +
"\n\nIt should contain a line for each user of the following format:" +
"\nUser Name:masterpassword" +
"\n\nEnsure the file's permissions make it only readable by you!", //
"Config File Not Found", JOptionPane.WARNING_MESSAGE );
return new User[0];
}
catch (IOException e) {
catch (IOException | NoSuchElementException e) {
e.printStackTrace();
return null;
String error = ifNotNullElse( e.getLocalizedMessage(), ifNotNullElse( e.getMessage(), e.toString() ) );
JOptionPane.showMessageDialog( this, //
"Problem reading config file:\n" + mpwConfig.getAbsolutePath() //
+ "\n\n" + error, //
"Config File Not Readable", JOptionPane.WARNING_MESSAGE );
return new User[0];
}
}

View File

@ -97,26 +97,8 @@ public class UnlockFrame extends JFrame {
typeHelp.addActionListener( new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final JDialog dialog = new JDialog( UnlockFrame.this, "Help", true );
dialog.setContentPane( new JPanel( new BorderLayout( 8, 8 ) ) {
{
setBorder( new EmptyBorder( 8, 8, 8, 8 ) );
}
} );
dialog.add( new JLabel( authenticationPanel.getHelpText() ), BorderLayout.CENTER );
dialog.add( new JButton( "OK" ) {
{
addActionListener( new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
dialog.dispose();
}
} );
}
}, BorderLayout.SOUTH );
dialog.pack();
dialog.setLocationRelativeTo( UnlockFrame.this );
dialog.setVisible( true );
JOptionPane.showMessageDialog( UnlockFrame.this, authenticationPanel.getHelpText(), "Help",
JOptionPane.INFORMATION_MESSAGE );
}
} );
if (authenticationPanel.getHelpText() == null) {