diff --git a/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java b/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java index d5da63c47..aeb491e5d 100644 --- a/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java +++ b/src/main/java/org/aksw/iguana/cc/config/elements/ConnectionConfig.java @@ -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; @@ -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 { @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 \ No newline at end of file diff --git a/src/main/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorker.java b/src/main/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorker.java index 67a57f988..e1a0cb722 100644 --- a/src/main/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorker.java +++ b/src/main/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorker.java @@ -86,10 +86,10 @@ public Supplier 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()) diff --git a/src/test/java/org/aksw/iguana/cc/config/elements/ConnectionConfigTest.java b/src/test/java/org/aksw/iguana/cc/config/elements/ConnectionConfigTest.java index 3bcddbc5a..0cddf0089 100644 --- a/src/test/java/org/aksw/iguana/cc/config/elements/ConnectionConfigTest.java +++ b/src/test/java/org/aksw/iguana/cc/config/elements/ConnectionConfigTest.java @@ -23,17 +23,19 @@ private static Stream 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"}} """)); diff --git a/src/test/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorkerTest.java b/src/test/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorkerTest.java index 24a6efc61..7f07e282c 100644 --- a/src/test/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorkerTest.java +++ b/src/test/java/org/aksw/iguana/cc/worker/impl/SPARQLProtocolWorkerTest.java @@ -63,7 +63,7 @@ public static Stream> 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>(); int i = 0; @@ -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,