Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic authentication for secure SOS #83

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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