Applies a patch from Boris Grozev that Adds a password strength meter to XMPP password changes and improves the feature in other ways.

cusax-fix
Emil Ivov 13 years ago
parent 8ecc482d92
commit e2c6718d5b

@ -250,5 +250,19 @@
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="svn" />
</component>
<component name="libraryTable">
<library name="jsip-src">
<CLASSES>
<root url="file://$PROJECT_DIR$/../jitsi-libsrc" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/../jitsi-libsrc/jain-sip-src-1.2.159.zip!/" />
<root url="file://$PROJECT_DIR$/../jitsi-libsrc" />
<root url="file://$PROJECT_DIR$/../libjitsi/src" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/../jitsi-libsrc" recursive="false" />
</library>
</component>
</project>

@ -108,6 +108,7 @@ service.gui.CHAT_ROOM_USER_QUIT=has quit {0}
service.gui.CHAT_ROOM_NAME=Chat room name
service.gui.ROOM_NAME=Chat Room
service.gui.AUTOJOIN=Autojoin
service.gui.CHANGE_PASSWORD=Change password
service.gui.CHAT_ROOM_NAME_INFO=In the field below enter the name of the chat room that you would like to create.
service.gui.CHAT_ROOM_NOT_EXIST=The {0} room was not found in the {1} server. Please verify if the name you typed is correct.
service.gui.CHAT_ROOM_NOT_CONNECTED=You need to be logged in in order to join the {0} chat room.
@ -346,6 +347,8 @@ service.gui.OR=or
service.gui.OR_ENTER_PHONE_NUMBER=Or enter phone number here...
service.gui.OWNER=owner of the room
service.gui.PASSWORD=Password
service.gui.PASSWORD_CHANGE_FAILURE=Password change failed
service.gui.PASSWORD_CHANGE_SUCCESS=Password successfully changed
service.gui.PASTE=&Paste
service.gui.PORT=Port
service.gui.PREFIX=Prefix

@ -70,4 +70,19 @@ public void changePassword(String newPass)
e);
}
}
/**
* Returns true if the server supports password changes. This uses smack's
* <tt>AccountManager#supportsAccountCreation</tt> method, which checks for
* XEP-0077 (inband registrations) support.
* @return True if the server supports password changes, false otherwise.
*/
public boolean supportsPasswordChange()
{
org.jivesoftware.smack.AccountManager accountManager
= new org.jivesoftware.smack.AccountManager(
protocolProvider.getConnection());
return accountManager.supportsAccountCreation();
}
}

@ -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 AccountPanel(final JabberAccountRegistrationForm parentForm)
}
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 @@ void setSimpleForm(boolean isSimpleForm)
else
{
mainPanel.add(userIDPassPanel, BorderLayout.NORTH);
mainPanel.add(changePasswordPanel, BorderLayout.SOUTH);
}
}
@ -498,185 +518,120 @@ public void actionPerformed(ActionEvent evt)
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 @@ else if (protocolProvider.getTransportProtocol()
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 @@ else if (protocolProvider.getTransportProtocol()
+ " account " + protocolProvider.
getAccountID().getAccountAddress());
storeNewPassword(newPass1);
storeNewPassword(newPass);
}
catch (IllegalArgumentException ex)
{
@ -716,33 +670,29 @@ else if (protocolProvider.getTransportProtocol()
+ " 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 void actionPerformed(ActionEvent e) {
}
};
/**
* 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

@ -369,16 +369,7 @@ public void loadAccount(AccountID accountID)
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);

@ -6,34 +6,23 @@
*/
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 @@ interface MasterPasswordExecutable
*/
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;
@ -290,91 +108,6 @@ public void actionPerformed(ActionEvent e)
}
}
/**
* 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
*/
@ -384,8 +117,8 @@ public static MasterPasswordChangeDialog getInstance()
dialog = new MasterPasswordChangeDialog();
return dialog;
}
/**
/**
* @param callbackInstance callback instance.
*/
public void setCallback(MasterPasswordExecutable callbackInstance)
@ -393,22 +126,4 @@ public void setCallback(MasterPasswordExecutable callbackInstance)
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;
}
}

@ -23,4 +23,10 @@ public interface OperationSetChangePassword
*/
public void changePassword(String newPass)
throws IllegalStateException, OperationFailedException;
/**
* Whether password changes are supported.
* @return True if the server supports password change, false otherwise.
*/
public boolean supportsPasswordChange();
}

@ -4,7 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.securityconfig.masterpassword;
package net.java.sip.communicator.util;
import java.util.regex.*;

