Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 200634 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/tasks/ui/TasksUiPlugin.java (+16 lines)
Lines 34-39 Link Here
34
import org.eclipse.jface.preference.IPreferenceStore;
34
import org.eclipse.jface.preference.IPreferenceStore;
35
import org.eclipse.jface.resource.ImageDescriptor;
35
import org.eclipse.jface.resource.ImageDescriptor;
36
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
36
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
37
import org.eclipse.jface.window.Window;
37
import org.eclipse.jface.wizard.WizardDialog;
38
import org.eclipse.jface.wizard.WizardDialog;
38
import org.eclipse.mylyn.context.core.ContextCorePlugin;
39
import org.eclipse.mylyn.context.core.ContextCorePlugin;
39
import org.eclipse.mylyn.internal.context.core.ContextPreferenceContstants;
40
import org.eclipse.mylyn.internal.context.core.ContextPreferenceContstants;
Lines 41-46 Link Here
41
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
42
import org.eclipse.mylyn.internal.tasks.core.ScheduledTaskContainer;
42
import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
43
import org.eclipse.mylyn.internal.tasks.core.TaskActivityManager;
43
import org.eclipse.mylyn.internal.tasks.core.TaskDataManager;
44
import org.eclipse.mylyn.internal.tasks.core.TaskDataManager;
45
import org.eclipse.mylyn.internal.tasks.ui.EnterMemoryPassordDialog;
44
import org.eclipse.mylyn.internal.tasks.ui.IDynamicSubMenuContributor;
46
import org.eclipse.mylyn.internal.tasks.ui.IDynamicSubMenuContributor;
45
import org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter;
47
import org.eclipse.mylyn.internal.tasks.ui.ITaskHighlighter;
46
import org.eclipse.mylyn.internal.tasks.ui.ITaskListNotification;
48
import org.eclipse.mylyn.internal.tasks.ui.ITaskListNotification;
Lines 1046-1049 Link Here
1046
		}
1048
		}
1047
	}
1049
	}
1048
1050
1051
	public static void testAndSetMemoryOnlyPassword(TaskRepository repository) {
1052
		boolean bb = repository.isMemoryOnlyPassword() && repository.getCachedPassword().compareTo("")== 0;
1053
		if (bb) {
1054
			EnterMemoryPassordDialog dialog = new EnterMemoryPassordDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), repository);
1055
			int result = dialog.open();
1056
			if (result == Window.OK) {
1057
				String password = dialog.getPassword();;
1058
				if (password == null)
1059
					password = "";
1060
				repository.setCachedPassword(password);
1061
			}
1062
		}
1063
		
1064
	}
1049
}
1065
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java (+2 lines)
Lines 59-64 Link Here
59
			repository.setAuthenticationCredentials(abstractRepositorySettingsPage.getUserName(),
59
			repository.setAuthenticationCredentials(abstractRepositorySettingsPage.getUserName(),
60
					abstractRepositorySettingsPage.getPassword());
60
					abstractRepositorySettingsPage.getPassword());
61
			repository.setRepositoryLabel(abstractRepositorySettingsPage.getRepositoryLabel());
61
			repository.setRepositoryLabel(abstractRepositorySettingsPage.getRepositoryLabel());
62
			repository.setMemoryOnlyPassword(abstractRepositorySettingsPage.getMemoryonlyPassword());
63
62
			repository.setAnonymous(abstractRepositorySettingsPage.isAnonymousAccess());
64
			repository.setAnonymous(abstractRepositorySettingsPage.isAnonymousAccess());
63
			repository.setHttpAuthenticationCredentials(abstractRepositorySettingsPage.getHttpAuthUserId(),
65
			repository.setHttpAuthenticationCredentials(abstractRepositorySettingsPage.getHttpAuthUserId(),
64
					abstractRepositorySettingsPage.getHttpAuthPassword());
66
					abstractRepositorySettingsPage.getHttpAuthPassword());
(-)src/org/eclipse/mylyn/internal/tasks/ui/ScheduledTaskListSynchJob.java (+18 lines)
Lines 55-60 Link Here
55
		this.taskListManager = taskListManager;
