From aa5eeee24a5a546bd1f5b83696a231bfe71fc0f9 Mon Sep 17 00:00:00 2001 From: Danny van Heumen Date: Mon, 20 Jul 2015 21:27:51 +0200 Subject: 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 --- .../googlecontacts/GoogleContactsActivator.java | 9 ++--- .../GoogleContactsConnectionImpl.java | 47 +++++++--------------- .../googlecontacts/GoogleContactsServiceImpl.java | 23 +++-------- .../GoogleContactsSourceService.java | 11 +---- .../impl/googlecontacts/OAuth2TokenStore.java | 10 ++--- .../configform/AccountSettingsForm.java | 39 ++---------------- 6 files changed, 31 insertions(+), 108 deletions(-) (limited to 'src/net/java/sip/communicator/impl') diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java index a0ffdcd..c993339 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsActivator.java @@ -273,14 +273,12 @@ public class GoogleContactsActivator implements BundleActivator 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 class GoogleContactsActivator implements BundleActivator * GoogleContactsConnection. * * @param login login - * @param password password * @param googleTalk if the provider service is GoogleTalk * @return a GoogleContactsSourceService 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); diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java index 52d03da..350d638 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsConnectionImpl.java @@ -43,11 +43,6 @@ public class GoogleContactsConnectionImpl private String login = null; /** - * Password. - */ - private String password = null; - - /** * If the connection is enabled. */ private boolean enabled = false; @@ -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(); } @@ -97,16 +90,6 @@ public class GoogleContactsConnectionImpl } /** - * get password. - * - * @return password to connect to the service - */ - public String getPassword() - { - return password; - } - - /** * Set login. * * @param login login to connect to the service @@ -117,16 +100,6 @@ public class GoogleContactsConnectionImpl } /** - * Set password. - * - * @param password password to connect to the service - */ - public void setPassword(String password) - { - this.password = password; - } - - /** * Initialize connection. * * @return connection status @@ -169,12 +142,22 @@ public class GoogleContactsConnectionImpl { 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 diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java index adcd198..8804bfc 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsServiceImpl.java @@ -12,7 +12,6 @@ import java.util.*; 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 @@ public class GoogleContactsServiceImpl { ConfigurationService configService = GoogleContactsActivator.getConfigService(); - CredentialsStorageService credentialsService = - GoogleContactsActivator.getCredentialsService(); List list = configService.getPropertyNamesByPrefix( CONFIGURATION_PATH, true); @@ -124,10 +121,8 @@ public class GoogleContactsServiceImpl 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 class GoogleContactsServiceImpl 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 class GoogleContactsServiceImpl configService.setProperty( path + ".prefix", ((GoogleContactsConnectionImpl)cnx).getPrefix()); - - credentialsService.storePassword(path, cnx.getPassword()); } /** @@ -411,15 +401,13 @@ public class GoogleContactsServiceImpl * Get a GoogleContactsConnection. * * @param login login to connect to the service - * @param password password to connect to the service * @return GoogleContactsConnection. */ - 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 class GoogleContactsServiceImpl * GoogleContactsConnection. * * @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); } /** diff --git a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java index 6207676..c4ca332 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/GoogleContactsSourceService.java @@ -40,11 +40,6 @@ public class GoogleContactsSourceService private final String login; /** - * Password. - */ - private final String password; - - /** * The prefix for all google contact phone numbers. */ private String phoneNumberprefix; @@ -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 class GoogleContactsSourceService super(); this.cnx = cnx; this.login = cnx.getLogin(); - this.password = cnx.getPassword(); this.phoneNumberprefix = cnx.getPrefix(); } @@ -219,7 +212,7 @@ public class GoogleContactsSourceService { if(cnx == null) { - cnx = new GoogleContactsConnectionImpl(login, password); + cnx = new GoogleContactsConnectionImpl(login); if(cnx.connect() == GoogleContactsConnection.ConnectionStatus. diff --git a/src/net/java/sip/communicator/impl/googlecontacts/OAuth2TokenStore.java b/src/net/java/sip/communicator/impl/googlecontacts/OAuth2TokenStore.java index dda1041..9a503f4 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/OAuth2TokenStore.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/OAuth2TokenStore.java @@ -208,7 +208,7 @@ public class OAuth2TokenStore } else { - token = new TokenData("TOKEN_NOT_AVAILABLE", refreshToken, 0); + token = new TokenData(null, refreshToken, 0); } store.set(createCredential(store, token)); } @@ -508,16 +508,12 @@ public class OAuth2TokenStore * 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) { diff --git a/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java b/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java index 9b3d083..7dd5799 100644 --- a/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java +++ b/src/net/java/sip/communicator/impl/googlecontacts/configform/AccountSettingsForm.java @@ -36,11 +36,6 @@ public class AccountSettingsForm private JTextField nameField; /** - * the component holding the password - */ - private JPasswordField passwordField; - - /** * The prefix field. */ private JTextField prefixField; @@ -133,29 +128,6 @@ public class AccountSettingsForm 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 class AccountSettingsForm /* listeners */ this.nameField.addActionListener(this); - this.passwordField.addActionListener(this); this.saveBtn.addActionListener(this); this.cancelBtn.addActionListener(this); @@ -207,14 +178,12 @@ public class AccountSettingsForm 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 class AccountSettingsForm 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); -- cgit v1.1