Skip to content

Commit

Permalink
add authentication subrecord inside ConnectionConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
nck-mlcnv committed Oct 4, 2023
1 parent bbbf9b3 commit 150c920
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.aksw.iguana.cc.controller.MainController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URI;
Expand All @@ -18,28 +15,25 @@
public record ConnectionConfig(
@JsonProperty(required = true)
String name,
String version,
@JsonProperty(required = true)
DatasetConfig dataset,
@JsonProperty(required = true)
@JsonDeserialize(contentUsing = URIDeserializer.class)
@JsonDeserialize(using = URIDeserializer.class)
URI endpoint,
String version,
String user,
String password,
@JsonDeserialize(contentUsing = URIDeserializer.class)
Authentication authentication,
@JsonDeserialize(using = URIDeserializer.class)
URI updateEndpoint,
DatasetConfig dataset
Authentication updateAuthentication

) {
public static class URIDeserializer extends JsonDeserializer<URI> {

@Override
public URI deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
try {
return URI.create(p.getValueAsString());
} catch (IllegalArgumentException e) {
throw e;
}
return URI.create(p.getValueAsString()); // verifying uri doesn't work here
}
}

public record Authentication(String user, String password) {}
}
// TODO: separate user/password for updateEndpoint
// TODO: support for authentication in SPARQLProtocolWorker
// TODO: move authentication to a sub-record
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public Supplier<InputStream> getStreamSupplier() {

if (requestHeader != null)
request.header("Accept", requestHeader);
if (connection.user() != null)
if (connection.authentication().user() != null)
request.header("Authorization",
HttpWorker.basicAuth(connection.user(),
Optional.ofNullable(connection.password()).orElse("")));
HttpWorker.basicAuth(connection.authentication().user(),
Optional.ofNullable(connection.authentication().password()).orElse("")));
switch (this.requestType) {
case GET_QUERY -> {
request.uri(new URIBuilder(connection.endpoint())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ private static Stream<Arguments> testData() {
return Stream.of(
Arguments.of(new ConnectionConfig(
"endpoint01",
URI.create("http://example.com/sparql"),
"0.1",
null, null, null, null
null,
URI.create("http://example.com/sparql"),
null, null, null
), """
{"name":"endpoint01","endpoint":"http://example.com/sparql","version":"0.1","user":null,"password":null,"updateEndpoint":null,"dataset":null}
"""),
Arguments.of(new ConnectionConfig(
"endpoint01",
URI.create("http://example.com/sparql"),
"0.1",
null, null, null, new DatasetConfig("MyData", "some.ttl")
new DatasetConfig("MyData", "some.ttl"),
URI.create("http://example.com/sparql"),
null, null, null
), """
{"name":"endpoint01","endpoint":"http://example.com/sparql","version":"0.1","user":null,"password":null,"updateEndpoint":null,"dataset":{"name":"MyData","file":"some.ttl"}}
"""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static Stream<Named<?>> requestFactoryData() throws IOException, URISynta
final var processor = new ResponseBodyProcessor("application/sparql-results+json");
final var queryHandlder = new QueryHandler(new QueryHandler.Config(queryFile.toAbsolutePath().toString(), QueryHandler.Config.Format.SEPARATOR, true, QueryHandler.Config.Order.LINEAR, 0L, QueryHandler.Config.Language.SPARQL));
final var datasetConfig = new DatasetConfig("TestDS", null);
final var connection = new ConnectionConfig("TestConn", uri, "1", "testUser", "password", null, datasetConfig);
final var connection = new ConnectionConfig("TestConn", "1", datasetConfig, uri, new ConnectionConfig.Authentication("user", "password"), null, null);

final var workers = new ArrayDeque<Named<?>>();
int i = 0;
Expand Down Expand Up @@ -143,7 +143,7 @@ public void testTimeLimit() throws URISyntaxException, IOException {
final var processor = new ResponseBodyProcessor("application/sparql-results+json");
final var queryHandlder = new QueryHandler(new QueryHandler.Config(queryFile.toAbsolutePath().toString(), QueryHandler.Config.Format.SEPARATOR, true, QueryHandler.Config.Order.LINEAR, 0L, QueryHandler.Config.Language.SPARQL));
final var datasetConfig = new DatasetConfig("TestDS", null);
final var connection = new ConnectionConfig("TestConn", uri, "1", "testUser", "password", null, datasetConfig);
final var connection = new ConnectionConfig("TestConn", "1", datasetConfig, uri, new ConnectionConfig.Authentication("user", "password"), null, null);

final var config = new SPARQLProtocolWorker.Config(
1,
Expand Down

0 comments on commit 150c920

Please sign in to comment.