Removed notion of a 'password' from Google Contacts implementation.

Removed all references to using/requesting/storing a password, since
client login authentication is now deprecated and there is no reason to
believe that this is coming back any time soon.

+ a bit of fine-tuning in exception handling
maven
Danny van Heumen 11 years ago
parent d0e0b7b34e
commit aa5eeee24a

@ -273,14 +273,12 @@ public void run()
className = className.substring(0, className.lastIndexOf('.'));
String acc = ProtocolProviderFactory.findAccountPrefix(
bundleContext, provider.getAccountID(), className);
String password = getCredentialsService().loadPassword(acc);
if(configService.getBoolean(acc + ".GOOGLE_CONTACTS_ENABLED",
true))
{
enableContactSource(
provider.getAccountID().getAccountAddress(),
password,
provider.getProtocolDisplayName().equals(
"Google Talk"));
}
@ -341,16 +339,15 @@ public void stop(BundleContext bundleContext)
* <tt>GoogleContactsConnection</tt>.
*
* @param login login
* @param password password
* @param googleTalk if the provider service is GoogleTalk
* @return a <tt>GoogleContactsSourceService</tt> instance
*/
public static GoogleContactsSourceService enableContactSource(
String login, String password,
String login,
boolean googleTalk)
{
GoogleContactsSourceService css = new GoogleContactsSourceService(
login, password);
GoogleContactsSourceService css =
new GoogleContactsSourceService(login);
ServiceRegistration<?> cssServiceRegistration = null;
css.setGoogleTalk(googleTalk);

@ -42,11 +42,6 @@ public class GoogleContactsConnectionImpl
*/
private String login = null;
/**
* Password.
*/
private String password = null;
/**
* If the connection is enabled.
*/
@ -67,12 +62,10 @@ public class GoogleContactsConnectionImpl
* Constructor.
*
* @param login the login to connect to the service
* @param password the password to connect to the service
*/
public GoogleContactsConnectionImpl(String login, String password)
public GoogleContactsConnectionImpl(String login)
{
this.login = login;
this.password = password;
googleService.useSsl();
}
@ -96,16 +89,6 @@ public String getLogin()
return login;
}
/**
* get password.
*
* @return password to connect to the service
*/
public String getPassword()
{
return password;
}
/**
* Set login.
*
@ -116,16 +99,6 @@ public void setLogin(String login)
this.login = login;
}
/**
* Set password.
*
* @param password password to connect to the service
*/
public void setPassword(String password)
{
this.password = password;
}
/**
* Initialize connection.
*
@ -169,12 +142,22 @@ public synchronized ContactFeed query(final ContactQuery query)
{
return this.googleService.query(query, ContactFeed.class);
}
catch (NullPointerException e)
{
// Don't include a stack trace, since this is will happen at start
// of Jitsi, as we do not have a valid access token available yet.
logger.info("Executing query failed with NPE. "
+ "Refreshing access token and trying again.");
// Maybe we should request an access token immediately after loading
// the refresh token from the credentials store?
this.store.refresh();
}
catch (Exception e)
{
// FIXME if possible narrow down the exceptions on which to
// refresh token
logger.info("Failed to execute query. Going to refresh token"
+ " and try again.", e);
// Catch all and retry with refreshed token. We may need to let this
// case go through.
logger.warn("Query failed with unexpected exception. Going to try "
+ "refreshing token anyways ...", e);
this.store.refresh();
}
try

@ -12,7 +12,6 @@
import java.util.regex.*;
import net.java.sip.communicator.impl.googlecontacts.configform.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.googlecontacts.*;
import net.java.sip.communicator.util.*;
@ -103,8 +102,6 @@ private void loadConfig()
{
ConfigurationService configService =
GoogleContactsActivator.getConfigService();
CredentialsStorageService credentialsService =
GoogleContactsActivator.getCredentialsService();
List<String> list = configService.getPropertyNamesByPrefix(
CONFIGURATION_PATH, true);
@ -124,10 +121,8 @@ private void loadConfig()
if(prefix == null)
prefix = "";
String password = credentialsService.loadPassword(path);
GoogleContactsConnectionImpl cnx = (GoogleContactsConnectionImpl)
getConnection(login, password);
getConnection(login);
cnx.setEnabled(enabled);
cnx.setPrefix(prefix);
@ -188,9 +183,6 @@ public void saveConfig(GoogleContactsConnection cnx)
ConfigurationService configService =
GoogleContactsActivator.getConfigService();
CredentialsStorageService credentialsService =
GoogleContactsActivator.getCredentialsService();
String login = cnx.getLogin();
String path = CONFIGURATION_PATH + ".acc" + Math.abs(login.hashCode());
@ -207,8 +199,6 @@ public void saveConfig(GoogleContactsConnection cnx)
configService.setProperty(
path + ".prefix",
((GoogleContactsConnectionImpl)cnx).getPrefix());
credentialsService.storePassword(path, cnx.getPassword());
}
/**
@ -411,15 +401,13 @@ public List<GoogleContactsEntry> getContacts()
* Get a <tt>GoogleContactsConnection</tt>.
*
* @param login login to connect to the service
* @param password password to connect to the service
* @return <tt>GoogleContactsConnection</tt>.
*/
public GoogleContactsConnection getConnection(String login,
String password)
public GoogleContactsConnection getConnection(String login)
{
try
{
return new GoogleContactsConnectionImpl(login, password);
return new GoogleContactsConnectionImpl(login);
}
catch(Exception e)
{
@ -447,11 +435,10 @@ public void addContactSource(GoogleContactsConnection cnx,
* <tt>GoogleContactsConnection</tt>.
*
* @param login login
* @param password password
*/
public void addContactSource(String login, String password)
public void addContactSource(String login)
{
GoogleContactsActivator.enableContactSource(login, password, false);
GoogleContactsActivator.enableContactSource(login, false);
}
/**

@ -39,11 +39,6 @@ public class GoogleContactsSourceService
*/
private final String login;
/**
* Password.
*/
private final String password;
/**
* The prefix for all google contact phone numbers.
*/
@ -71,11 +66,10 @@ public class GoogleContactsSourceService
* @param login login
* @param password password
*/
public GoogleContactsSourceService(String login, String password)
public GoogleContactsSourceService(String login)
{
super();
this.login = login;
this.password = password;
}
/**
@ -88,7 +82,6 @@ public GoogleContactsSourceService(GoogleContactsConnection cnx)
super();
this.cnx = cnx;
this.login = cnx.getLogin();
this.password = cnx.getPassword();
this.phoneNumberprefix = cnx.getPrefix();
}
@ -219,7 +212,7 @@ public GoogleContactsConnectionImpl getConnection()
{
if(cnx == null)
{
cnx = new GoogleContactsConnectionImpl(login, password);
cnx = new GoogleContactsConnectionImpl(login);
if(cnx.connect() ==
GoogleContactsConnection.ConnectionStatus.

@ -208,7 +208,7 @@ private static void acquireCredential(
}
else
{
token = new TokenData("TOKEN_NOT_AVAILABLE", refreshToken, 0);
token = new TokenData(null, refreshToken, 0);
}
store.set(createCredential(store, token));
}
@ -508,16 +508,12 @@ private static class TokenData
* Constructor for TokenData container.
*
* @param accessToken the access token
* @param refreshToken the refresh token
* @param expirationTime the expiration time
* @param refreshToken the refresh token (cannot be null)
* @param expirationTime the expiration time (must be >= 0)
*/
private TokenData(final String accessToken, final String refreshToken,
final long expirationTime)
{
if (accessToken == null)
{
throw new NullPointerException("access token cannot be null");
}
this.accessToken = accessToken;
if (refreshToken == null)
{

@ -35,11 +35,6 @@ public class AccountSettingsForm
*/
private JTextField nameField;
/**
* the component holding the password
*/
private JPasswordField passwordField;
/**
* The prefix field.
*/
@ -133,29 +128,6 @@ public JPanel getContentPanel()
c.anchor = GridBagConstraints.LINE_START;
basePanel.add(nameExampleLabel, c);
JLabel passwordLabel = new JLabel(
Resources.getString("impl.googlecontacts.PASSWORD"));
this.passwordField = new JPasswordField();
nameLabel.setLabelFor(passwordField);
c.gridx = 0;
c.gridy = 2;
c.weightx = 0;
c.weighty = 0;
c.gridwidth = 1;
c.insets = new Insets(2, 50, 0, 5);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LINE_START;
basePanel.add(passwordLabel, c);
c.gridx = 1;
c.gridy = 2;
c.weightx = 1;
c.weighty = 0;
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(2, 5, 0, 50);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LINE_END;
basePanel.add(passwordField, c);
JLabel prefixLabel = new JLabel(
Resources.getString("service.gui.PREFIX"));
this.prefixField = new JTextField();
@ -184,7 +156,6 @@ public JPanel getContentPanel()
/* listeners */
this.nameField.addActionListener(this);
this.passwordField.addActionListener(this);
this.saveBtn.addActionListener(this);
this.cancelBtn.addActionListener(this);
@ -207,14 +178,12 @@ public void loadData(GoogleContactsConnection cnx)
if(cnx != null)
{
this.nameField.setText(cnx.getLogin());
this.passwordField.setText(cnx.getPassword());
this.prefixField.setText(cnx.getPrefix());
this.cnx = (GoogleContactsConnectionImpl) cnx;
}
else
{
this.nameField.setText("");
this.passwordField.setText("");
this.cnx = null;
}
}
@ -231,19 +200,17 @@ public void actionPerformed(ActionEvent e)
if(src == saveBtn)
{
String login = nameField.getText();
String password = new String(passwordField.getPassword());
String prefix = prefixField.getText();
if(cnx == null)
{
cnx = (GoogleContactsConnectionImpl) GoogleContactsActivator
.getGoogleContactsService()
.getConnection(login, password);
cnx =
(GoogleContactsConnectionImpl) GoogleContactsActivator
.getGoogleContactsService().getConnection(login);
}
else
{
cnx.setLogin(login);
cnx.setPassword(password);
}
cnx.setPrefix(prefix);

@ -42,13 +42,6 @@ public enum ConnectionStatus
*/
public String getLogin();
/**
* Get password.
*
* @return password to connect to the service
*/
public String getPassword();
/**
* Set login.
*
@ -56,13 +49,6 @@ public enum ConnectionStatus
*/
public void setLogin(String login);
/**
* Set password.
*
* @param password password to connect to the service
*/
public void setPassword(String password);
/**
* Initialize connection.
*

@ -31,12 +31,15 @@ public List<GoogleContactsEntry> searchContact(GoogleContactsConnection cnx,
/**
* Get a <tt>GoogleContactsConnection</tt>.
*
* Get a connection to Google Contacts. Only the login name may be provided.
* Passwords are not supported anymore. Authorization is acquired by
* requesting the user to go to Google and acquire an OAuth 2 approval for
* Jitsi.
*
* @param login login to connect to the service
* @param password password to connect to the service
* @return <tt>GoogleContactsConnection</tt>.
*/
public GoogleContactsConnection getConnection(String login,
String password);
public GoogleContactsConnection getConnection(String login);
/**
* Get the full contacts list.
@ -50,9 +53,8 @@ public GoogleContactsConnection getConnection(String login,
* <tt>GoogleContactsConnection</tt>.
*
* @param login login
* @param password password
*/
public void addContactSource(String login, String password);
public void addContactSource(String login);
/**
* Add a contact source service with the specified

Loading…
Cancel
Save