diff options
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r-- | org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java index 059d61052..7acbbb184 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java @@ -245,22 +245,22 @@ public final class TaskRepository extends PlatformObject { } private void addAuthInfo(String username, String password, String userProperty, String passwordProperty) { - synchronized (LOCK) { - if (Platform.isRunning()) { - if (useSecureStorage()) { - try { - ISecurePreferences securePreferences = getSecurePreferences(); - if (userProperty.equals(getKeyPrefix(AuthenticationType.REPOSITORY) + USERNAME)) { - this.setProperty(userProperty, username); - } else { - securePreferences.put(userProperty, username, false); - } - securePreferences.put(passwordProperty, password, true); - } catch (StorageException e) { - StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, - "Could not store authorization credentials", e)); //$NON-NLS-1$ + if (Platform.isRunning()) { + if (useSecureStorage()) { + try { + ISecurePreferences securePreferences = getSecurePreferences(); + if (userProperty.equals(getKeyPrefix(AuthenticationType.REPOSITORY) + USERNAME)) { + this.setProperty(userProperty, username); + } else { + securePreferences.put(userProperty, username, false); } - } else { + securePreferences.put(passwordProperty, password, true); + } catch (StorageException e) { + StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, + "Could not store authorization credentials", e)); //$NON-NLS-1$ + } + } else { + synchronized (LOCK) { Map<String, String> map = getAuthInfo(); if (map == null) { map = new HashMap<String, String>(); @@ -278,7 +278,9 @@ public final class TaskRepository extends PlatformObject { "Could not set authorization credentials", e)); //$NON-NLS-1$ } } - } else { + } + } else { + synchronized (LOCK) { Map<String, String> headlessCreds = credentials.get(getRepositoryUrl()); if (headlessCreds == null) { headlessCreds = new HashMap<String, String>(); @@ -390,27 +392,24 @@ public final class TaskRepository extends PlatformObject { @SuppressWarnings("unchecked") private String getAuthInfo(String property) { - synchronized (LOCK) { - if (Platform.isRunning()) { - if (useSecureStorage()) { - String propertyValue = null; - if (property.equals(getKeyPrefix(AuthenticationType.REPOSITORY) + USERNAME)) { - propertyValue = this.getProperty(property); - } else { - try { - ISecurePreferences securePreferences = getSecurePreferences(); - propertyValue = securePreferences.get(property, null); - } catch (StorageException e) { - StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, - "Could not retrieve authorization credentials", e)); //$NON-NLS-1$ - } - if (propertyValue == null) { - propertyValue = getFromLegacyKeystore(property); - } - } - return propertyValue; + if (Platform.isRunning()) { + if (useSecureStorage()) { + String propertyValue = null; + if (property.equals(getKeyPrefix(AuthenticationType.REPOSITORY) + USERNAME)) { + propertyValue = this.getProperty(property); } else { try { + ISecurePreferences securePreferences = getSecurePreferences(); + propertyValue = securePreferences.get(property, null); + } catch (StorageException e) { + StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, + "Could not retrieve authorization credentials", e)); //$NON-NLS-1$ + } + } + return propertyValue; + } else { + synchronized (LOCK) { + try { Map<String, String> map = Platform.getAuthorizationInfo(new URL(getRepositoryUrl()), AUTH_REALM, AUTH_SCHEME); if (map != null) { @@ -430,7 +429,9 @@ public final class TaskRepository extends PlatformObject { } return null; } - } else { + } + } else { + synchronized (LOCK) { Map<String, String> headlessCreds = credentials.get(getRepositoryUrl()); if (headlessCreds == null) { headlessCreds = new HashMap<String, String>(); @@ -441,28 +442,6 @@ public final class TaskRepository extends PlatformObject { } } - @SuppressWarnings("unchecked") - private String getFromLegacyKeystore(String property) { - String propertyValue = null; - try { - Map<String, String> map = Platform.getAuthorizationInfo(new URL(getRepositoryUrl()), AUTH_REALM, - AUTH_SCHEME); - if (map != null) { - propertyValue = map.get(property); - if (propertyValue != null) { - ISecurePreferences securePreferences = getSecurePreferences(); - securePreferences.put(property, propertyValue, property.endsWith(PASSWORD)); - map.remove(property); - } - } - } catch (Exception e) { - StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN, - "Could not retrieve authorization credentials", e)); //$NON-NLS-1$ - } - return propertyValue; - - } - public String getCharacterEncoding() { final String encoding = properties.get(IRepositoryConstants.PROPERTY_ENCODING); return encoding == null || "".equals(encoding) ? DEFAULT_CHARACTER_ENCODING : encoding; //$NON-NLS-1$ |