Revision 47845
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/DownloaderAuthenticationConfig.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
public boolean isConfigurable(); |
32 | 32 |
|
33 |
public boolean isFilled(); |
|
34 |
|
|
33 | 35 |
public boolean requestAuthenticationConfig(); |
34 | 36 |
|
35 |
public DownloaderCredentials getCredentials(DownloaderCredentials credentials);
|
|
37 |
public DownloaderAuthenticationConfig createAuthenticationConfig(String serviceUrl);
|
|
36 | 38 |
} |
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/DownloaderManager.java | ||
---|---|---|
27 | 27 |
import java.net.MalformedURLException; |
28 | 28 |
import java.net.URL; |
29 | 29 |
import java.util.Collection; |
30 |
import java.util.List; |
|
30 | 31 |
import org.apache.commons.lang3.StringUtils; |
31 | 32 |
import org.gvsig.compat.net.Downloader; |
32 | 33 |
|
... | ... | |
118 | 119 |
|
119 | 120 |
public String getAuthenticationConfigurationServiceAsString(String url); |
120 | 121 |
|
122 |
public void propagateCredentials(String sourceServiceUrl, Collection<String> targetServicesUrls); |
|
123 |
|
|
121 | 124 |
} |
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/spi/AbstractDownloaderAuthenticationConfig.java | ||
---|---|---|
78 | 78 |
public boolean isConfigurable() { |
79 | 79 |
return false; |
80 | 80 |
} |
81 |
|
|
82 |
@Override |
|
83 |
public boolean isFilled() { |
|
84 |
return true; |
|
85 |
} |
|
81 | 86 |
|
87 |
|
|
82 | 88 |
@Override |
83 | 89 |
public boolean requestAuthenticationConfig() { |
84 | 90 |
return true; |
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/DownloaderCredentials.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
public boolean isAuthorizationTokenExpired(); |
23 | 23 |
|
24 |
public DownloaderCredentials createCredentials(String serviceUrl); |
|
25 |
|
|
26 |
public DownloaderCredentials createCredentials(DownloaderAuthenticationConfig config); |
|
27 |
|
|
24 | 28 |
} |
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 | ||
---|---|---|
34 | 34 |
import java.util.Iterator; |
35 | 35 |
import java.util.List; |
36 | 36 |
import java.util.Map; |
37 |
import java.util.Objects; |
|
37 | 38 |
import org.apache.commons.lang3.StringUtils; |
38 | 39 |
import org.apache.http.entity.ContentType; |
39 | 40 |
import org.gvsig.compat.net.ICancellable; |
... | ... | |
145 | 146 |
|
146 | 147 |
@Override |
147 | 148 |
public DownloaderCredentials getCredentials(String url) { |
149 |
if (StringUtils.isBlank(url)) { |
|
150 |
return null; |
|
151 |
} |
|
152 |
|
|
148 | 153 |
for (DownloaderCredentials theCredentials : this.credentials) { |
149 | 154 |
if(urlStartsWith(url, theCredentials.getServiceUrl())){ |
150 | 155 |
return theCredentials; |
... | ... | |
155 | 160 |
return null; |
156 | 161 |
} |
157 | 162 |
for (DownloaderCredentials theCredentials : this.credentials) { |
158 |
DownloaderCredentials x = config.getCredentials(theCredentials);
|
|
163 |
DownloaderCredentials x = theCredentials.createCredentials(config);
|
|
159 | 164 |
if(x != null) { |
160 | 165 |
this.addOrReplaceCredentials(x); |
161 | 166 |
return x; |
... | ... | |
203 | 208 |
|
204 | 209 |
@Override |
205 | 210 |
public DownloaderAuthenticationConfig getAuthenticationConfigurationService(String baseUrl) { |
211 |
if (StringUtils.isBlank(baseUrl)) { |
|
212 |
return null; |
|
213 |
} |
|
214 |
|
|
206 | 215 |
for (DownloaderAuthenticationConfig theConfig : this.authenticationConfigurationServices) { |
207 |
if(urlStartsWith(baseUrl, theConfig.getServiceUrl())){
|
|
216 |
if (urlStartsWith(baseUrl, theConfig.getServiceUrl())) {
|
|
208 | 217 |
return theConfig; |
209 | 218 |
} |
210 | 219 |
} |
... | ... | |
256 | 265 |
|
257 | 266 |
@Override |
258 | 267 |
public synchronized File downloadFile(URL url, String method, ContentType contenttype, String data, String name, ICancellable cancel, int maxbytes) throws IOException, ConnectException, UnknownHostException { |
259 |
// File target = getPreviousDownloadedURL(url, data); |
|
260 |
// if(target != null){ |
|
261 |
// return target; |
|
262 |
// } |
|
268 |
return downloadFile(url, method, contenttype, data, name, cancel, maxbytes, true); |
|
269 |
} |
|
270 |
|
|
271 |
@Override |
|
272 |
public synchronized File downloadFile(URL url, String method, ContentType contenttype, String data, String name, ICancellable cancel, int maxbytes, boolean useCache) throws IOException, ConnectException, UnknownHostException { |
|
273 |
LOG.info("Download file " + Objects.toString(url)); |
|
274 |
if (useCache) { |
|
275 |
File target = getPreviousDownloadedURL(url, data); |
|
276 |
if (target != null) { |
|
277 |
LOG.info("CACHED "+url.toString() + " at '" + target.getAbsolutePath() + "'"); |
|
278 |
return target; |
|
279 |
} |
|
280 |
} |
|
263 | 281 |
File target = new File(name); |
264 | 282 |
if (!target.isAbsolute()){ |
265 | 283 |
target = getUniqueTemporaryFile(name); |
... | ... | |
269 | 287 |
} |
270 | 288 |
Runnable task = this.createDownloaderTask(this, url, method, contenttype, data, target, cancel.getID(), maxbytes); |
271 | 289 |
task.run(); |
272 |
|
|
273 | 290 |
return target; |
274 | 291 |
} |
275 | 292 |
|
293 |
public void propagateCredentials(String sourceServiceUrl, Collection<String> targetServicesUrls) { |
|
294 |
if(StringUtils.isBlank(sourceServiceUrl)){ |
|
295 |
return; |
|
296 |
} |
|
297 |
DownloaderAuthenticationConfig sourceConfig = this.getAuthenticationConfigurationService(sourceServiceUrl); |
|
298 |
if(sourceConfig == null){ |
|
299 |
return; |
|
300 |
} |
|
301 |
DownloaderCredentials sourceCredentials = this.getCredentials(sourceServiceUrl); |
|
302 |
for (String targetServiceUrl : targetServicesUrls) { |
|
303 |
if(StringUtils.isBlank(targetServiceUrl)){ |
|
304 |
continue; |
|
305 |
} |
|
306 |
DownloaderAuthenticationConfig targetConfig = this.getAuthenticationConfigurationService(targetServiceUrl); |
|
307 |
if(targetConfig == null) { |
|
308 |
targetConfig = sourceConfig.createAuthenticationConfig(targetServiceUrl); |
|
309 |
if(targetConfig != null) { |
|
310 |
this.registerAuthenticationConfigurationService(targetConfig); |
|
311 |
} |
|
312 |
} |
|
313 |
if(sourceCredentials != null) { |
|
314 |
DownloaderCredentials targetCredentials = this.getCredentials(targetServiceUrl); |
|
315 |
if(targetCredentials == null){ |
|
316 |
targetCredentials = sourceCredentials.createCredentials(targetServiceUrl); |
|
317 |
if(targetCredentials != null) { |
|
318 |
this.addOrReplaceCredentials(targetCredentials); |
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
322 |
} |
|
323 |
|
|
324 |
|
|
325 |
} |
|
326 |
|
|
276 | 327 |
|
277 | 328 |
} |
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 | ||
---|---|---|
4 | 4 |
import java.io.IOException; |
5 | 5 |
import java.io.InputStream; |
6 | 6 |
import java.net.SocketTimeoutException; |
7 |
import java.net.URI; |
|
8 |
import java.net.URISyntaxException; |
|
7 | 9 |
import java.net.URL; |
8 | 10 |
import java.util.Objects; |
9 | 11 |
import java.util.concurrent.Executor; |
... | ... | |
35 | 37 |
import org.gvsig.downloader.DownloaderCredentials; |
36 | 38 |
import org.gvsig.downloader.DownloaderManager; |
37 | 39 |
import org.gvsig.downloader.IOExceptionWithStatus; |
40 |
import org.slf4j.Logger; |
|
41 |
import org.slf4j.LoggerFactory; |
|
38 | 42 |
|
39 | 43 |
@SuppressWarnings("UseSpecificCatch") |
40 | 44 |
final class SEAuthDownloaderTask |
41 | 45 |
extends AbstractSEDownloaderTask |
42 |
implements Runnable { |
|
46 |
implements Runnable |
|
47 |
{ |
|
43 | 48 |
|
49 |
private static Logger LOGGER = LoggerFactory.getLogger(SEAuthDownloaderTask.class); |
|
50 |
|
|
44 | 51 |
private class DownloaderResponseHandler implements ResponseHandler<Object> { |
45 | 52 |
|
46 | 53 |
private int status; |
... | ... | |
194 | 201 |
return responseHandler; |
195 | 202 |
} |
196 | 203 |
|
197 |
// public File send(String method) throws IOException { |
|
198 |
// int status = 500; |
|
199 |
// URL theUrl = url; |
|
200 |
// try { |
|
201 |
// int numretries = 3; |
|
202 |
// for (int retries = 0; retries < numretries; retries++) { |
|
203 |
// HttpRequestBase request; |
|
204 |
// switch (method.toUpperCase()) { |
|
205 |
// case METHOD_DELETE: |
|
206 |
// request = new HttpDelete(theUrl.toURI()); |
|
207 |
// break; |
|
208 |
// case METHOD_GET: |
|
209 |
// default: |
|
210 |
// request = new HttpGet(theUrl.toURI()); |
|
211 |
// break; |
|
212 |
// } |
|
213 |
//// request.setHeader("User-Agent","Mozilla/5.0 (gvSIG) like Gecko"); |
|
214 |
// request.setHeader("User-Agent","gvSIG-desktop"); |
|
215 |
// request.setHeader("Referer","http://www.gvsig.com"); |
|
216 |
// |
|
217 |
// LOGGER.info("RETRY "+retries); |
|
218 |
// DownloaderResponseHandler responseHandler = executeRequest(request); |
|
219 |
// status = responseHandler.getStatus(); |
|
220 |
// if(status >= 200 && status < 300) { |
|
221 |
// //2xx success |
|
222 |
// return this.dstFile; |
|
223 |
// |
|
224 |
// } else if(status == 307 || status == 308) { |
|
225 |
// String redirection = responseHandler.getRedirectionLocation(); |
|
226 |
// if(StringUtils.isBlank(redirection)) { |
|
227 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status+" redirect to blank URL."); |
|
228 |
// } |
|
229 |
// try { |
|
230 |
// theUrl = new URL(redirection); |
|
231 |
// } catch (Exception ex) { |
|
232 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status+" redirect to invalid URL "+redirection); |
|
233 |
// } |
|
234 |
// } else if(status >= 300 && status < 400) { |
|
235 |
// // 3xx redirection |
|
236 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status); |
|
237 |
// } else if(status == 401 || status == 403) { |
|
238 |
// // "401 Unauthorized" indicates that the request lacks valid authentication credentials |
|
239 |
// // "403 Forbidden" the client doesn't have permission to access the requested resource |
|
240 |
// // https://www.permit.io/blog/401-vs-403-error-whats-the-difference |
|
241 |
// if( retries < numretries-1 ) { |
|
242 |
// authorize(theUrl); |
|
243 |
// } |
|
244 |
// } else if(status >= 400 && status < 500) { |
|
245 |
// // 4xx client errors |
|
246 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status); |
|
247 |
// } else if(status >= 500 && status < 600) { |
|
248 |
// // 5xx server errors |
|
249 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status); |
|
250 |
// } else { |
|
251 |
// //Unknown |
|
252 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' HTTPStatus = "+status); |
|
253 |
// } |
|
254 |
// } |
|
255 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' too many retries, last status " + status); |
|
256 |
// |
|
257 |
// } catch (IOExceptionWithStatus ex) { |
|
258 |
// throw ex; |
|
259 |
// } catch (Throwable ex) { |
|
260 |
// throw new IOExceptionWithStatus(status, "Can't call method "+method+" "+Objects.toString(theUrl)+"' last status " + status, ex); |
|
261 |
// } |
|
262 |
// } |
|
204 |
private URI urlToUri(URL url) throws URISyntaxException{ |
|
205 |
try { |
|
206 |
URI uri = url.toURI(); |
|
207 |
return uri; |
|
208 |
} catch (URISyntaxException ex) { |
|
209 |
String s = url.toExternalForm(); |
|
210 |
//?apa hasta que se arregle la construcci?n de URL de tiles de WMTS |
|
211 |
// s = StringUtils.replace(s, "{", "%7B"); |
|
212 |
// s = StringUtils.replace(s, "}", "%7D"); |
|
213 |
return new URI(s); |
|
214 |
} |
|
215 |
} |
|
263 | 216 |
|
264 | 217 |
private File send(String method, ContentType contentType, String data) throws IOExceptionWithStatus { |
265 | 218 |
int status = 500; |
266 | 219 |
URL theUrl = url; |
267 | 220 |
try { |
221 |
URI theUri = urlToUri(url); |
|
268 | 222 |
int numretries = 3; |
269 | 223 |
for (int retries = 0; retries < numretries; retries++) { |
270 | 224 |
HttpRequestBase request; |
271 | 225 |
switch (method.toUpperCase()) { |
272 | 226 |
case DownloaderManager.METHOD_DELETE: |
273 |
request = new HttpDelete(theUrl.toURI());
|
|
227 |
request = new HttpDelete(theUri);
|
|
274 | 228 |
break; |
275 | 229 |
case DownloaderManager.METHOD_PUT: |
276 |
request = new HttpPut(theUrl.toURI());
|
|
230 |
request = new HttpPut(theUri);
|
|
277 | 231 |
request.setHeader("Content-type", contentType.toString()); |
278 | 232 |
((HttpPut)request).setEntity(new StringEntity(data, contentType)); |
279 | 233 |
break; |
280 | 234 |
case DownloaderManager.METHOD_POST: |
281 |
request = new HttpPost(theUrl.toURI());
|
|
235 |
request = new HttpPost(theUri);
|
|
282 | 236 |
request.setHeader("SOAPAction", "post"); |
283 | 237 |
request.setHeader("Content-type", contentType.toString()); |
284 | 238 |
((HttpPost)request).setEntity(new StringEntity(data, contentType)); |
285 | 239 |
break; |
286 | 240 |
case DownloaderManager.METHOD_GET: |
287 | 241 |
default: |
288 |
request = new HttpGet(theUrl.toURI());
|
|
242 |
request = new HttpGet(theUri);
|
|
289 | 243 |
break; |
290 | 244 |
} |
291 | 245 |
// request.setHeader("User-Agent","Mozilla/5.0 (gvSIG) like Gecko"); |
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 | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import java.nio.charset.StandardCharsets; |
9 | 9 |
import java.util.Base64; |
10 |
import org.apache.commons.lang3.StringUtils; |
|
11 |
import org.gvsig.downloader.DownloaderAuthenticationConfig; |
|
12 |
import org.gvsig.downloader.DownloaderCredentials; |
|
13 |
import org.gvsig.downloader.DownloaderManager; |
|
10 | 14 |
import static org.gvsig.downloader.lib.impl.types.httpbasic.DownloaderHTTPBasicAuthenticationFactory.HTTPBASIC_AUTHENTICATION_NAME; |
11 | 15 |
import org.gvsig.downloader.spi.AbstractDownloaderCredentials; |
12 | 16 |
|
... | ... | |
41 | 45 |
public String getPassword() { |
42 | 46 |
return password; |
43 | 47 |
} |
48 |
|
|
49 |
@Override |
|
50 |
public DownloaderCredentials createCredentials(String serviceUrl) { |
|
51 |
if (StringUtils.isBlank(serviceUrl)) { |
|
52 |
return null; |
|
53 |
} |
|
54 |
|
|
55 |
return new DownloaderHTTPBasicCredentials( |
|
56 |
serviceUrl, |
|
57 |
this.getUserid(), |
|
58 |
this.getPassword() |
|
59 |
); |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public DownloaderCredentials createCredentials(DownloaderAuthenticationConfig config) { |
|
64 |
if(!(config instanceof DownloaderHTTPBasicAuthenticationConfig)){ |
|
65 |
return null; |
|
66 |
} |
|
67 |
DownloaderHTTPBasicAuthenticationConfig otherConfig = (DownloaderHTTPBasicAuthenticationConfig)config; |
|
68 |
if (DownloaderManager.urlStartsWith(otherConfig.getServiceUrl(), this.getServiceUrl())) { |
|
69 |
return new DownloaderHTTPBasicCredentials( |
|
70 |
otherConfig.getServiceUrl(), |
|
71 |
this.getUserid(), |
|
72 |
this.getPassword() |
|
73 |
); |
|
74 |
} |
|
75 |
return null; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
44 | 79 |
|
45 | 80 |
} |
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/DownloaderHTTPBasicAuthenticationConfig.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.downloader.lib.impl.types.httpbasic; |
7 | 7 |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
8 | 9 |
import org.gvsig.downloader.DownloaderAuthenticationConfig; |
9 | 10 |
import org.gvsig.downloader.DownloaderAuthenticationRequester; |
10 |
import org.gvsig.downloader.DownloaderCredentials; |
|
11 |
import org.gvsig.downloader.DownloaderManager; |
|
12 | 11 |
import static org.gvsig.downloader.lib.impl.types.httpbasic.DownloaderHTTPBasicAuthenticationFactory.HTTPBASIC_AUTHENTICATION_NAME; |
13 | 12 |
import org.gvsig.downloader.spi.AbstractDownloaderAuthenticationConfig; |
14 | 13 |
import org.gvsig.json.JsonObjectBuilder; |
... | ... | |
45 | 44 |
} |
46 | 45 |
|
47 | 46 |
@Override |
48 |
public DownloaderCredentials getCredentials(DownloaderCredentials credentials) { |
|
49 |
if(!(credentials instanceof DownloaderHTTPBasicCredentials)){ |
|
50 |
return null; |
|
51 |
} |
|
52 |
DownloaderHTTPBasicCredentials theCredentials = (DownloaderHTTPBasicCredentials)credentials; |
|
53 |
if (DownloaderManager.urlStartsWith(this.getServiceUrl(), theCredentials.getServiceUrl())) { |
|
54 |
return new DownloaderHTTPBasicCredentials( |
|
55 |
this.getServiceUrl(), |
|
56 |
theCredentials.getUserid(), |
|
57 |
theCredentials.getPassword() |
|
58 |
); |
|
59 |
} |
|
60 |
return null; |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 | 47 |
public JsonObjectBuilder toJsonBuilder() { |
65 | 48 |
JsonObjectBuilder builder = super.toJsonBuilder(); |
66 | 49 |
builder.add_class(this); |
67 | 50 |
return builder; |
68 | 51 |
} |
69 | 52 |
|
53 |
@Override |
|
54 |
public DownloaderAuthenticationConfig createAuthenticationConfig(String serviceUrl) { |
|
55 |
if (StringUtils.isBlank(serviceUrl)) { |
|
56 |
return null; |
|
57 |
} |
|
58 |
|
|
59 |
DownloaderAuthenticationConfig other = new DownloaderHTTPBasicAuthenticationConfig(null, serviceUrl); |
|
60 |
return other; |
|
61 |
} |
|
70 | 62 |
|
71 | 63 |
} |
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/DownloaderConfigServicePanelImpl.java | ||
---|---|---|
12 | 12 |
import javax.swing.ImageIcon; |
13 | 13 |
import javax.swing.JComponent; |
14 | 14 |
import javax.swing.JOptionPane; |
15 |
import javax.swing.SwingUtilities; |
|
15 | 16 |
import javax.swing.event.ChangeListener; |
16 | 17 |
import javax.swing.event.DocumentEvent; |
17 | 18 |
import javax.swing.event.DocumentListener; |
... | ... | |
78 | 79 |
this.cboAuthenticationType.setSelectedIndex(0); |
79 | 80 |
|
80 | 81 |
this.cboAuthenticationType.addActionListener((ActionEvent e) -> { |
81 |
doAuthenticationOrUrlChange(); |
|
82 |
changeListenerHelper.fireEvent(); |
|
82 |
SwingUtilities.invokeLater(() -> { |
|
83 |
doAuthenticationOrUrlChange(); |
|
84 |
changeListenerHelper.fireEvent(); |
|
85 |
}); |
|
83 | 86 |
}); |
84 | 87 |
|
85 | 88 |
this.btnAuthenticationConfig.addActionListener((ActionEvent e) -> { |
... | ... | |
142 | 145 |
this.config = null; |
143 | 146 |
this.txtServiceURL.setText(""); |
144 | 147 |
cboAuthenticationType.setSelectedIndex(0); |
148 |
changeListenerHelper.fireEvent(); |
|
145 | 149 |
} |
146 | 150 |
|
147 | 151 |
@Override |
... | ... | |
150 | 154 |
this.txtServiceURL.setText(this.config.getServiceUrl()); |
151 | 155 |
ListElement.setSelected(cboAuthenticationType, this.config.getFactory()); |
152 | 156 |
this.doUpdateComponents(); |
157 |
changeListenerHelper.fireEvent(); |
|
153 | 158 |
} |
154 | 159 |
|
155 | 160 |
@Override |
... | ... | |
188 | 193 |
return; |
189 | 194 |
} |
190 | 195 |
this.config.requestAuthenticationConfig(); |
196 |
this.changeListenerHelper.fireEvent(); |
|
191 | 197 |
} |
192 | 198 |
|
193 | 199 |
private void doAuthenticationTest() { |
... | ... | |
216 | 222 |
|
217 | 223 |
@Override |
218 | 224 |
public boolean isTheConfigurationValid() { |
219 |
return this.config!=null && !this.isDirty();
|
|
225 |
return !this.isDirty() && this.config!=null && this.config.isFilled();
|
|
220 | 226 |
} |
221 | 227 |
|
222 | 228 |
@Override |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.swing/org.gvsig.downloader.swing.scribejava/src/main/java/org/gvsig/downloader/swing/scribejava/keycloak/DownloaderAuthenticationKeycloakConfig.java | ||
---|---|---|
141 | 141 |
} |
142 | 142 |
|
143 | 143 |
@Override |
144 |
public boolean isFilled() { |
|
145 |
return StringUtils.isNotBlank(this.clientid) && |
|
146 |
StringUtils.isNotBlank(this.scope) && |
|
147 |
this.localPort >= 1024 && |
|
148 |
StringUtils.isNotBlank(this.realm) && |
|
149 |
StringUtils.isNotBlank(this.keycloakBaseurl); |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
144 | 153 |
public boolean requestAuthenticationConfig() { |
145 | 154 |
WindowManager_v2 winmgr = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
146 | 155 |
DownloaderAuthenticationKeycloakConfigPanel panel = new DownloaderAuthenticationKeycloakConfigPanel(); |
... | ... | |
263 | 272 |
} |
264 | 273 |
|
265 | 274 |
@Override |
266 |
public DownloaderCredentials getCredentials(DownloaderCredentials credentials) {
|
|
267 |
if(!(credentials instanceof DownloaderKeycloakCredentials)){
|
|
275 |
public DownloaderAuthenticationConfig createAuthenticationConfig(String serviceUrl) {
|
|
276 |
if (StringUtils.isBlank(serviceUrl)) {
|
|
268 | 277 |
return null; |
269 | 278 |
} |
270 |
DownloaderKeycloakCredentials theCredentials = (DownloaderKeycloakCredentials)credentials; |
|
271 |
DownloaderAuthenticationKeycloakConfig otherConfig = theCredentials.getConfig(); |
|
272 | 279 |
|
273 |
if (!DownloaderManager.areSameURLs(this.getKeycloakBaseurl(), otherConfig.getKeycloakBaseurl())) { |
|
274 |
return null; |
|
275 |
} |
|
276 |
if (!StringUtils.equals(this.getRealm(), otherConfig.getRealm())) { |
|
277 |
return null; |
|
278 |
} |
|
279 |
if (!StringUtils.equals(this.getClientid(), otherConfig.getClientid())) { |
|
280 |
return null; |
|
281 |
} |
|
282 |
if (!StringUtils.equals(this.getScope(), otherConfig.getScope())) { |
|
283 |
return null; |
|
284 |
} |
|
285 |
|
|
286 |
return new DownloaderKeycloakCredentials( |
|
287 |
this, |
|
288 |
theCredentials.getToken(), |
|
289 |
theCredentials.getUserid(), |
|
290 |
theCredentials.getTime() |
|
291 |
); |
|
280 |
DownloaderAuthenticationKeycloakConfig other = new DownloaderAuthenticationKeycloakConfig(null, serviceUrl); |
|
281 |
other.clientid = this.clientid; |
|
282 |
other.keycloakBaseurl = this.keycloakBaseurl; |
|
283 |
other.localPort = this.localPort; |
|
284 |
other.realm = this.realm; |
|
285 |
other.scope = this.scope; |
|
286 |
return other; |
|
292 | 287 |
} |
293 | 288 |
|
294 | 289 |
|
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.swing/org.gvsig.downloader.swing.scribejava/src/main/java/org/gvsig/downloader/swing/scribejava/keycloak/DownloaderKeycloakCredentials.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import com.github.scribejava.core.model.OAuth2AccessToken; |
9 | 9 |
import javax.json.JsonObject; |
10 |
import org.apache.commons.lang3.StringUtils; |
|
10 | 11 |
import org.apache.commons.lang3.builder.ToStringBuilder; |
11 | 12 |
import org.apache.commons.lang3.builder.ToStringStyle; |
12 | 13 |
import org.gvsig.downloader.DownloaderAuthenticationConfig; |
13 | 14 |
import org.gvsig.downloader.DownloaderCredentials; |
15 |
import org.gvsig.downloader.DownloaderLocator; |
|
16 |
import org.gvsig.downloader.DownloaderManager; |
|
14 | 17 |
import org.gvsig.downloader.spi.AbstractDownloaderCredentials; |
15 | 18 |
import org.gvsig.json.Json; |
16 | 19 |
|
... | ... | |
52 | 55 |
return userid; |
53 | 56 |
} |
54 | 57 |
|
58 |
@Override |
|
55 | 59 |
public boolean isAuthorizationTokenExpired() { |
56 | 60 |
try { |
57 | 61 |
long now = System.currentTimeMillis(); |
... | ... | |
109 | 113 |
builder.append("AuthorizationToken", this.getAuthorizationToken()); |
110 | 114 |
return builder.build(); |
111 | 115 |
} |
112 |
|
|
113 |
|
|
114 |
|
|
115 | 116 |
|
117 |
@Override |
|
118 |
public DownloaderCredentials createCredentials(String serviceUrl) { |
|
119 |
if (StringUtils.isBlank(serviceUrl)) { |
|
120 |
return null; |
|
121 |
} |
|
122 |
|
|
123 |
DownloaderManager downloader = DownloaderLocator.getDownloaderManager(); |
|
124 |
DownloaderAuthenticationConfig theConfig = downloader.getAuthenticationConfigurationService(serviceUrl); |
|
125 |
if(theConfig == null){ |
|
126 |
theConfig = this.config.createAuthenticationConfig(serviceUrl); |
|
127 |
} |
|
128 |
|
|
129 |
return new DownloaderKeycloakCredentials( |
|
130 |
(DownloaderAuthenticationKeycloakConfig) theConfig, |
|
131 |
this.getToken(), |
|
132 |
this.getUserid(), |
|
133 |
this.getTime() |
|
134 |
); |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
public DownloaderCredentials createCredentials(DownloaderAuthenticationConfig config) { |
|
139 |
if(!(config instanceof DownloaderAuthenticationKeycloakConfig)){ |
|
140 |
return null; |
|
141 |
} |
|
142 |
DownloaderAuthenticationKeycloakConfig otherConfig = (DownloaderAuthenticationKeycloakConfig)config; |
|
143 |
DownloaderAuthenticationKeycloakConfig myConfig = this.getConfig(); |
|
144 |
|
|
145 |
if (!DownloaderManager.areSameURLs(myConfig.getKeycloakBaseurl(), otherConfig.getKeycloakBaseurl())) { |
|
146 |
return null; |
|
147 |
} |
|
148 |
if (!StringUtils.equals(myConfig.getRealm(), otherConfig.getRealm())) { |
|
149 |
return null; |
|
150 |
} |
|
151 |
if (!StringUtils.equals(myConfig.getClientid(), otherConfig.getClientid())) { |
|
152 |
return null; |
|
153 |
} |
|
154 |
if (!StringUtils.equals(myConfig.getScope(), otherConfig.getScope())) { |
|
155 |
return null; |
|
156 |
} |
|
157 |
|
|
158 |
return new DownloaderKeycloakCredentials( |
|
159 |
otherConfig, |
|
160 |
this.getToken(), |
|
161 |
this.getUserid(), |
|
162 |
this.getTime() |
|
163 |
); |
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
|
|
116 | 168 |
} |
Also available in: Unified diff