Adds functionality to save passwords and nicknames for chat rooms.

cusax-fix
hristoterezov 12 years ago
parent e464156bad
commit 818ace92b4

@ -124,6 +124,7 @@ service.gui.CHAT_ROOM_REGISTRATION_REQUIRED=The {0} chat room requires registrat
service.gui.CHAT_ROOM_REQUIRES_PASSWORD=The {0} chat room has requested a password.
service.gui.CHAT_ROOMS=Chat rooms
service.gui.CHAT_ROOM_SUBJECT_CHANGED={0} has changed the subject to {1}
service.gui.CHAT_ROOM_REMEMBER_PASSWORD=Remember password
service.gui.CHOOSE_CONTACT=Choose contact
service.gui.CHOOSE_ACCOUNT=Please select one of the listed accounts.
service.gui.CITY=City

@ -15,6 +15,7 @@
import net.java.sip.communicator.service.callhistory.*;
import net.java.sip.communicator.service.contactlist.*;
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.customcontactactions.*;
import net.java.sip.communicator.service.desktop.*;
import net.java.sip.communicator.service.globaldisplaydetails.*;
@ -103,6 +104,8 @@ public class GuiActivator implements BundleActivator
private static AlertUIService alertUIService;
private static CredentialsStorageService credentialsService;
private static final Map<Object, ProtocolProviderFactory>
providerFactoriesMap = new Hashtable<Object, ProtocolProviderFactory>();
@ -829,4 +832,26 @@ public static ProtocolProviderService getPreferredAccount()
}
return null;
}
/**
* Returns a reference to a CredentialsStorageService implementation
* currently registered in the bundle context or null if no such
* implementation was found.
*
* @return a currently valid implementation of the
* CredentialsStorageService.
*/
public static CredentialsStorageService getCredentialsStorageService()
{
if (credentialsService == null)
{
ServiceReference credentialsReference
= bundleContext.getServiceReference(
CredentialsStorageService.class.getName());
credentialsService
= (CredentialsStorageService) bundleContext
.getService(credentialsReference);
}
return credentialsService;
}
}