@ -12,6 +12,7 @@
import javax.imageio.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.keybindings.*;
import net.java.sip.communicator.service.netaddr.*;
import net.java.sip.communicator.service.resources.*;
@ -46,6 +47,8 @@ public class UtilActivator
private static ResourceManagementService resourceService;
private static BrowserLauncherService browserLauncherService;
private static UIService uiService;
private static BundleContext bundleContext;
@ -219,4 +222,18 @@ public static BufferedImage getImage(String imageID)
return image;
}
/**
* Gets the <tt>UIService</tt> instance registered in the
* <tt>BundleContext</tt> of the <tt>UtilActivator</tt>.
*
* @return the <tt>UIService</tt> instance registered in the
* <tt>BundleContext</tt> of the <tt>UtilActivator</tt>
*/
public static UIService getUIService()
{
if (uiService == null)
uiService = ServiceUtils.getService(bundleContext, UIService.class);
return uiService;
}
}

@ -0,0 +1,385 @@
/*
* 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.util.swing;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*;
import org.jitsi.service.resources.*;
/**
* UI dialog to change the master password.
*
* @author Dmitri Melnikov
* @author Boris Grozev
*/
public class PasswordChangeDialog
extends SIPCommDialog
implements KeyListener
{
/**
* Serial version UID.
*/
private static final long serialVersionUID = 0L;
/**
* The <tt>ResourceManagementService</tt> used by this instance to access
* the localized and internationalized resources of the application.
*/
protected final ResourceManagementService resources
= UtilActivator.getResources();
/**
* Password quality meter.
*/
private PasswordQualityMeter passwordMeter =
new PasswordQualityMeter();
/**
* Whether to show a current password field or not
*/
private boolean showCurrentPassword = false;
/**
* UI components.
*/
private JPasswordField 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;
/**
* Builds the dialog, no current password
*/
public PasswordChangeDialog()
{
this(false);
}
/**
* Builds the dialog.
*
* @param showCurrentPassword Whether to show a "current password" field
*/
public PasswordChangeDialog(boolean showCurrentPassword)
{
super(false);
this.showCurrentPassword = showCurrentPassword;
initComponents();
this.setTitle(resources
.getI18NString("service.gui.CHANGE_PASSWORD"));
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 (showCurrentPassword)
{
currentPasswdField.requestFocusInWindow();
}
else
{
newPasswordField.requestFocusInWindow();
}
}
/**
* Initializes 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("service.gui.CHANGE_PASSWORD"));
// label fields
labelsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));
if(showCurrentPassword)
{
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(showCurrentPassword)
{
currentPasswdField = new JPasswordField(15);
currentPasswdField.addActionListener(clickOkButton);
}
newPasswordField = new JPasswordField(15);
newPasswordField.addKeyListener(this);
newPasswordField.addActionListener(clickOkButton);
newAgainPasswordField = new JPasswordField(15);
newAgainPasswordField.addKeyListener(this);
newAgainPasswordField.addActionListener(clickOkButton);
textFieldsPanel = new TransparentPanel(new GridLayout(0, 1, 8, 8));
if(showCurrentPassword)
{
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.setEnabled(false);
cancelButton
= new JButton(resources.getI18NString("service.gui.CANCEL"));
cancelButton.setMnemonic(resources.getI18nMnemonic(
"service.gui.CANCEL"));
cancelButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
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);
}
/**
* Displays an error pop-up.
*
* @param message the message to display
*/
protected void displayPopupError(String message)
{
UtilActivator
.getUIService()
.getPopupDialog()
.showMessagePopupDialog(
message,
resources.getI18NString(
"service.gui.PASSWORD_CHANGE_FAILURE"),
PopupDialog.ERROR_MESSAGE);
}
/**
* Displays an info pop-up.
*
* @param message the message to display.
*/
protected void displayPopupInfo(String message)
{
UtilActivator
.getUIService()
.getPopupDialog()
.showMessagePopupDialog(
message,
resources.getI18NString(
"service.gui.PASSWORD_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)
{
}
/**
* 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(UtilActivator.getResources()
.getImage("service.gui.icons.AUTHORIZATION_ICON"));
wrapIconPanel.add(iconLabel, BorderLayout.NORTH);
return wrapIconPanel;
}
/**
* Return a reference to the "ok" button.
*
* @return a reference to the "ok" button.
*/
protected JButton getOkButton()
{
return okButton;
}
/**
* Return a reference to the "cancel" button.
*
* @return a reference to the "cancel" button.
*/
protected JButton getCancelButton()
{
return cancelButton;
}
/**
* Return the string entered in the password field.
*
* @return the string entered in the password field.
*/
protected String getNewPassword()
{
return new String(newPasswordField.getPassword());
}
/**
* Return the string entered in the "current password" field, or null if
* that field is not shown.
*
* @return the string entered in the "current password" field.
*/
protected String getCurrentPassword()
{
if(currentPasswdField == null)
{
return null;
}
else
{
return new String(currentPasswdField.getPassword());
}
}
/**
* Sets the descriptional text that is displayed
* @param infoText the new text to display.
*/
protected void setInfoText(String infoText)
{
infoTextArea.setText(infoText);
}
}

@ -28,6 +28,7 @@ Import-Package: com.sun.awt,
javax.xml.transform.stream,
net.java.sip.communicator.util,
net.java.sip.communicator.util.dns,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.keybindings,
net.java.sip.communicator.service.netaddr,

Loading…
Cancel
Save