Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Add basic authentication for secure SOS
Browse files Browse the repository at this point in the history
  • Loading branch information
glegal committed Dec 4, 2017
1 parent 70db273 commit 2ebf9a9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
9 changes: 9 additions & 0 deletions bindings/src/main/resources/import-configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,15 @@
</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="Credentials" minOccurs="0">
<xs:annotation>
<xs:documentation>
If the sos server is protected by Basic
authentication, the user name and password has to
be defined.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="insertSweArrayObservationTimeoutBuffer">
<xs:annotation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,44 @@ public URL getSosUrl() throws MalformedURLException {
}

/**
* <p>getUser.</p>
* <p>getSosUser.</p>
*
* @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;
}

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

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

/**
* <p>getPassword.</p>
* <p>getFtpPassword.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getPassword() {
public String getFtpPassword() {
return importConf.getDataFile().getRemoteFile().getCredentials().getPassword();
}

Expand Down
12 changes: 12 additions & 0 deletions feeder/src/main/java/org/n52/sos/importer/feeder/Feeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -268,6 +270,16 @@ public Feeder(final Configuration config)
sweArrayObservationTimeOutBuffer);
}
isUseLastTimestamp = config.isUseLastTimestamp();
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DataFile download() {
try (FileOutputStream fos = new FileOutputStream(file);) {
client.connect(config.getRemoteFileURL());
if (config.areRemoteFileCredentialsSet()) {
client.login(config.getUser(), config.getPassword());
client.login(config.getFtpUser(), config.getFtpPassword());
}
client.enterLocalPassiveMode();
URL remoteFileURL = new URL(config.getRemoteFileURL());
Expand Down

0 comments on commit 2ebf9a9

Please sign in to comment.