@ -364,7 +364,12 @@ else if (menuItemName.equals("changeNicknameItem"))
{
try
{
room.setUserNickname(reasonDialog.getReason().trim());
String nickname = reasonDialog.getReason().trim();
room.setUserNickname(nickname);
ConfigurationUtils.updateChatRoomProperty(
room.getParentProvider(),
room.getIdentifier(),
"userNickName", nickname);
}
catch (OperationFailedException ex)
{

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.gui.main.chat.conference;
import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.*;
@ -57,6 +58,13 @@ public class ChatRoomWrapper
*/
private Boolean persistent = null;
/**
* The prefix needed by the credential storage service to store the password
* of the chat room.
*/
private String passwordPrefix
= "net.java.sip.communicator.impl.gui.accounts.";
/**
* Creates a <tt>ChatRoomWrapper</tt> by specifying the protocol provider,
* the identifier and the name of the chat room.
@ -73,6 +81,10 @@ public ChatRoomWrapper( ChatRoomProviderWrapper parentProvider,
this.parentProvider = parentProvider;
this.chatRoomID = chatRoomID;
this.chatRoomName = chatRoomName;
passwordPrefix += getParentProvider().getProtocolProvider()
.getAccountID().getAccountUniqueID() + ".chatrooms." +
getChatRoomID() + ".password";
}
/**
@ -172,6 +184,39 @@ public void setPersistent(boolean value)
this.persistent = value;
}
/**
* Stores the password for the chat room.
*
* @param password the password to store
*/
public void savePassword(String password)
{
GuiActivator.getCredentialsStorageService()
.storePassword(passwordPrefix, password);
}
/**
* Returns the password for the chat room.
*
* @return the password
*/
public String loadPassword()
{
return GuiActivator.getCredentialsStorageService()
.loadPassword(passwordPrefix);
}
/**
* Removes the saved password for the chat room.
*/
public void removePassword()
{
GuiActivator.getCredentialsStorageService()
.removePassword(passwordPrefix);
}
/**
* Is room set to auto join on start-up.
* @return is auto joining enabled.

@ -629,6 +629,39 @@ public void rejectInvitation(
multiUserChatAdHocOpSet.rejectInvitation(invitation, reason);
}
/**
* Joins the given chat room with the given password and manages all the
* exceptions that could occur during the join process.
*
* @param chatRoomWrapper the chat room to join.
* @param nickName the nickname we choose for the given chat room.
* @param password the password.
* @param rememberPassword if true the password should be saved.
*/
public void joinChatRoom( ChatRoomWrapper chatRoomWrapper,
String nickName,
byte[] password,
boolean rememberPassword)
{
ChatRoom chatRoom = chatRoomWrapper.getChatRoom();
if(chatRoom == null)
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString("service.gui.WARNING"),
GuiActivator.getResources().getI18NString(
"service.gui.CHAT_ROOM_NOT_CONNECTED",
new String[]{chatRoomWrapper.getChatRoomName()}))
.showDialog();
return;
}
new JoinChatRoomTask(chatRoomWrapper, nickName, password,
rememberPassword).execute();
}
/**
* Joins the given chat room with the given password and manages all the
* exceptions that could occur during the join process.
@ -658,7 +691,6 @@ public void joinChatRoom( ChatRoomWrapper chatRoomWrapper,
new JoinChatRoomTask(chatRoomWrapper, nickName, password).execute();
}
/**
* Creates a chat room, by specifying the chat room name, the parent
* protocol provider and eventually, the contacts invited to participate in
@ -1462,14 +1494,42 @@ private static class JoinChatRoomTask
private final byte[] password;
private final boolean rememberPassword;
JoinChatRoomTask( ChatRoomWrapper chatRoomWrapper,
String nickName,
byte[] password)
byte[] password,
boolean rememberPassword)
{
this.chatRoomWrapper = chatRoomWrapper;
this.nickName = nickName;
if(password == null)
{
String passString = chatRoomWrapper.loadPassword();
if(passString != null)
{
this.password = passString.getBytes();
}
else
{
this.password = null;
}
}
else
{
this.password = password;
}
this.rememberPassword = rememberPassword;
}
JoinChatRoomTask( ChatRoomWrapper chatRoomWrapper,
String nickName,
byte[] password)
{
this(chatRoomWrapper, nickName, password, false);
}
/**
* @override {@link SwingWorker}{@link #doInBackground()} to perform
@ -1540,7 +1600,8 @@ protected void done()
if(AUTHENTICATION_FAILED.equals(returnCode))
{
ChatRoomAuthenticationWindow authWindow
= new ChatRoomAuthenticationWindow(chatRoomWrapper);
= new ChatRoomAuthenticationWindow(chatRoomWrapper,
nickName);
authWindow.setVisible(true);
}
@ -1574,14 +1635,22 @@ else if(SUBSCRIPTION_ALREADY_EXISTS.equals(returnCode))
new String[]{chatRoomWrapper.getChatRoomName()});
}
if (!SUCCESS.equals(returnCode)
&& !AUTHENTICATION_FAILED.equals(returnCode))
if (!SUCCESS.equals(returnCode))
{
if(!AUTHENTICATION_FAILED.equals(returnCode))
{
new ErrorDialog(
GuiActivator.getUIService().getMainFrame(),
GuiActivator.getResources().getI18NString(
"service.gui.ERROR"), errorMessage).showDialog();
}
chatRoomWrapper.removePassword();
}
if (SUCCESS.equals(returnCode) && rememberPassword)
{
chatRoomWrapper.savePassword(new String(password));
}
}
}

@ -195,10 +195,31 @@ else if (itemName.equals("openChatRoom"))
}
else if(itemName.equals("joinAsChatRoom"))
{
ChatRoomAuthenticationWindow authWindow
= new ChatRoomAuthenticationWindow(chatRoomWrapper);
String nickName = null;
ChatOperationReasonDialog reasonDialog =
new ChatOperationReasonDialog(GuiActivator
.getResources().getI18NString(
"service.gui.CHANGE_NICKNAME"), GuiActivator
.getResources().getI18NString(
"service.gui.CHANGE_NICKNAME_LABEL"));
authWindow.setVisible(true);
reasonDialog.setReasonFieldText(chatRoomWrapper
.getChatRoom().getUserNickname());
int result = reasonDialog.showDialog();
if (result == MessageDialog.OK_RETURN_CODE)
{
nickName = reasonDialog.getReason().trim();
ConfigurationUtils.updateChatRoomProperty(
chatRoomWrapper.getParentProvider().getProtocolProvider(),
chatRoomWrapper.getChatRoomID(), "userNickName",
nickName);
}
GuiActivator.getUIService().getConferenceChatManager()
.joinChatRoom(chatRoomWrapper, nickName, null);
}
else if(itemName.equals("nickNameChatRoom"))
{

@ -417,7 +417,7 @@ else if(sourceButton.equals(okButton))
}
GuiActivator.getUIService().getConferenceChatManager()
.joinChatRoom(chatRoomWrapper);
.joinChatRoom(chatRoomWrapper, nickName, null);
ChatWindowManager chatWindowManager =
GuiActivator.getUIService().getChatWindowManager();

@ -15,6 +15,7 @@
import net.java.sip.communicator.impl.gui.main.chat.conference.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.util.*;
import net.java.sip.communicator.util.skin.*;
/**
@ -31,13 +32,10 @@ public class ChatRoomAuthenticationWindow
{
private JTextArea infoTextArea = new JTextArea();
private JLabel idLabel = new JLabel(
GuiActivator.getResources().getI18NString("service.gui.IDENTIFIER"));
private JLabel passwdLabel = new JLabel(
GuiActivator.getResources().getI18NString("service.gui.PASSWORD"));
private JTextField idValue;
private JCheckBox rememberPassword;
private JPasswordField passwdField = new JPasswordField(15);
@ -53,6 +51,11 @@ public class ChatRoomAuthenticationWindow
private JPanel textFieldsPanel =
new TransparentPanel(new GridLayout(0, 1, 8, 8));
private JPanel bottomPanel =
new TransparentPanel(new GridLayout(0, 1, 8, 8));
private JPanel mainPanel = new TransparentPanel(new BorderLayout(10, 10));
private JPanel buttonsPanel =
@ -62,14 +65,18 @@ public class ChatRoomAuthenticationWindow
private ChatRoomWrapper chatRoom;
private String nickname;
/**
* Creates an instance of the <tt>LoginWindow</tt>.
* @param chatRoom the chat room for which we're authenticating
*/
public ChatRoomAuthenticationWindow(ChatRoomWrapper chatRoom)
public ChatRoomAuthenticationWindow(ChatRoomWrapper chatRoom, String nickname)
{
this.chatRoom = chatRoom;
this.nickname = nickname;
ImageIcon logoImage
= new ImageIcon(chatRoom.getParentProvider().getImage());
@ -104,9 +111,7 @@ public ChatRoomAuthenticationWindow(ChatRoomWrapper chatRoom)
*/
private void init()
{
this.idValue = new JTextField(
chatRoom.getParentProvider().getProtocolProvider()
.getAccountID().getUserID());
this.infoTextArea.setOpaque(false);
this.infoTextArea.setLineWrap(true);
@ -118,22 +123,25 @@ private void init()
"service.gui.CHAT_ROOM_REQUIRES_PASSWORD",
new String[]{chatRoom.getChatRoomName()}));
this.idLabel.setFont(idLabel.getFont().deriveFont(Font.BOLD));
this.passwdLabel.setFont(passwdLabel.getFont().deriveFont(Font.BOLD));
this.labelsPanel.add(idLabel);
this.labelsPanel.add(passwdLabel);
this.textFieldsPanel.add(idValue);
this.textFieldsPanel.add(passwdField);
this.textFieldsPanel.add(passwdField);
this.rememberPassword = new JCheckBox(GuiActivator.getResources()
.getI18NString("service.gui.CHAT_ROOM_REMEMBER_PASSWORD"),
chatRoom.isPersistent());
this.bottomPanel.add(rememberPassword);
this.buttonsPanel.add(loginButton);
this.buttonsPanel.add(cancelButton);
this.bottomPanel.add(buttonsPanel);
this.mainPanel.add(infoTextArea, BorderLayout.NORTH);
this.mainPanel.add(labelsPanel, BorderLayout.WEST);
this.mainPanel.add(textFieldsPanel, BorderLayout.CENTER);
this.mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
this.mainPanel.add(bottomPanel, BorderLayout.SOUTH);
this.backgroundPanel.add(mainPanel, BorderLayout.CENTER);
@ -163,7 +171,8 @@ private void setTransparent(boolean transparent) {
this.mainPanel.setOpaque(!transparent);
this.labelsPanel.setOpaque(!transparent);
this.textFieldsPanel.setOpaque(!transparent);
this.buttonsPanel.setOpaque(!transparent);
this.bottomPanel.setOpaque(!transparent);
}
/**
@ -181,8 +190,10 @@ public void actionPerformed(ActionEvent evt)
if (buttonName.equals("ok"))
{
GuiActivator.getUIService().getConferenceChatManager()
.joinChatRoom(chatRoom, idValue.getText(),
new String(passwdField.getPassword()).getBytes());
.joinChatRoom(chatRoom, nickname,
new String(passwdField.getPassword()).getBytes(),
rememberPassword.isSelected());
}
this.dispose();

@ -76,4 +76,5 @@ Import-Package: com.apple.eawt,
org.jitsi.util.event,
org.jitsi.util.swing,
org.osgi.framework,
say.swing
say.swing,
net.java.sip.communicator.service.credentialsstorage

Loading…
Cancel
Save