aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin
diff options
context:
space:
mode:
authorEmil Ivov <emcho@jitsi.org>2012-09-13 12:42:30 +0000
committerEmil Ivov <emcho@jitsi.org>2012-09-13 12:42:30 +0000
commite2c6718d5b79d924dec41c5bc7308974a3af99f6 (patch)
tree1286df0b6998cfdc32cba4e9db0cc5adcb6e1e69 /src/net/java/sip/communicator/plugin
parent8ecc482d92a95b327d316e29f51b5e9d884a77fa (diff)
downloadjitsi-e2c6718d5b79d924dec41c5bc7308974a3af99f6.zip
jitsi-e2c6718d5b79d924dec41c5bc7308974a3af99f6.tar.gz
jitsi-e2c6718d5b79d924dec41c5bc7308974a3af99f6.tar.bz2
Applies a patch from Boris Grozev that Adds a password strength meter to XMPP password changes and improves the feature in other ways.
Diffstat (limited to 'src/net/java/sip/communicator/plugin')
-rw-r--r--src/net/java/sip/communicator/plugin/jabberaccregwizz/AccountPanel.java323
-rw-r--r--src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java11
-rw-r--r--src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java361
-rw-r--r--src/net/java/sip/communicator/plugin/securityconfig/masterpassword/PasswordQualityMeter.java160
4 files changed, 162 insertions, 693 deletions
diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/AccountPanel.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/AccountPanel.java
index 0bcac3a..167b0d5 100644
--- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/AccountPanel.java
+++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/AccountPanel.java
@@ -52,7 +52,8 @@ public class AccountPanel
/**
* Panel to hold the "change password" button
*/
- private final JPanel changePasswordPanel = new TransparentPanel();
+ private final JPanel changePasswordPanel
+ = new TransparentPanel(new BorderLayout(10,10));
/**
* "Change password" button
@@ -61,6 +62,11 @@ public class AccountPanel
= new JButton(Resources.getString(
"plugin.jabberaccregwizz.CHANGE_PASSWORD"));
+ /**
+ * A pane to show a message in the "change password" panel
+ */
+ private final JEditorPane changePasswordMessagePane = new JEditorPane();
+
private final JabberAccountRegistrationForm parentForm;
private final JRadioButton existingAccountButton;
@@ -139,20 +145,33 @@ public class AccountPanel
}
userIDPassPanel.add(southPanel, BorderLayout.SOUTH);
-
- this.add(mainPanel, BorderLayout.NORTH);
- changePasswordButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- ChangePasswordDialog changePasswordDialog
- = new ChangePasswordDialog();
+ changePasswordPanel.setBorder(BorderFactory.createTitledBorder(
+ Resources.getString(
+ "plugin.jabberaccregwizz.CHANGE_PASSWORD")));
+
+ changePasswordButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ JabberPasswordChangeDialog passwordChangeDialog
+ = new JabberPasswordChangeDialog();
+ passwordChangeDialog.setVisible(true);
}
});
- changePasswordPanel.add(changePasswordButton, BorderLayout.CENTER);
- //show it only if needed (when modifying an account)
+
+ changePasswordMessagePane.setOpaque(false);
+ changePasswordMessagePane.setBorder(BorderFactory.
+ createEmptyBorder(0, 5, 10, 0));
+ changePasswordMessagePane.setEditable(false);
+
+ changePasswordPanel.add(changePasswordMessagePane, BorderLayout.NORTH);
+ changePasswordPanel.add(changePasswordButton, BorderLayout.SOUTH);
+
+ //we only show that when showChangePasswordPanel is called
changePasswordPanel.setVisible(false);
- this.add(changePasswordPanel);
-
+
+ this.add(mainPanel, BorderLayout.NORTH);
}
/**
* Creates a register choice panel.
@@ -422,6 +441,7 @@ public class AccountPanel
else
{
mainPanel.add(userIDPassPanel, BorderLayout.NORTH);
+ mainPanel.add(changePasswordPanel, BorderLayout.SOUTH);
}
}
@@ -498,185 +518,120 @@ public class AccountPanel
return registerButton;
}
/**
- * Shows or hides the "change password" button
+ * Shows or hides the "change password" panel
*/
- public void showChangePasswordButton()
- {
- changePasswordPanel.setVisible(true);
+ public void showChangePasswordPanel(boolean show)
+ {
+ if(!show)
+ {
+ changePasswordPanel.setVisible(false);
+ return;
+ }
+ else
+ {
+ ProtocolProviderService protocolProvider =
+ parentForm.getWizard().getProtocolProvider();
+
+ //the button will only be enabled if our preliminary checks (the
+ //account is logged in the server supports inband registers) succeed
+ changePasswordButton.setEnabled(false);
+ if (protocolProvider == null)
+ {
+ //we shouldn't get here, because this dialog only shows
+ //when editing an existing account
+ logger.warn("protocolProvider is null");
+ changePasswordMessagePane.setText(
+ "Cannot change password for this account");
+ }
+ else if (!protocolProvider.isRegistered())
+ {
+ changePasswordMessagePane.setText(Resources.getString(
+ "plugin.jabberaccregwizz.HAS_TO_BE_LOGGED_IN"));
+ }
+ else if (!protocolProvider.getOperationSet(
+ OperationSetChangePassword.class).supportsPasswordChange())
+ {
+ changePasswordMessagePane.setText(Resources.getString(
+ "plugin.jabberaccregwizz."
+ + "SERVER_NOT_SUPPORT_PASSWORD_CHANGE"));
+ }
+ else
+ {
+ changePasswordMessagePane.setVisible(false);
+ changePasswordButton.setEnabled(true);
+ }
+
+ changePasswordPanel.setVisible(true);
+ }
}
-
+
/**
* A "change password" dialog.
*/
- private class ChangePasswordDialog extends SIPCommDialog
+ private class JabberPasswordChangeDialog extends PasswordChangeDialog
{
- /**
- * The main panel
- */
- private final JPanel mainPanel = new JPanel(new BorderLayout());
-
- /**
- * A pane for showing messages (info or errors)
- */
- private final JEditorPane messagePane = new JEditorPane();
-
- /**
- * Panel for the text fields
- */
- TransparentPanel valuesPanel
- = new TransparentPanel(new GridLayout(0, 1));
-
- /**
- * The password field
- */
- private final JPasswordField passField1 = new JPasswordField();
-
- /**
- * The confirm password field
- */
- private final JPasswordField passField2 = new JPasswordField();
-
- /**
- * Panel for the "ok" and "cancel" buttons
- */
- private final TransparentPanel buttonsPanel
- = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
/**
- * The "OK" button
+ * Default constructor.
*/
- private final JButton okButton
- = new JButton(Resources.getString("service.gui.OK"));
-
- /**
- * The "cancel" button
- */
- private final JButton cancelButton
- = new JButton(Resources.getString("service.gui.CANCEL"));
-
- /**
- * Panel for the labels
- */
- private final TransparentPanel labelsPanel
- = new TransparentPanel(new GridLayout(0, 1));
-
- /**
- * The "new password" label
- */
- private final JLabel passLabel1 = new JLabel(Resources.
- getString("plugin.jabberaccregwizz.NEW_PASSWORD"));
-
- /**
- * The "confirm password" label
- */
- private final JLabel passLabel2 = new JLabel(Resources.
- getString("plugin.jabberaccregwizz.NEW_PASSWORD_CONFIRM"));
-
-
- /**
- * Creates a full dialog (sets all the fields and buttons)
- */
- public ChangePasswordDialog()
+ public JabberPasswordChangeDialog()
{
- //don't save size and location
super(false);
-
+
setTitle(Resources.
- getString("plugin.jabberaccregwizz.CHANGE_PASSWORD"));
-
- messagePane.setOpaque(false);
- messagePane.setForeground(Color.RED);
- messagePane.setBorder(BorderFactory.createEmptyBorder(0, 0, 15, 0));
- messagePane.setEditable(false);
- mainPanel.add(messagePane, BorderLayout.NORTH);
- loadMessage(Resources.getString(
- "plugin.jabberaccregwizz.ENTER_NEW_PASSWORD"));
-
- labelsPanel.add(passLabel1);
- labelsPanel.add(passLabel2);
-
- passField1.setColumns(15);
- passField2.setColumns(15);
- valuesPanel.add(passField1);
- valuesPanel.add(passField2);
-
- okButton.addActionListener(okButtonListener);
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e){
- dispose();
- }
- });
-
- buttonsPanel.add(okButton);
- buttonsPanel.add(cancelButton);
- getRootPane().setDefaultButton(okButton);
-
- mainPanel.add(labelsPanel, BorderLayout.WEST);
- mainPanel.add(valuesPanel, BorderLayout.CENTER);
- mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
-
- mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
- getContentPane().add(mainPanel, BorderLayout.NORTH);
- setModal(true);
- setVisible(true);
- pack();
+ getString("plugin.jabberaccregwizz.CHANGE_PASSWORD"));
+ setInfoText(Resources.
+ getString("plugin.jabberaccregwizz.ENTER_NEW_PASSWORD"));
+
+ this.getOkButton().addActionListener(okButtonListener);
}
/**
* This is the ActionListener for the "ok" button.
*/
- private final ActionListener okButtonListener = new ActionListener(){
+ private final ActionListener okButtonListener = new ActionListener()
+ {
/**
- * Action for the "ok" button. This contains most of the logic for
- * the dialog:
- * It checks the fields, whether the account is logged in, tries to
- * change the password and displays messages in the message pane
+ * Action for the "ok" button. Checks whether the account is logged
+ * in, tries to change the password and displays the appropriate
+ * messages.
*/
- public void actionPerformed(ActionEvent e) {
- String newPass1 = new String(passField1.getPassword());
- String newPass2 = new String(passField2.getPassword());
+ public void actionPerformed(ActionEvent e)
+ {
+ String newPass = getNewPassword();
ProtocolProviderService protocolProvider =
parentForm.getWizard().getProtocolProvider();
- if (protocolProvider == null) {
+ if (protocolProvider == null)
+ {
//we shouldn't get here, because this dialog only shows
//when editing an existing account
logger.warn("protocolProvider is null in change"
+ " password dialog");
- loadMessage("Could not change password");
- hideCancelAndFields();
- okButton.removeActionListener(okButtonListener);
- okButton.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e)
- {
- dispose();
- }
- });
+ displayPopupError("Could not change password");
+ return;
}
- else if (!protocolProvider.isRegistered()) {
+ else if (!protocolProvider.isRegistered())
+ {
//editing an account, which is not logged in
- loadMessage(Resources.getString(
+ displayPopupError(Resources.getString(
"plugin.jabberaccregwizz.HAS_TO_BE_LOGGED_IN"));
- }
- else if (!newPass1.equals(newPass2)) {
- loadMessage(Resources.getString(
- "plugin.jabberaccregwizz.NOT_SAME_PASSWORD"));
- }
- else if (newPass1.length() <= 0) {
- loadMessage(Resources.getString(
- "plugin.jabberaccregwizz.PASSWORD_EMPTY"));
+ return;
}
else if (protocolProvider.getTransportProtocol()
- != TransportProtocol.TLS) {
- //XEP-077 advices agains changing password unless
+ != TransportProtocol.TLS)
+ {
+ //XEP-0077 advices agains changing password unless
//the underlying stream is encrypted
- loadMessage(Resources.getString(
+ displayPopupError(Resources.getString(
"plugin.jabberaccregwizz.TLS_REQUIRED"));
+ return;
}
else //try to change
{
- if (logger.isInfoEnabled()) {
+ if (logger.isInfoEnabled())
+ {
logger.info("Trying to change password for jabber"
+ " account "
+ protocolProvider.
@@ -686,10 +641,9 @@ public class AccountPanel
OperationSetChangePassword opset =
protocolProvider.getOperationSet(
OperationSetChangePassword.class);
- try {
- opset.changePassword(newPass1);
- loadMessage(Resources.getString(
- "plugin.jabberaccregwizz.PASSWORD_CHANGED"));
+ try
+ {
+ opset.changePassword(newPass);
/**
* If the old password was stored, update it with the
@@ -705,7 +659,7 @@ public class AccountPanel
+ " account " + protocolProvider.
getAccountID().getAccountAddress());
- storeNewPassword(newPass1);
+ storeNewPassword(newPass);
}
catch (IllegalArgumentException ex)
{
@@ -716,33 +670,29 @@ public class AccountPanel
+ " account " + protocolProvider.
getAccountID().getAccountAddress(),
ex);
- loadMessage(Resources.getString(
+ displayPopupError(Resources.getString(
"plugin.jabberaccregwizz."
+ "PASSWORD_NOT_STORED"));
}
-
- //now update the password field in AccountPanel,
- //because it still has the old pass and if the user
- //completes the wizard it will store it.
- passField.setText(newPass1);
}
+ //now update the password field in AccountPanel,
+ //because it still has the old pass and if the user
+ //completes the wizard it will store it.
+ passField.setText(newPass);
+
+ displayPopupInfo(Resources.getString(
+ "plugin.jabberaccregwizz.PASSWORD_CHANGED"));
+ dispose();
- hideCancelAndFields();
- okButton.removeActionListener(this);
- okButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- dispose();
- }
- });
}
catch (IllegalStateException ex) {
//we already checked for this, but if the connection
//has since been lost smack will throw this
- loadMessage(Resources.getString(
+ displayPopupError(Resources.getString(
"plugin.jabberaccregwizz.HAS_TO_BE_LOGGED_IN"));
}
catch (OperationFailedException ex) {
- loadMessage(Resources.getString(
+ displayPopupError(Resources.getString(
"plugin.jabberaccregwizz."
+ "SERVER_NOT_SUPPORT_PASSWORD_CHANGE"));
}
@@ -750,33 +700,6 @@ public class AccountPanel
}
};
-
- /**
- * Loads the given message into the message pane.
- * @param message The message to load
- */
- private void loadMessage(String message)
- {
- messagePane.setText(message);
- mainPanel.revalidate();
- mainPanel.repaint();
- pack();
- }
-
- /**
- * Leaves only the message pane and the "ok" button visible
- * XXX: a more appropriate name?
- */
- public void hideCancelAndFields()
- {
- cancelButton.setVisible(false);
- passField1.setVisible(false);
- passField2.setVisible(false);
- passLabel1.setVisible(false);
- passLabel2.setVisible(false);
- pack();
- }
-
/**
* Stores the new password in the account configuration
* @param newPass The new password
diff --git a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java
index 6008dc8..2407dec 100644
--- a/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java
+++ b/src/net/java/sip/communicator/plugin/jabberaccregwizz/JabberAccountRegistrationForm.java
@@ -369,16 +369,7 @@ public class JabberAccountRegistrationForm
String serverAddress
= accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
- //The idea here is to not show the "change password" button for
- //GTalk and Facebook acounts, or accounts in gmail, since we know
- //they don't support inband password changes.
- //This is probably a bad way to achieve it...
- if ( !serverAddress.equals("gmail.com")
- && !serverAddress.equals("talk.google.com")
- && !serverAddress.equals("chat.facebook.com"))
- {
- accountPanel.showChangePasswordButton();
- }
+ accountPanel.showChangePasswordPanel(true);
connectionPanel.setServerAddress(serverAddress);
diff --git a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java b/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java
index 24ce6f7..2ec5be7 100644
--- a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java
+++ b/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/MasterPasswordChangeDialog.java
@@ -6,35 +6,24 @@
*/
package net.java.sip.communicator.plugin.securityconfig.masterpassword;
-import java.awt.*;
import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.text.*;
-
import net.java.sip.communicator.plugin.securityconfig.*;
import net.java.sip.communicator.service.credentialsstorage.*;
-import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.swing.*;
-import org.jitsi.service.resources.*;
-
/**
* UI dialog to change the master password.
*
* @author Dmitri Melnikov
+ * @author Boris Grozev
*/
public class MasterPasswordChangeDialog
- extends SIPCommDialog
+ extends PasswordChangeDialog
implements ActionListener,
KeyListener
{
/**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- /**
* Callback interface. Implementing classes know how to change the master
* password from the old to the new one.
*/
@@ -49,240 +38,69 @@ public class MasterPasswordChangeDialog
*/
public boolean execute(String masterPassword, String newMasterPassword);
}
-
- /**
- * Dialog instance of this class.
- */
- private static MasterPasswordChangeDialog dialog;
-
- /**
- * Password quality meter.
- */
- private static PasswordQualityMeter passwordMeter =
- new PasswordQualityMeter();
-
- /**
+
+ /**
* Callback to execute on password change.
*/
private MasterPasswordExecutable callback;
-
+
/**
- * UI components.
- */
- private JTextComponent currentPasswdField;
- private JPasswordField newPasswordField;
- private JPasswordField newAgainPasswordField;
- private JButton okButton;
- private JButton cancelButton;
- private JTextArea infoTextArea;
- private JProgressBar passwordQualityBar;
- private JPanel textFieldsPanel;
- private JPanel labelsPanel;
- private JPanel buttonsPanel;
- private JPanel qualityPanel;
- private JPanel dataPanel;
-
- /**
- * The <tt>ResourceManagementService</tt> used by this instance to access
- * the localized and internationalized resources of the application.
+ * Dialog instance of this class.
*/
- private final ResourceManagementService resources
- = SecurityConfigActivator.getResources();
+ private static MasterPasswordChangeDialog dialog;
/**
* Builds the dialog.
*/
private MasterPasswordChangeDialog()
{
- super(false);
- initComponents();
-
- this.setTitle(
- resources.getI18NString(
+ super(SecurityConfigActivator.getCredentialsStorageService()
+ .isUsingMasterPassword());
+
+ setTitle(resources.getI18NString(
"plugin.securityconfig.masterpassword.MP_TITLE"));
- this.setMinimumSize(new Dimension(450, 320));
- this.setPreferredSize(new Dimension(450, 320));
- this.setResizable(false);
-
- JPanel mainPanel = new JPanel(new BorderLayout(10, 10));
- mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
-
- mainPanel.add(createIconComponent(), BorderLayout.WEST);
- mainPanel.add(dataPanel);
-
- this.getContentPane().add(mainPanel);
-
- this.pack();
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- Dimension screenSize = toolkit.getScreenSize();
-
- int x = (screenSize.width - this.getWidth()) / 2;
- int y = (screenSize.height - this.getHeight()) / 2;
-
- this.setLocation(x, y);
-
- if (currentPasswdField instanceof JPasswordField)
- {
- currentPasswdField.requestFocusInWindow();
- }
- else
- {
- newPasswordField.requestFocusInWindow();
- }
- }
-
- /**
- * Initialises the UI components.
- */
- private void initComponents()
- {
- dataPanel = new TransparentPanel(new BorderLayout(10, 10));
- dataPanel.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
-
- // info text
- infoTextArea = new JTextArea();
- infoTextArea.setEditable(false);
- infoTextArea.setOpaque(false);
- infoTextArea.setLineWrap(true);
- infoTextArea.setWrapStyleWord(true);
- infoTextArea.setFont(infoTextArea.getFont().deriveFont(Font.BOLD));
- infoTextArea.setText(
- resources.getI18NString(
- "plugin.securityconfig.masterpassword.INFO_TEXT"));
-
- // label fields
- labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));
-
- labelsPanel.add(new JLabel(resources.getI18NString(
- "plugin.securityconfig.masterpassword.CURRENT_PASSWORD")));
- labelsPanel.add(new JLabel(resources.getI18NString(
- "plugin.securityconfig.masterpassword.ENTER_PASSWORD")));
- labelsPanel.add(new JLabel(resources.getI18NString(
- "plugin.securityconfig.masterpassword.REENTER_PASSWORD")));
-
- // password fields
- ActionListener clickOkButton = new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if (okButton.isEnabled())
- okButton.doClick();
- }
- };
- if (!SecurityConfigActivator
- .getCredentialsStorageService()
- .isUsingMasterPassword())
- {
- currentPasswdField = new JTextField(resources.getI18NString(
- "plugin.securityconfig.masterpassword.MP_NOT_SET"));
- currentPasswdField.setEnabled(false);
- }
- else
- {
- currentPasswdField = new JPasswordField(15);
- ((JPasswordField) currentPasswdField)
- .addActionListener(clickOkButton);
- }
- newPasswordField = new JPasswordField(15);
- newPasswordField.addKeyListener(this);
- newAgainPasswordField = new JPasswordField(15);
- newAgainPasswordField.addKeyListener(this);
- newPasswordField.addActionListener(clickOkButton);
- newAgainPasswordField.addActionListener(clickOkButton);
-
- textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));
- textFieldsPanel.add(currentPasswdField);
- textFieldsPanel.add(newPasswordField);
- textFieldsPanel.add(newAgainPasswordField);
-
- // OK and cancel buttons
- okButton = new JButton(resources.getI18NString("service.gui.OK"));
- okButton.setMnemonic(resources.getI18nMnemonic("service.gui.OK"));
- okButton.addActionListener(this);
- okButton.setEnabled(false);
- cancelButton
- = new JButton(resources.getI18NString("service.gui.CANCEL"));
- cancelButton.setMnemonic(resources.getI18nMnemonic(
- "service.gui.CANCEL"));
- cancelButton.addActionListener(this);
-
- passwordQualityBar =
- new JProgressBar(0, PasswordQualityMeter.TOTAL_POINTS);
- passwordQualityBar.setValue(0);
-
- qualityPanel = new TransparentPanel();
- qualityPanel.setLayout(new BoxLayout(qualityPanel, BoxLayout.Y_AXIS));
-
- JLabel qualityMeterLabel = new JLabel(resources.getI18NString(
- "plugin.securityconfig.masterpassword.PASSWORD_QUALITY_METER"));
- qualityMeterLabel.setAlignmentX(CENTER_ALIGNMENT);
-
- qualityPanel.add(qualityMeterLabel);
- qualityPanel.add(passwordQualityBar);
- qualityPanel.add(Box.createVerticalStrut(15));
-
- buttonsPanel = new TransparentPanel(
- new FlowLayout(FlowLayout.RIGHT, 0, 5));
- buttonsPanel.add(okButton);
- buttonsPanel.add(cancelButton);
- qualityPanel.add(buttonsPanel);
-
- dataPanel.add(infoTextArea, BorderLayout.NORTH);
- dataPanel.add(labelsPanel, BorderLayout.WEST);
- dataPanel.add(textFieldsPanel, BorderLayout.CENTER);
- dataPanel.add(qualityPanel, BorderLayout.SOUTH);
+ setInfoText(resources.getI18NString(
+ "plugin.securityconfig.masterpassword.INFO_TEXT"));
+
+ getOkButton().addActionListener(this);
}
/**
- * OK and Cancel button event handler.
+ * OK button event handler.
*
* @param e action event
*/
public void actionPerformed(ActionEvent e)
{
- JButton sourceButton = (JButton) e.getSource();
boolean close = false;
- if (sourceButton.equals(okButton)) // ok button
- {
- CredentialsStorageService credentialsStorageService
- = SecurityConfigActivator.getCredentialsStorageService();
- String oldMasterPassword = null;
+ CredentialsStorageService credentialsStorageService
+ = SecurityConfigActivator.getCredentialsStorageService();
+ String oldMasterPassword = null;
- if (credentialsStorageService.isUsingMasterPassword())
+ if (credentialsStorageService.isUsingMasterPassword())
+ {
+ oldMasterPassword = getCurrentPassword();
+ if (oldMasterPassword.length() == 0)
{
- oldMasterPassword =
- new String(((JPasswordField) currentPasswdField)
- .getPassword());
- if (oldMasterPassword.length() == 0)
- {
- displayPopupError(
- resources.getI18NString(
- "plugin.securityconfig.masterpassword.MP_CURRENT_EMPTY"));
- return;
- }
- boolean verified =
- credentialsStorageService
- .verifyMasterPassword(oldMasterPassword);
- if (!verified)
- {
- displayPopupError(
- resources.getI18NString(
- "plugin.securityconfig.masterpassword.MP_VERIFICATION_FAILURE_MSG"));
- return;
- }
+ displayPopupError(resources.getI18NString(
+ "plugin.securityconfig.masterpassword.MP_CURRENT_EMPTY"));
+ return;
}
- // if the callback executes OK, we close the dialog
- if (callback != null)
+ boolean verified = credentialsStorageService
+ .verifyMasterPassword(oldMasterPassword);
+ if (!verified)
{
- String newPassword = new String(newPasswordField.getPassword());
- close = callback.execute(oldMasterPassword, newPassword);
+ displayPopupError(resources.getI18NString(
+ "plugin.securityconfig.masterpassword.MP_VERIFICATION_FAILURE_MSG"));
+ return;
}
}
- else // cancel button
+ // if the callback executes OK, we close the dialog
+ if (callback != null)
{
- close = true;
+ close = callback.execute(oldMasterPassword, getNewPassword());
}
-
+
if (close)
{
dialog = null;
@@ -291,91 +109,6 @@ public class MasterPasswordChangeDialog
}
/**
- * Displays an error pop-up.
- *
- * @param message the message to display
- */
- protected void displayPopupError(String message)
- {
- SecurityConfigActivator
- .getUIService()
- .getPopupDialog()
- .showMessagePopupDialog(
- message,
- resources.getI18NString(
- "plugin.securityconfig.masterpassword.MP_CHANGE_FAILURE"),
- PopupDialog.ERROR_MESSAGE);
- }
-
- /**
- * Displays an info pop-up.
- *
- * @param message the message to display.
- */
- protected void displayPopupInfo(String message)
- {
- SecurityConfigActivator
- .getUIService()
- .getPopupDialog()
- .showMessagePopupDialog(
- message,
- resources.getI18NString(
- "plugin.securityconfig.masterpassword.MP_CHANGE_SUCCESS"),
- PopupDialog.INFORMATION_MESSAGE);
- }
-
- protected void close(boolean isEscaped)
- {
- cancelButton.doClick();
- }
-
- /**
- * When a key is pressed we do 2 things. The first is to compare the two
- * password input fields and enable OK button if they are equal. The second
- * is to measure the password quality of the password from the first input
- * field.
- *
- * @param event key event
- */
- public void keyReleased(KeyEvent event)
- {
- JPasswordField source = (JPasswordField) event.getSource();
- if (newPasswordField.equals(source)
- || newAgainPasswordField.equals(source))
- {
- String password1 = new String(newPasswordField.getPassword());
- String password2 = new String(newAgainPasswordField.getPassword());
- // measure password quality
- passwordQualityBar
- .setValue(passwordMeter.assessPassword(password1));
- // enable OK button if passwords are equal
- boolean eq = (password1.length() != 0)
- && password1.equals(password2);
- okButton.setEnabled(eq);
- password1 = null;
- password2 = null;
- }
- }
-
- /**
- * Not overriding.
- *
- * @param arg0 key event
- */
- public void keyPressed(KeyEvent arg0)
- {
- }
-
- /**
- * Not overriding.
- *
- * @param arg0 key event
- */
- public void keyTyped(KeyEvent arg0)
- {
- }
-
- /**
* @return dialog instance
*/
public static MasterPasswordChangeDialog getInstance()
@@ -384,8 +117,8 @@ public class MasterPasswordChangeDialog
dialog = new MasterPasswordChangeDialog();
return dialog;
}
-
- /**
+
+ /**
* @param callbackInstance callback instance.
*/
public void setCallback(MasterPasswordExecutable callbackInstance)
@@ -393,22 +126,4 @@ public class MasterPasswordChangeDialog
this.callback = callbackInstance;
}
- /**
- * Creates the icon component to show on the left of this dialog.
- *
- * @return the created component
- */
- private static Component createIconComponent()
- {
- JPanel wrapIconPanel = new JPanel(new BorderLayout());
-
- JLabel iconLabel = new JLabel();
-
- iconLabel.setIcon(SecurityConfigActivator.getResources()
- .getImage("service.gui.icons.AUTHORIZATION_ICON"));
-
- wrapIconPanel.add(iconLabel, BorderLayout.NORTH);
-
- return wrapIconPanel;
- }
}
diff --git a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/PasswordQualityMeter.java b/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/PasswordQualityMeter.java
deleted file mode 100644
index 545e2d5..0000000
--- a/src/net/java/sip/communicator/plugin/securityconfig/masterpassword/PasswordQualityMeter.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.plugin.securityconfig.masterpassword;
-
-import java.util.regex.*;
-
-/**
- * Simple password quality meter. The JavaScript version found at
- * http://www.geekwisdom.com/js/passwordmeter.js was used as a base. Provides a
- * method to compute the relative score of the password that can be used to
- * model a progress bar, for example.
- *
- * @author Dmitri Melnikov
- */
-public class PasswordQualityMeter
-{
- /**
- * Maximum possible points.
- */
- public static final int TOTAL_POINTS = 42;
-
- /**
- * Assesses the strength of the password.
- *
- * @param pass the password to assess
- * @return the score for this password between 0 and <tt>TOTAL_POINTS</tt>
- */
- public int assessPassword(String pass)
- {
- int score = 0;
-
- if (pass == null || pass.length() == 0)
- return score;
- score += assessLength(pass);
- score += assessLetters(pass);
- score += assessNumbers(pass);
- score += assessSpecials(pass);
- return score;
- }
-
- /**
- * Assesses password length:
- * level 0 (3 point): less than 5 characters
- * level 1 (6 points): between 5 and 7 characters
- * level 2 (12 points): between 8 and 15 characters
- * level 3 (18 points): 16 or more characters
- *
- * @param pass the password to assess
- * @return the score based on the length
- */
- private int assessLength(String pass)
- {
- int len = pass.length();
-
- if (len < 5)
- return 3;
- else if (len >= 5 && len < 8)
- return 6;
- else if (len >= 8 && len < 16)
- return 12;
- // len >= 16
- return 18;
- }
-
- /**
- * Assesses letter cases:
- * level 0 (0 points): no letters
- * level 1 (5 points): all letters are either lower or upper case
- * level 2 (7 points): letters are mixed case
- *
- * @param pass the password to assess
- * @return the score based on the letters
- */
- private int assessLetters(String pass)
- {
- boolean lower = matches(pass, "[a-z]+");
- boolean upper = matches(pass, "[A-Z]+");
-
- if (lower && upper)
- return 7;
- if (lower || upper)
- return 5;
- return 0;
- }
-
- /**
- * Assesses number count:
- * level 0 (0 points): no numbers exist
- * level 1 (5 points): one or two number exists
- * level 1 (7 points): 3 or more numbers exists
- *
- * @param pass the password to assess
- * @return the score based on the numbers
- */
- private int assessNumbers(String pass)
- {
- int found = countMatches(pass, "\\d");
-
- if (found < 1)
- return 0;
- else if (found >= 1 && found < 3)
- return 5;
- return 7;
- }
-
- /**
- * Assesses special character count.
- * Here special characters are non-word and non-space ones.
- * level 0 (0 points): no special characters
- * level 1 (5 points): one special character exists
- * level 2 (10 points): more than one special character exists
- *
- * @param pass the password to assess
- * @return the score based on special characters
- */
- private int assessSpecials(String pass)
- {
- int found = countMatches(pass, "[^\\w\\s]");
-
- if (found < 1)
- return 0;
- else if (found <= 1 && found < 2)
- return 5;
- return 10;
- }
-
- /**
- * Counts the number of matches of a given pattern in a given string.
- *
- * @param str the string to search in
- * @param pattern the pattern to search for
- * @return number of matches of <tt>patter</tt> in <tt>str</tt>
- */
- private int countMatches(String str, String pattern)
- {
- Pattern p = Pattern.compile(pattern);
- Matcher matcher = p.matcher(str);
- int found = 0;
-
- while (matcher.find())
- found++;
- return found;
- }
-
- /**
- * Wrapper around @link{Pattern} and @link{Matcher} classes.
- *
- * @param str the string to search in
- * @param pattern the pattern to search for
- * @return true if <tt>pattern</tt> has been found in <tt>str</tt>.
- */
- private boolean matches(String str, String pattern)
- {
- return Pattern.compile(pattern).matcher(str).find();
- }
-}