1 | 0 | |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
package org.eclipse.swtbot.swt.finder.widgets; |
13 | |
|
14 | |
import org.eclipse.swt.browser.AuthenticationEvent; |
15 | |
import org.eclipse.swt.browser.AuthenticationListener; |
16 | |
import org.eclipse.swt.browser.Browser; |
17 | |
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; |
18 | |
import org.eclipse.swtbot.swt.finder.results.VoidResult; |
19 | |
import org.eclipse.swtbot.swt.finder.utils.Credentials; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | final class BrowserAuthenticationListener implements AuthenticationListener { |
27 | |
|
28 | |
private Credentials credentials; |
29 | |
|
30 | |
public void init(final Browser widget) { |
31 | 0 | UIThreadRunnable.syncExec(new VoidResult() { |
32 | |
public void run() { |
33 | 0 | widget.addAuthenticationListener(BrowserAuthenticationListener.this); |
34 | 0 | } |
35 | |
}); |
36 | 0 | } |
37 | |
|
38 | |
public void setCredentials(Credentials credentials) { |
39 | 0 | this.credentials = credentials; |
40 | 0 | } |
41 | |
|
42 | |
public Credentials getCredentials() { |
43 | 0 | return this.credentials; |
44 | |
} |
45 | |
|
46 | |
public void authenticate(AuthenticationEvent event) { |
47 | 0 | if (credentials == null) { |
48 | 0 | event.doit = false; |
49 | 0 | return; |
50 | |
} |
51 | 0 | event.doit = true; |
52 | 0 | event.user = credentials.username(); |
53 | 0 | event.password = credentials.password(); |
54 | 0 | } |
55 | |
|
56 | |
} |