From 3b1cb33184c84edfc8a6bba711ab9d47acd648b4 Mon Sep 17 00:00:00 2001 From: Sam Davis Date: Wed, 16 Jan 2013 11:14:38 -0800 Subject: 326119: Repository credentials are overwritten during repository settings validation Change-Id: I0f8becdc0bc2869d67de80401920bf6f7d69bd87 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=326119 --- .../eclipse/mylyn/tasks/core/TaskRepository.java | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse') 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 3cc5f42a8..4dc4d7995 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 @@ -233,6 +233,8 @@ public final class TaskRepository extends PlatformObject { private transient volatile boolean updating; + private boolean shouldPersistCredentials = true; + public TaskRepository(String connectorKind, String repositoryUrl) { this(connectorKind, repositoryUrl, NO_VERSION_SPECIFIED); } @@ -284,7 +286,7 @@ public final class TaskRepository extends PlatformObject { } private void addAuthInfo(String username, String password, String userProperty, String passwordProperty) { - if (Platform.isRunning()) { + if (Platform.isRunning() && shouldPersistCredentials()) { if (useSecureStorage()) { try { ISecurePreferences securePreferences = getSecurePreferences(); @@ -387,7 +389,7 @@ public final class TaskRepository extends PlatformObject { } synchronized (LOCK) { - if (Platform.isRunning()) { + if (Platform.isRunning() && shouldPersistCredentials()) { if (useSecureStorage()) { if (Platform.isRunning()) { ISecurePreferences securePreferences = getSecurePreferences(); @@ -431,7 +433,7 @@ public final class TaskRepository extends PlatformObject { @SuppressWarnings("unchecked") private String getAuthInfo(String property) { - if (Platform.isRunning()) { + if (Platform.isRunning() && shouldPersistCredentials()) { if (useSecureStorage()) { String propertyValue = null; if (property.equals(getKeyPrefix(AuthenticationType.REPOSITORY) + USERNAME)) { @@ -481,6 +483,29 @@ public final class TaskRepository extends PlatformObject { } } + /** + * Returns {@code} if credentials persisted in the platform keystore. + * + * @since 3.10 + * @see #setShouldPersistCredentials(boolean) + */ + public boolean shouldPersistCredentials() { + return shouldPersistCredentials; + } + + /** + * Toggles the flag for persisting credentials. If {@code shouldPersistCredentials} is {@code false} credentials + * will not be persisted in the platform keystore. + *

+ * This flag does not have any effect if not running in an OSGi environment. + * + * @since 3.10 + * @see #shouldPersistCredentials() + */ + public void setShouldPersistCredentials(boolean shouldPersistCredentials) { + this.shouldPersistCredentials = shouldPersistCredentials; + } + public String getCharacterEncoding() { final String encoding = properties.get(IRepositoryConstants.PROPERTY_ENCODING); return encoding == null || "".equals(encoding) ? DEFAULT_CHARACTER_ENCODING : encoding; //$NON-NLS-1$ -- cgit v1.2.3