Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-02-19 17:17:04 -0500
committerSam Davis2014-03-03 21:44:28 -0500
commit65dac84d9258b64323ef4ddead930732293c4d21 (patch)
treecc042c2130997b2c3f744a54e93aea4f26860d2d
parentb1b3ad53aa1c59dc78b586c9ef71433c3ae92505 (diff)
downloadorg.eclipse.mylyn.tasks-65dac84d9258b64323ef4ddead930732293c4d21.tar.gz
org.eclipse.mylyn.tasks-65dac84d9258b64323ef4ddead930732293c4d21.tar.xz
org.eclipse.mylyn.tasks-65dac84d9258b64323ef4ddead930732293c4d21.zip
428504: bugzilla connector is logged out after credentials migrated from
keyring Change-Id: I033be68acf2686a087058a7474289c842d7deebe Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=428504
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TaskRepositoryKeyringMigrator.java13
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java81
2 files changed, 72 insertions, 22 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TaskRepositoryKeyringMigrator.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TaskRepositoryKeyringMigrator.java
index d86d87832..a552c4ea4 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TaskRepositoryKeyringMigrator.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/util/TaskRepositoryKeyringMigrator.java
@@ -20,6 +20,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.repositories.core.auth.ICredentialsStore;
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
import org.eclipse.mylyn.tasks.core.TaskRepository;
@@ -54,6 +56,17 @@ public class TaskRepositoryKeyringMigrator extends KeyringMigrator<TaskRepositor
}
@Override
+ protected void migrateCredentials(TaskRepository location) {
+ super.migrateCredentials(location);
+ // clear the cachedUserName in case it was set before the migration ran
+ AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
+ if (credentials != null) {
+ location.setCredentials(AuthenticationType.REPOSITORY, credentials,
+ location.getSavePassword(AuthenticationType.REPOSITORY));
+ }
+ }
+
+ @Override
protected Map<String, String> getAuthorizationInfo(String url) throws MalformedURLException {
try {
return super.getAuthorizationInfo(url);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
index 04e7a5721..cd5880d4a 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskRepositoryManagerTest.java
@@ -105,15 +105,14 @@ public class TaskRepositoryManagerTest extends TestCase {
public void testsUseSecureStorage() throws Exception {
TaskRepository repository = new TaskRepository("bugzilla", "http://repository2/");
+ flushAuthenticationCredentials(repository);
repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials("testUserName",
"testPassword"), true);
repository.setCredentials(AuthenticationType.HTTP,
new AuthenticationCredentials("httpUserName", "httpPassword"), true);
- ISecurePreferences securePreferences = SecurePreferencesFactory.getDefault().node(
- SECURE_CREDENTIALS_STORE_NODE_ID);
- securePreferences = securePreferences.node(EncodingUtils.encodeSlashes(repository.getUrl()));
+ ISecurePreferences securePreferences = getSecurePreferences(repository);
assertEquals("testPassword", securePreferences.get(AUTH_PASSWORD, null));
assertNull(securePreferences.get(AUTH_USERNAME, null));
assertEquals("httpUserName", securePreferences.get(AUTH_HTTP_USERNAME, null));
@@ -135,30 +134,50 @@ public class TaskRepositoryManagerTest extends TestCase {
}
public void testMigrationFromKeyring() throws Exception {
- Map<String, String> authInfo = new HashMap<String, String>();
- authInfo.put(AUTH_USERNAME, "testuser");
- authInfo.put(AUTH_PASSWORD, "testpassword");
- authInfo.put(AUTH_HTTP_USERNAME, "testhttpuser");
- authInfo.put(AUTH_HTTP_PASSWORD, "testhttppassword");
- authInfo.put(AUTH_PROXY_USERNAME, "testproxyuser");
- authInfo.put(AUTH_PROXY_PASSWORD, "testproxypassword");
+ Map<String, String> authInfo = createAuthInfo();
TaskRepository repository = new TaskRepository("bugzilla", "http://example.com/");
- repository.flushAuthenticationCredentials();
+ flushAuthenticationCredentials(repository);
Platform.addAuthorizationInfo(new URL(repository.getUrl()), AUTH_REALM, AUTH_SCHEME, authInfo);
new TaskRepositoryKeyringMigrator(AUTH_REALM, AUTH_SCHEME).migrateCredentials(Collections.singleton(repository));
assertCredentialsMigrated(repository);
repository = new TaskRepository("bugzilla", "I am not a url.");
- repository.flushAuthenticationCredentials();
+ flushAuthenticationCredentials(repository);
Platform.addAuthorizationInfo(new URL("http://eclipse.org/mylyn"), repository.getUrl(), AUTH_SCHEME, authInfo);
new TaskRepositoryKeyringMigrator(AUTH_REALM, AUTH_SCHEME).migrateCredentials(Collections.singleton(repository));
assertCredentialsMigrated(repository);
}
+ public void testMigrationFromKeyringAfterGetUserNameCalled() throws Exception {
+ Map<String, String> authInfo = createAuthInfo();
+
+ TaskRepository repository = new TaskRepository("bugzilla", "http://example.com/");
+ flushAuthenticationCredentials(repository);
+ Platform.addAuthorizationInfo(new URL(repository.getUrl()), AUTH_REALM, AUTH_SCHEME, authInfo);
+
+ assertNull(repository.getUserName());
+
+ new TaskRepositoryKeyringMigrator(AUTH_REALM, AUTH_SCHEME).migrateCredentials(Collections.singleton(repository));
+ assertNotNull(repository.getUserName());
+ assertTrue(repository.getUserName().equals("testuser"));
+ assertCredentialsMigrated(repository);
+ }
+
+ private Map<String, String> createAuthInfo() {
+ Map<String, String> authInfo = new HashMap<String, String>();
+ authInfo.put(AUTH_USERNAME, "testuser");
+ authInfo.put(AUTH_PASSWORD, "testpassword");
+ authInfo.put(AUTH_HTTP_USERNAME, "testhttpuser");
+ authInfo.put(AUTH_HTTP_PASSWORD, "testhttppassword");
+ authInfo.put(AUTH_PROXY_USERNAME, "testproxyuser");
+ authInfo.put(AUTH_PROXY_PASSWORD, "testproxypassword");
+ return authInfo;
+ }
+
public void testMigrationFromOldSecureStoreNode() throws Exception {
TaskRepository repository = new TaskRepository("bugzilla", "http://example.com/");
- repository.flushAuthenticationCredentials();
+ flushAuthenticationCredentials(repository);
repository.setProperty(AUTH_USERNAME, "testuser");
ISecurePreferences oldNode = SecurePreferencesFactory.getDefault().node(ITasksCoreConstants.ID_PLUGIN);
@@ -177,17 +196,35 @@ public class TaskRepositoryManagerTest extends TestCase {
StorageException {
assertEquals("testuser", repository.getProperty(AUTH_USERNAME));
- ISecurePreferences newNode = SecurePreferencesFactory.getDefault().node(SECURE_CREDENTIALS_STORE_NODE_ID);
- newNode = newNode.node(EncodingUtils.encodeSlashes(repository.getUrl()));
- assertEquals("testpassword", newNode.get(AUTH_PASSWORD, null));
- assertEquals("testhttpuser", newNode.get(AUTH_HTTP_USERNAME, null));
- assertEquals("testhttppassword", newNode.get(AUTH_HTTP_PASSWORD, null));
- assertEquals("testproxyuser", newNode.get(AUTH_PROXY_USERNAME, null));
- assertEquals("testproxypassword", newNode.get(AUTH_PROXY_PASSWORD, null));
+ ISecurePreferences securePreferences = getSecurePreferences(repository);
+ assertEquals("testpassword", securePreferences.get(AUTH_PASSWORD, null));
+ assertEquals("testhttpuser", securePreferences.get(AUTH_HTTP_USERNAME, null));
+ assertEquals("testhttppassword", securePreferences.get(AUTH_HTTP_PASSWORD, null));
+ assertEquals("testproxyuser", securePreferences.get(AUTH_PROXY_USERNAME, null));
+ assertEquals("testproxypassword", securePreferences.get(AUTH_PROXY_PASSWORD, null));
- for (String key : newNode.childrenNames()) {
- assertEquals(key.endsWith(PASSWORD), newNode.isEncrypted(key));
+ for (String key : securePreferences.childrenNames()) {
+ assertEquals(key.endsWith(PASSWORD), securePreferences.isEncrypted(key));
}
+
+ assertEquals("testpassword", repository.getCredentials(AuthenticationType.REPOSITORY).getPassword());
+ assertEquals("testhttpuser", repository.getCredentials(AuthenticationType.HTTP).getUserName());
+ assertEquals("testhttppassword", repository.getCredentials(AuthenticationType.HTTP).getPassword());
+ assertEquals("testproxyuser", repository.getCredentials(AuthenticationType.PROXY).getUserName());
+ assertEquals("testproxypassword", repository.getCredentials(AuthenticationType.PROXY).getPassword());
+ }
+
+ private ISecurePreferences getSecurePreferences(TaskRepository repository) {
+ ISecurePreferences rootNode = SecurePreferencesFactory.getDefault().node(SECURE_CREDENTIALS_STORE_NODE_ID);
+ return rootNode.node(EncodingUtils.encodeSlashes(repository.getUrl()));
+ }
+
+ private void flushAuthenticationCredentials(TaskRepository repository) {
+ repository.flushAuthenticationCredentials();
+ assertTrue(getSecurePreferences(repository).keys().length == 0);
+ repository.setProperty(AUTH_REPOSITORY + ".enabled", Boolean.toString(true));
+ repository.setProperty(AUTH_HTTP + ".enabled", Boolean.toString(true));
+ repository.setProperty(AUTH_PROXY + ".enabled", Boolean.toString(true));
}
public void testRepositoryWithSlash() throws MalformedURLException {

Back to the top