55
		this.taskListManager = taskListManager;
56
		this.setSystem(true);
56
		this.setSystem(true);
57
		this.setPriority(Job.BUILD);
57
		this.setPriority(Job.BUILD);
58
59
		if (repositories == null) {
60
			repositories = TasksUiPlugin.getRepositoryManager().getAllRepositories();
61
		}
62
63
		for (final TaskRepository repository : repositories) {
64
			TasksUiPlugin.testAndSetMemoryOnlyPassword(repository);
65
		}
58
	}
66
	}
59
67
60
	public ScheduledTaskListSynchJob(TaskListManager taskListManager) {
68
	public ScheduledTaskListSynchJob(TaskListManager taskListManager) {
Lines 62-71 Link Here
62
		this.taskListManager = taskListManager;
70
		this.taskListManager = taskListManager;
63
		this.setPriority(Job.BUILD);
71
		this.setPriority(Job.BUILD);
64
		this.scheduleDelay = -1;
72
		this.scheduleDelay = -1;
73
74
		if (repositories == null) {
75
			repositories = TasksUiPlugin.getRepositoryManager().getAllRepositories();
76
		}
77
78
		for (final TaskRepository repository : repositories) {
79
			TasksUiPlugin.testAndSetMemoryOnlyPassword(repository);
80
		}
65
	}
81
	}
66
82
67
	@Override
83
	@Override
68
	public IStatus run(final IProgressMonitor monitor) {
84
	public IStatus run(final IProgressMonitor monitor) {
85
69
		try {
86
		try {
70
			taskList = taskListManager.getTaskList();
87
			taskList = taskListManager.getTaskList();
71
			if (repositories == null) {
88
			if (repositories == null) {
Lines 83-88 Link Here
83
					continue;
100
					continue;
84
				}
101
				}
85
102
103
				
86
				final AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
104
				final AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
87
						.getRepositoryConnector(repository.getConnectorKind());
105
						.getRepositoryConnector(repository.getConnectorKind());
88
				if (connector == null) {
106
				if (connector == null) {
(-)src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java (-2 / +41 lines)
Lines 188-193 Link Here
188
188
189
	private Hyperlink manageAccountHyperlink;
189
	private Hyperlink manageAccountHyperlink;
190
190
191
	protected Button memoryonlyPasswordButton;
192
	
193
	
191
	public AbstractRepositorySettingsPage(String title, String description, AbstractRepositoryConnectorUi repositoryUi) {
194
	public AbstractRepositorySettingsPage(String title, String description, AbstractRepositoryConnectorUi repositoryUi) {
192
		super(title);
195
		super(title);
193
		super.setTitle(title);
196
		super.setTitle(title);
Lines 318-323 Link Here
318
			});
321
			});
319
		}
322
		}
320
323
324
		memoryonlyPasswordButton = new Button(compositeContainer, SWT.CHECK);
325
		GridDataFactory.fillDefaults().span(2, SWT.DEFAULT).applyTo(memoryonlyPasswordButton);
326
327
		memoryonlyPasswordButton.setText("Memoryonly Password");
328
		memoryonlyPasswordButton.addSelectionListener(new SelectionAdapter() {
329
			@Override
330
			public void widgetSelected(SelectionEvent e) {
331
				setMemoryOnly(memoryonlyPasswordButton.getSelection());
332
				isPageComplete();
333
			}
334
		});
335
321
		repositoryUserNameEditor = new StringFieldEditor("", LABEL_USER, StringFieldEditor.UNLIMITED,
336
		repositoryUserNameEditor = new StringFieldEditor("", LABEL_USER, StringFieldEditor.UNLIMITED,
322
				compositeContainer) {
337
				compositeContainer) {
323
338
Lines 377-382 Link Here
377
				setAnonymous(true);
392
				setAnonymous(true);
378
			}
393
			}
379
		}
394
		}
395
		
396
		memoryonlyPasswordButton.setSelection(repository.isMemoryOnlyPassword());
380
397
381
		// TODO: put this back if we can't get the info from all connectors
398
		// TODO: put this back if we can't get the info from all connectors
382
		// if (needsTimeZone()) {
399
		// if (needsTimeZone()) {
