Improve reliability with regards to bad config files.
This commit is contained in:
parent
be0ae7ff45
commit
c38920f238
@ -1,5 +1,7 @@
|
|||||||
package com.lyndir.lhunath.masterpassword;
|
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.base.Splitter;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@ -8,6 +10,7 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
|
||||||
@ -45,13 +48,9 @@ public class ConfigAuthenticationPanel extends AuthenticationPanel implements It
|
|||||||
return (User) userField.getSelectedItem();
|
return (User) userField.getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getHelpText() {
|
public String getHelpText() {
|
||||||
return "<html>"
|
return "Reads users from ~/.mpw, the following syntax applies:\nUser Name:masterpassword"
|
||||||
+ "Reads users from ~/.mpw<br><br>"
|
+ "\n\nEnsure the file's permissions make it only readable by you!";
|
||||||
+ "Use the following syntax:<br>"
|
|
||||||
+ "My Name:mymasterpassword<br><br>"
|
|
||||||
+ "Make sure the read permissions<br>to the file are safe!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasConfigUsers() {
|
public static boolean hasConfigUsers() {
|
||||||
@ -75,11 +74,21 @@ public class ConfigAuthenticationPanel extends AuthenticationPanel implements It
|
|||||||
return Iterables.toArray( users.build(), User.class );
|
return Iterables.toArray( users.build(), User.class );
|
||||||
}
|
}
|
||||||
catch (FileNotFoundException e) {
|
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();
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,26 +97,8 @@ public class UnlockFrame extends JFrame {
|
|||||||
typeHelp.addActionListener( new ActionListener() {
|
typeHelp.addActionListener( new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final ActionEvent e) {
|
public void actionPerformed(final ActionEvent e) {
|
||||||
final JDialog dialog = new JDialog( UnlockFrame.this, "Help", true );
|
JOptionPane.showMessageDialog( UnlockFrame.this, authenticationPanel.getHelpText(), "Help",
|
||||||
dialog.setContentPane( new JPanel( new BorderLayout( 8, 8 ) ) {
|
JOptionPane.INFORMATION_MESSAGE );
|
||||||
{
|
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
if (authenticationPanel.getHelpText() == null) {
|
if (authenticationPanel.getHelpText() == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user