From edfa1175e3485ff176367aa6f9b4fe4bd6edaf50 Mon Sep 17 00:00:00 2001 From: Guilhem Legal Date: Wed, 15 Mar 2017 12:23:28 +0100 Subject: [PATCH] Add basic authentication for secure SOS --- .../main/resources/import-configuration.xsd | 21 ++++++++---- .../sos/importer/feeder/Configuration.java | 32 ++++++++++++++++--- .../feeder/SensorObservationService.java | 12 +++++++ .../importer/feeder/task/OneTimeFeeder.java | 2 +- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/bindings/src/main/resources/import-configuration.xsd b/bindings/src/main/resources/import-configuration.xsd index d6f06403..155ea030 100644 --- a/bindings/src/main/resources/import-configuration.xsd +++ b/bindings/src/main/resources/import-configuration.xsd @@ -1207,12 +1207,21 @@ If version 2.0.0 is used, the binding has to be defined, e.g. SOAP, POX binding. - - - - - - + + + + + + If the sos server is protected by Basic + authentication, the user name and password has to + be defined. + + + + + + + An additional timeout buffer for connect and socket timeout when using import strategy "SweArrayObservationWithSplitExtension". Scale is in diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java index 2a4a9e0c..e9c757b2 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/Configuration.java @@ -387,20 +387,44 @@ public URL getSosUrl() throws MalformedURLException { } /** - *

getUser.

+ *

getSosUser.

* * @return a {@link java.lang.String} object. */ - public String getUser() { + public String getSosUser() { + if (importConf.getSosMetadata().getCredentials() != null) { + return importConf.getSosMetadata().getCredentials().getUserName(); + } + return null; + } + + /** + *

getSosPassword.

+ * + * @return a {@link java.lang.String} object. + */ + public String getSosPassword() { + if (importConf.getSosMetadata().getCredentials() != null) { + return importConf.getSosMetadata().getCredentials().getPassword(); + } + return null; + } + + /** + *

getFtpUser.

+ * + * @return a {@link java.lang.String} object. + */ + public String getFtpUser() { return importConf.getDataFile().getRemoteFile().getCredentials().getUserName(); } /** - *

getPassword.

+ *

getFtpPassword.

* * @return a {@link java.lang.String} object. */ - public String getPassword() { + public String getFtpPassword() { return importConf.getDataFile().getRemoteFile().getCredentials().getPassword(); } diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java b/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java index aa962d74..99087903 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/SensorObservationService.java @@ -35,6 +35,8 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.text.ParseException; @@ -261,6 +263,16 @@ public SensorObservationService(final Configuration config) + " if required.", sweArrayObservationTimeOutBuffer); } + if (config.getSosUser() != null && config.getSosPassword()!= null) { + try { + URI u = sosUrl.toURI(); + sosWrapper.setBasicAuthHost(u.getScheme() + "://" + u.getHost() + ':' + u.getPort()); + sosWrapper.setBasicAuthUser(config.getSosUser()); + sosWrapper.setBasicAuthPassword(config.getSosPassword()); + } catch (URISyntaxException ex) { + throw new OXFException(ex); + } + } } private Binding getBinding(final String binding) throws OXFException { diff --git a/feeder/src/main/java/org/n52/sos/importer/feeder/task/OneTimeFeeder.java b/feeder/src/main/java/org/n52/sos/importer/feeder/task/OneTimeFeeder.java index 2e17097e..dc20eb7c 100644 --- a/feeder/src/main/java/org/n52/sos/importer/feeder/task/OneTimeFeeder.java +++ b/feeder/src/main/java/org/n52/sos/importer/feeder/task/OneTimeFeeder.java @@ -129,7 +129,7 @@ private DataFile getRemoteFile() { FileOutputStream fos = null; try { client.connect(config.getFtpHost()); - final boolean login = client.login(config.getUser(), config.getPassword()); + final boolean login = client.login(config.getFtpUser(), config.getFtpPassword()); if (login) { LOG.info("FTP: connected..."); // download file