Lines 832-837 Link Here
832
		}
849
		}
833
	}
850
	}
834
851
852
	public void setMemoryOnly(boolean selected) {
853
854
		memoryonlyPasswordButton.setSelection(selected);
855
856
		if (selected) {
857
			oldPassword = (repositoryPasswordEditor).getStringValue();
858
			repositoryPasswordEditor.setStringValue("");
859
		} else {
860
			repositoryPasswordEditor.setStringValue(oldPassword);
861
		}
862
863
		repositoryPasswordEditor.setEnabled(!selected, compositeContainer);
864
		if (getWizard() != null) {
865
			getWizard().getContainer().updateButtons();
866
		}
867
	}
868
835
	public void setHttpAuth(boolean selected) {
869
	public void setHttpAuth(boolean selected) {
836
		if (!needsHttpAuth) {
870
		if (!needsHttpAuth) {
837
			return;
871
			return;
Lines 1042-1050 Link Here
1042
1076
1043
	private String credentialsComplete() {
1077
	private String credentialsComplete() {
1044
		if ((needsAnonymousLogin() && !anonymousButton.getSelection())
1078
		if ((needsAnonymousLogin() && !anonymousButton.getSelection())
1045
				&& (repositoryUserNameEditor.getStringValue().trim().equals("") || repositoryPasswordEditor.getStringValue()
1079
				&& (repositoryUserNameEditor.getStringValue().trim().equals("") || (repositoryPasswordEditor.getStringValue()
1046
						.trim()
1080
						.trim()
1047
						.equals(""))) {
1081
						.equals("")) ) && !memoryonlyPasswordButton.getSelection()) {
1048
			return "Repository user name and password must not be blank";
1082
			return "Repository user name and password must not be blank";
1049
		}
1083
		}
1050
		return null;
1084
		return null;
Lines 1122-1127 Link Here
1122
		if (needsAnonymousLogin()) {
1156
		if (needsAnonymousLogin()) {
1123
			repository.setAnonymous(anonymousButton.getSelection());
1157
			repository.setAnonymous(anonymousButton.getSelection());
1124
		}
1158
		}
1159
		repository.setMemoryOnlyPassword(memoryonlyPasswordButton.getSelection());
1125
		// repository.setProperty(TaskRepository.AUTH_HTTP_USERNAME,
1160
		// repository.setProperty(TaskRepository.AUTH_HTTP_USERNAME,
1126
		// getHttpAuthUserId());
1161
		// getHttpAuthUserId());
1127
		// repository.setProperty(TaskRepository.AUTH_HTTP_PASSWORD,
1162
		// repository.setProperty(TaskRepository.AUTH_HTTP_PASSWORD,
Lines 1314-1317 Link Here
1314
1349
1315
	}
1350
	}
1316
1351
1352
	public Boolean getMemoryonlyPassword() {
1353
			return memoryonlyPasswordButton.getSelection();
1354
	}
1355
1317
}
1356
}
(-)src/org/eclipse/mylyn/internal/tasks/ui/EnterMemoryPassordDialog.java (+174 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.tasks.ui;
10
11
import java.util.ArrayList;
12
import java.util.List;
13
14
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.mylyn.tasks.core.TaskRepository;
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.VerifyEvent;
18
import org.eclipse.swt.events.VerifyListener;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Control;
24
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.swt.widgets.Label;
26
import org.eclipse.swt.widgets.Listener;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.swt.widgets.Text;
29
30
/**
31
 * This Dialog is used to enter a memory only Password for TaskRepositories.
32
 * 
33
 * @author Frank Becker
34
 * @since 2.1
35
 */
36
37
public class EnterMemoryPassordDialog extends Dialog {
38
39
	TaskRepository repository;
40
41
	Text passwordText;
42
43
	String password = "";
44
45
	boolean inUpdate = false;
46
47
	List<Integer> numXs = new ArrayList<Integer>();;
48
49
	public EnterMemoryPassordDialog(Shell parentShell, TaskRepository repository) {
50
		super(parentShell);
51
		this.repository = repository;
52
	}
53
54
	protected void configureShell(Shell newShell) {
55
		super.configureShell(newShell);
56
		newShell.setText("EnterMemoryPassordDialog Titel");
57
	}
58
59
	public String getPassword() {
60
		return password;
61
	}
62
63
	@Override
64
	protected Control createContents(Composite parent) {
65
		Composite main = new Composite(parent, SWT.NONE);
66
		GridLayout layout = new GridLayout();
67
		layout.numColumns = 3;
68
		main.setLayout(layout);
69
		main.setLayoutData(new GridData(GridData.FILL_BOTH));
70
		Label l = new Label(main, SWT.NULL);
71
		l.setText("Please enter the Password for repository");
72
73
		GridData gd = new GridData();
74
		gd.horizontalSpan = 3;
75
		l.setLayoutData(gd);
76
77
		l = new Label(main, SWT.NULL);
78
79
		l.setText(repository.getRepositoryLabel());
80
		gd = new GridData();
81
		gd.horizontalSpan = 3;
82
		l.setLayoutData(gd);
83
84
		passwordText = new Text(main, SWT.SINGLE | SWT.BORDER);
85
		GridData data = new GridData();
86
		data.widthHint = 250;
87
		data.horizontalSpan = 3;
88
		passwordText.setLayoutData(data);
89
90
		passwordText.addVerifyListener(new VerifyListener() {
91
			public void verifyText(VerifyEvent e) {
92
				if (inUpdate)
93
					return;
94
				e.doit = false;
95
				inUpdate = true;
96
				switch (e.character) {
97
				case 8: {
98
					// backspace pressed
99
					if (password.length() > 0) {
100
						password = password.substring(0, password.length() - 1);
101
					}
102
					// get rid of bogus Xs
103
					int numX = numXs.get(numXs.size() - 1).intValue();
104
					numXs.remove(numXs.size() - 1);
105
					String oldText = passwordText.getText();
106
					String newText = oldText.substring(0, oldText.length() - numX);
107
					passwordText.setText(newText);
108
					passwordText.setSelection(newText.length());
109
					break;
110
				}
111
				default: {
112
					String oldText = passwordText.getText();
113
					String x = getXs();
114
					numXs.add(numXs.size(), new Integer(x.length()));
115
					String newText = oldText + x;
116
					passwordText.setText(newText);
117
					passwordText.setSelection(newText.length());
118
					password += e.character;
119
				}
120
				}
121
				inUpdate = false;
122
			}
123
		});
124
125
		Composite buttonComposite = new Composite(main, SWT.NONE);
126
127
		layout = new GridLayout();
128
		layout.numColumns = 2;
129
		buttonComposite.setLayout(layout);
130
		main.setLayoutData(new GridData(GridData.FILL_BOTH));
131
132
		Button b = new Button(buttonComposite, SWT.PUSH);
133
		b.setText("QK");
134
		data = new GridData();
135
		data.widthHint = 70;
136
		b.setLayoutData(data);
137
		b.addListener(SWT.Selection, new Listener() {
138
			public void handleEvent(Event event) {
139
				okPressed();
140
			}
141
		});
142
		buttonComposite.getShell().setDefaultButton(b);
143
		b = new Button(buttonComposite, SWT.PUSH);
144
		b.setText("Cancel");
145
		data = new GridData();
146
		data.widthHint = 70;
147
		b.setLayoutData(data);
148
		b.addListener(SWT.Selection, new Listener() {
149
			public void handleEvent(Event event) {
150
				cancelPressed();
151
			}
152
		});
153
		Dialog.applyDialogFont(parent);
154
		return main;
155
	}
156
157
	String getXs() {
158
		double random = Math.random();
159
		random *= 2;
160
		random += 2;
161
		long num = Math.round(random);
162
		// Random number between 2 and 4
163
		switch ((int) num) {
164
		case 2:
165
			return "**"; //$NON-NLS-1$
166
		case 3:
167
			return "***"; //$NON-NLS-1$
168
		case 4:
169
			return "****"; //$NON-NLS-1$
170
		}
171
		return "*"; //$NON-NLS-1$
172
	}
173
174
}
(-)src/org/eclipse/mylyn/tasks/core/TaskRepository.java (+45 lines)
Lines 73-78 Link Here
73
73
74
	public static final String OFFLINE = "org.eclipse.mylyn.tasklist.repositories.offline";
74
	public static final String OFFLINE = "org.eclipse.mylyn.tasklist.repositories.offline";
75
75
76
	public static final String MEMORYONLY_PASSWORD = "org.eclipse.mylyn.tasklist.repositories.memoryonly.password";
77
76
	// HACK: Lock used to work around race condition in
78
	// HACK: Lock used to work around race condition in
77
	// Platform.add/get/flushAuthorizationInfo()
79
	// Platform.add/get/flushAuthorizationInfo()
78
	private static final Object LOCK = new Object();
80
	private static final Object LOCK = new Object();
Lines 83-88 Link Here
83
	private boolean isCachedUserName;
85
	private boolean isCachedUserName;
84
86
85
	private String cachedUserName;
87
	private String cachedUserName;
88
	
89
	private boolean isCachedUserPassword;
90
91
	private String cachedUserPassword;
86
92
87
	static {
93
	static {
88
		URL url = null;
94
		URL url = null;
Lines 169-174 Link Here
169
	}
175
	}
170
176
171
	public String getPassword() {
177
	public String getPassword() {
178
		if (!isCachedUserPassword) {
179
			if (isMemoryOnlyPassword()) {
180
				StatusHandler.log("Memoryonly Password not set for repository "+ this.getRepositoryLabel(), this);
181
				cachedUserPassword = "";
182
			} else {
183
				cachedUserPassword = getUserPasswordFromKeyRing();
184
				isCachedUserPassword = true;
185
			}
186
		}
187
		return cachedUserPassword;
188
	}
189
190
	private String getUserPasswordFromKeyRing() {
172
		return getAuthInfo(AUTH_PASSWORD);
191
		return getAuthInfo(AUTH_PASSWORD);
173
	}
192
	}
174
193
Lines 192-197 Link Here
192
		setCredentials(username, password, AUTH_USERNAME, AUTH_PASSWORD);
211
		setCredentials(username, password, AUTH_USERNAME, AUTH_PASSWORD);
193
		cachedUserName = username;
212
		cachedUserName = username;
194
		isCachedUserName = true;
213
		isCachedUserName = true;
214
		cachedUserPassword = password;
215
		isCachedUserPassword = true;
195
	}
216
	}
196
217
197
	public void setProxyAuthenticationCredentials(String username, String password) {
218
	public void setProxyAuthenticationCredentials(String username, String password) {
Lines 231-236 Link Here
231
					headlessCreds.clear();
252
					headlessCreds.clear();
232
				}
253
				}
233
				isCachedUserName = false;
254
				isCachedUserName = false;
255
				isCachedUserPassword = false;
234
			} catch (CoreException e) {
256
			} catch (CoreException e) {
235
				StatusHandler.fail(e, "could not flush authorization credentials", true);
257
				StatusHandler.fail(e, "could not flush authorization credentials", true);
236
			}
258
			}
Lines 467-470 Link Here
467
		return getProperty(OFFLINE) != null && "true".equals(getProperty(OFFLINE));
489
		return getProperty(OFFLINE) != null && "true".equals(getProperty(OFFLINE));
468
	}
490
	}
469
491
492
	public void setCachedPassword(String cachedUserPassword) {
493
		this.cachedUserPassword = cachedUserPassword;
494
		isCachedUserPassword = true;
495
	}
496
497
	public String getCachedPassword() {
498
		if (isCachedUserPassword)
499
			return cachedUserPassword;
500
		else
501
			return "";
502
	}
503
504
	public void setMemoryOnlyPassword(boolean b) {
505
		properties.put(MEMORYONLY_PASSWORD, String.valueOf(b));
506
//		if (b)
507
//			setAuthenticationCredentials(getUserName(), "");
508
	}
509
510
	public boolean isMemoryOnlyPassword() {
511
		return /*getProperty(MEMORYONLY_PASSWORD) == null ||*/ "true".equals(getProperty(MEMORYONLY_PASSWORD));
512
	}
513
514
470
}
515
}

Return to bug 200634