Revision 47824
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/types/httpbasic/DownloaderHTTPBasicCredentials.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.downloader.lib.impl.types.httpbasic; |
7 | 7 |
|
8 |
import java.nio.charset.StandardCharsets; |
|
9 |
import java.util.Base64; |
|
8 | 10 |
import static org.gvsig.downloader.lib.impl.types.httpbasic.DownloaderHTTPBasicAuthenticationFactory.HTTPBASIC_AUTHENTICATION_NAME; |
9 | 11 |
import org.gvsig.downloader.spi.AbstractDownloaderCredentials; |
10 | 12 |
|
... | ... | |
28 | 30 |
|
29 | 31 |
@Override |
30 | 32 |
public String getAuthorizationToken() { |
31 |
return "Basic XXXX"; // TODO: Encode user and password
|
|
33 |
return "Basic "+Base64.getEncoder().encodeToString((this.userid+":"+this.password).getBytes(StandardCharsets.UTF_8));
|
|
32 | 34 |
} |
33 | 35 |
|
34 | 36 |
@Override |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/types/httpbasic/DownloaderHTTPBasicAuthenticationRequester.java | ||
---|---|---|
23 | 23 |
package org.gvsig.downloader.lib.impl.types.httpbasic; |
24 | 24 |
|
25 | 25 |
import java.awt.event.ActionEvent; |
26 |
import java.util.concurrent.Executor; |
|
26 | 27 |
import javax.swing.SwingUtilities; |
27 | 28 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
28 | 29 |
import org.gvsig.downloader.DownloaderAuthenticationRequester; |
... | ... | |
46 | 47 |
} |
47 | 48 |
|
48 | 49 |
@Override |
49 |
public boolean requestAuthorization() { |
|
50 |
public boolean requestAuthorization(Executor executorUI) {
|
|
50 | 51 |
if( !SwingUtilities.isEventDispatchThread() ) { |
51 | 52 |
try { |
52 | 53 |
MutableBoolean r = new MutableBoolean(); |
53 |
SwingUtilities.invokeAndWait(() -> { |
|
54 |
r.setValue(requestAuthorization()); |
|
54 |
// SwingUtilities.invokeAndWait(() -> { |
|
55 |
executorUI.execute(() -> { |
|
56 |
r.setValue(requestAuthorization(executorUI)); |
|
55 | 57 |
}); |
56 | 58 |
return r.booleanValue(); |
57 | 59 |
} catch (Exception ex) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/DownloaderManagerImpl.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.downloader.lib.impl; |
25 | 25 |
|
26 |
import java.io.File; |
|
26 | 27 |
import java.net.URL; |
27 | 28 |
import java.util.Collection; |
28 | 29 |
import java.util.HashMap; |
... | ... | |
56 | 57 |
this.authenticationConfigurationServices = new HashMap<>(); |
57 | 58 |
} |
58 | 59 |
|
59 |
// protected Runnable createDownloaderTask(Downloader downloader, URL url, String data, File target, Object groupID, int maxbytes) { |
|
60 |
// SEAuthDownloaderTask t = new SEAuthDownloaderTask(downloader, url, data, target, groupID); |
|
61 |
// t.setMaxbytes(maxbytes); |
|
62 |
// return t; |
|
63 |
// } |
|
60 |
@Override |
|
61 |
protected Runnable createDownloaderTask(SEDownloader downloader, URL url, String data, File target, Object groupID, int maxbytes) { |
|
62 |
SEAuthDownloaderTask t = new SEAuthDownloaderTask( |
|
63 |
downloader, |
|
64 |
url, |
|
65 |
data, |
|
66 |
target, |
|
67 |
groupID); |
|
68 |
t.setMaxbytes(maxbytes); |
|
69 |
return t; |
|
70 |
} |
|
64 | 71 |
|
65 | 72 |
@Override |
66 | 73 |
public void addOrReplaceCredentials(DownloaderCredentials credentials) { |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/SEAuthDownloaderTask.java | ||
---|---|---|
7 | 7 |
import java.net.HttpURLConnection; |
8 | 8 |
import java.net.URL; |
9 | 9 |
import java.util.Objects; |
10 |
import java.util.concurrent.Executor; |
|
10 | 11 |
import org.apache.commons.io.IOUtils; |
11 | 12 |
import org.apache.commons.lang3.StringUtils; |
12 | 13 |
import org.apache.http.Header; |
... | ... | |
26 | 27 |
import org.apache.http.entity.StringEntity; |
27 | 28 |
import org.apache.http.impl.client.CloseableHttpClient; |
28 | 29 |
import org.apache.http.impl.client.HttpClientBuilder; |
29 |
import org.gvsig.compat.se.net.downloader.Downloader; |
|
30 | 30 |
import org.gvsig.compat.se.net.downloader.se.AbstractSEDownloaderTask; |
31 |
import org.gvsig.compat.se.net.downloader.se.SEDownloader; |
|
31 | 32 |
import org.gvsig.downloader.DownloaderAuthenticationConfig; |
32 | 33 |
import org.gvsig.downloader.DownloaderAuthenticationRequester; |
33 | 34 |
import org.gvsig.downloader.DownloaderCredentials; |
34 |
import org.gvsig.downloader.DownloaderManager; |
|
35 | 35 |
|
36 | 36 |
@SuppressWarnings("UseSpecificCatch") |
37 | 37 |
final class SEAuthDownloaderTask |
... | ... | |
78 | 78 |
private static final String METHOD_GET = "GET"; |
79 | 79 |
private static final String METHOD_DELETE = "DELETE"; |
80 | 80 |
|
81 |
public SEAuthDownloaderTask(Downloader downloader, URL url, String data, File dstFile, Object groupID) { |
|
81 |
public SEAuthDownloaderTask(SEDownloader downloader, URL url, String data, File dstFile, Object groupID) {
|
|
82 | 82 |
super(downloader, url, data, dstFile, groupID); |
83 | 83 |
} |
84 | 84 |
|
... | ... | |
113 | 113 |
throw new AuthenticationException("Can't configure service authentication for url '"+this.url+"'."); |
114 | 114 |
} |
115 | 115 |
LOGGER.info("AUTHORIZATION REQUESTER TYPE: "+authorizationRequester.getProviderName()); |
116 |
if( !authorizationRequester.requestAuthorization() ) { |
|
116 |
if( !authorizationRequester.requestAuthorization(this.getExecutorUI()) ) {
|
|
117 | 117 |
return; |
118 | 118 |
} |
119 | 119 |
DownloaderCredentials credentials = authorizationRequester.getCredentials(); |
... | ... | |
133 | 133 |
if( config!=null ) { |
134 | 134 |
DownloaderAuthenticationRequester authorizationRequester = config.create(); |
135 | 135 |
if( authorizationRequester!=null ) { |
136 |
if( authorizationRequester.requestAuthorization() ) { |
|
136 |
if( authorizationRequester.requestAuthorization(this.getExecutorUI()) ) {
|
|
137 | 137 |
credentials = authorizationRequester.getCredentials(); |
138 | 138 |
addOrReplaceCredentials(credentials); |
139 | 139 |
request.addHeader("Authorization", credentials.getAuthorizationToken()); |
... | ... | |
332 | 332 |
} |
333 | 333 |
} |
334 | 334 |
|
335 |
private Executor getExecutorUI() { |
|
336 |
return this.downloader.getExecutorUI(); |
|
337 |
} |
|
335 | 338 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.api/src/main/java/org/gvsig/downloader/DownloaderAuthenticationRequester.java | ||
---|---|---|
1 | 1 |
package org.gvsig.downloader; |
2 | 2 |
|
3 |
import java.util.concurrent.Executor; |
|
4 |
|
|
3 | 5 |
/** |
4 | 6 |
* |
5 | 7 |
* @author jjdelcerro |
... | ... | |
10 | 12 |
|
11 | 13 |
public String getProviderName(); |
12 | 14 |
|
13 |
public boolean requestAuthorization(); |
|
15 |
public boolean requestAuthorization(Executor executorUI);
|
|
14 | 16 |
|
15 | 17 |
public DownloaderCredentials getCredentials(); |
16 | 18 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.swing/org.gvsig.downloader.swing.impl/src/main/java/org/gvsig/downloader/swing/impl/config/DownloaderConfigServicePanel.java | ||
---|---|---|
8 | 8 |
import java.awt.event.ActionEvent; |
9 | 9 |
import java.awt.event.KeyAdapter; |
10 | 10 |
import java.awt.event.KeyEvent; |
11 |
import java.util.concurrent.Executor; |
|
11 | 12 |
import javax.swing.DefaultComboBoxModel; |
12 | 13 |
import javax.swing.ImageIcon; |
13 | 14 |
import javax.swing.JOptionPane; |
... | ... | |
176 | 177 |
} |
177 | 178 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
178 | 179 |
DownloaderAuthenticationRequester requester = this.config.create(); |
179 |
if( !requester.requestAuthorization() ) { |
|
180 |
if( !requester.requestAuthorization((Runnable command) -> {command.run();}) ) {
|
|
180 | 181 |
dialogs.messageDialog( |
181 | 182 |
"Authentication test failed", |
182 | 183 |
"Authentication test", |
Also available in: Unified diff