You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2013/07/04 00:48:23 UTC
svn commit: r1499590 - in /jena/Experimental/jena-jdbc: ./
jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/
jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/
jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/con...
Author: rvesse
Date: Wed Jul 3 22:48:22 2013
New Revision: 1499590
URL: http://svn.apache.org/r1499590
Log:
Revise remote endpoint driver implementation to use new HTTP auth framework.
Added new parameters for remote endpoint driver for providing more control over configuring authentication
Added:
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithAuth.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithAuth.java
Modified:
jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/metadata/RemoteEndpointMetadata.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointStatement.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TS_JdbcDriverRemote.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithResultSetTypes.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java
jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithResultSetTypes.java
jena/Experimental/jena-jdbc/pom.xml
Modified: jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-core/src/test/java/org/apache/jena/jdbc/utils/TestUtils.java Wed Jul 3 22:48:22 2013
@@ -20,6 +20,8 @@ package org.apache.jena.jdbc.utils;
import java.util.Iterator;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
+
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetAccessor;
@@ -34,36 +36,44 @@ import com.hp.hpl.jena.sparql.core.Quad;
* Test utility methods
*/
public class TestUtils {
-
+
/**
* Generates a synthetic dataset for testing
- * @param numGraphs Number of graphs to generate
- * @param triplesPerGraph Triples per graph
- * @param createDefaultGraph Whether to generate a default graph
+ *
+ * @param numGraphs
+ * Number of graphs to generate
+ * @param triplesPerGraph
+ * Triples per graph
+ * @param createDefaultGraph
+ * Whether to generate a default graph
* @return Synthetic dataset
*/
public static Dataset generateDataset(int numGraphs, int triplesPerGraph, boolean createDefaultGraph) {
- if (numGraphs <= 0) throw new IllegalArgumentException("Number of graphs must be >= 1");
- if (triplesPerGraph <= 0) throw new IllegalArgumentException("Number of triples per graph must be >= 1");
-
+ if (numGraphs <= 0)
+ throw new IllegalArgumentException("Number of graphs must be >= 1");
+ if (triplesPerGraph <= 0)
+ throw new IllegalArgumentException("Number of triples per graph must be >= 1");
+
Dataset ds = DatasetFactory.createMem();
if (createDefaultGraph) {
numGraphs--;
Model def = ModelFactory.createDefaultModel();
for (int i = 1; i <= triplesPerGraph; i++) {
- def.add(def.createStatement(def.createResource("http://default/subject/" + i), def.createProperty("http://default/predicate"), def.createTypedLiteral(i)));
+ def.add(def.createStatement(def.createResource("http://default/subject/" + i),
+ def.createProperty("http://default/predicate"), def.createTypedLiteral(i)));
}
ds.setDefaultModel(def);
}
-
+
for (int g = 1; g < numGraphs; g++) {
Model named = ModelFactory.createDefaultModel();
for (int i = 1; i <= triplesPerGraph; i++) {
- named.add(named.createStatement(named.createResource("http://named/subject/" + i), named.createProperty("http://named/predicate"), named.createTypedLiteral(i)));
+ named.add(named.createStatement(named.createResource("http://named/subject/" + i),
+ named.createProperty("http://named/predicate"), named.createTypedLiteral(i)));
}
ds.addNamedModel("http://named/" + g, named);
}
-
+
return ds;
}
@@ -99,7 +109,7 @@ public class TestUtils {
while (quads.hasNext()) {
targetDSG.add(quads.next());
}
- } else {
+ } else {
target.setDefaultModel(source.getDefaultModel());
}
@@ -121,7 +131,22 @@ public class TestUtils {
* Remote Graph Store protocol service
*/
public static void copyToRemoteDataset(Dataset source, String service) {
- DatasetAccessor target = DatasetAccessorFactory.createHTTP(service);
+ copyToRemoteDataset(source, service, null);
+ }
+
+ /**
+ * Copies a dataset to a remote service that provides SPARQL 1.1 Graph Store
+ * protocol support
+ *
+ * @param source
+ * Source Dataset
+ * @param service
+ * Remote Graph Store protocol service
+ * @param authenticator
+ * HTTP Authenticator
+ */
+ public static void copyToRemoteDataset(Dataset source, String service, HttpAuthenticator authenticator) {
+ DatasetAccessor target = DatasetAccessorFactory.createHTTP(service, authenticator);
target.putModel(source.getDefaultModel());
Iterator<String> uris = source.listNames();
while (uris.hasNext()) {
@@ -131,10 +156,15 @@ public class TestUtils {
}
/**
- * Renames a graph of a dataset producing a new dataset so as to not modify the original dataset
- * @param ds Dataset
- * @param oldUri Old URI
- * @param newUri New URI
+ * Renames a graph of a dataset producing a new dataset so as to not modify
+ * the original dataset
+ *
+ * @param ds
+ * Dataset
+ * @param oldUri
+ * Old URI
+ * @param newUri
+ * New URI
* @return New Dataset
*/
public static Dataset renameGraph(Dataset ds, String oldUri, String newUri) {
@@ -146,7 +176,7 @@ public class TestUtils {
// Copy across default graph
dest.setDefaultModel(ds.getDefaultModel());
}
-
+
Iterator<String> uris = ds.listNames();
while (uris.hasNext()) {
String uri = uris.next();
@@ -162,7 +192,7 @@ public class TestUtils {
dest.addNamedModel(uri, ds.getNamedModel(uri));
}
}
-
+
return dest;
}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/RemoteEndpointDriver.java Wed Jul 3 22:48:22 2013
@@ -18,12 +18,22 @@
package org.apache.jena.jdbc.remote;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import org.apache.jena.atlas.web.auth.ApacheModAuthFormLogin;
+import org.apache.jena.atlas.web.auth.FormLogin;
+import org.apache.jena.atlas.web.auth.FormsAuthenticator;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
+import org.apache.jena.atlas.web.auth.PreemptiveBasicAuthenticator;
+import org.apache.jena.atlas.web.auth.SimpleAuthenticator;
import org.apache.jena.jdbc.JdbcCompatibility;
import org.apache.jena.jdbc.JenaDriver;
import org.apache.jena.jdbc.connections.JenaConnection;
@@ -77,10 +87,35 @@ import org.apache.jena.jdbc.remote.conne
* <li>{@code model-results-type} - Sets the format to request {@code CONSTRUCT}
* and {@code DESCRIBE} results in from the remote endpoint</li>
* </ul>
+ * <h3>Authentication Parameters</h3>
* <p>
* The driver also supports the standard JDBC {@code user} and {@code password}
* parameters which are used to set user credentials for authenticating to the
- * remote HTTP server.
+ * remote HTTP server. This uses the ARQ HTTP authenticator API behind the
+ * scenes so the following parameters may also be used to configure desired
+ * behavior:
+ * </p>
+ * <ul>
+ * <li>{@code preemptive-auth} - Sets a boolean indicating whether preemptive
+ * basic authentication should be enabled, disabled by default.</li>
+ * <li>{@code form-url} - Sets a URL to use for form based login.</li>
+ * <li>{@code form-user-field} - Sets the name of the user name field used for
+ * form based login. If omitted but {@code forms-url} is used then the default
+ * value {@code httpd_username} is used i.e. we assume you are communicating
+ * with a Apache mod_auth_form protected site that uses the default form
+ * configuration.</li>
+ * <li>{@code form-password-field} - Sets the name of the password field used
+ * for form based login. If omitted but {@code form-url} is used then the
+ * default value {@code httpd_password} is used i.e. we assume you are
+ * communicating with a Apache mod_auth_form protected site that uses the
+ * default form configuration.</li>
+ * </ul>
+ * <p>
+ * Alternatively you may use the {@code authenticator} parameter to set a
+ * specific authenticator implementation to use, must be passed an instance of
+ * {@link HttpAuthenticator} so can only be passed via the {@link Properties}
+ * object and not via the connection URL. If this parameter is used then all
+ * other authentication parameters are ignored.
* </p>
*/
public class RemoteEndpointDriver extends JenaDriver {
@@ -145,6 +180,41 @@ public class RemoteEndpointDriver extend
public static final String PARAM_MODEL_RESULTS_TYPE = "model-results-type";
/**
+ * Constant for the connection URL parameter that sets the URL to use for
+ * form based login.
+ */
+ public static final String PARAM_FORMS_LOGIN_URL = "form-url";
+
+ /**
+ * Constant for the connection URL parameter that sets the user name field
+ * to use for form based logins
+ */
+ public static final String PARAM_FORMS_LOGIN_USER_FIELD = "form-user-field";
+
+ /**
+ * Constant for the connection URL parameter that sets the password field to
+ * use for form based logins
+ */
+ public static final String PARAM_FORMS_LOGIN_PASSWORD_FIELD = "form-password-field";
+
+ /**
+ * Constant for the connection URL parameter that sets that preemptive
+ * authentication should be enabled.
+ */
+ public static final String PARAM_PREEMPTIVE_AUTH = "preemptive-auth";
+
+ /**
+ * Constant for the parameter used to specify an authenticator used.
+ * <p>
+ * It is <strong>important</strong> to be aware that you must pass in an
+ * actual instance of a {@link HttpAuthenticator} for this parameter so you
+ * cannot use directly in the Connection URL and must pass in via the
+ * {@link Properties} object.
+ * </p>
+ */
+ public static final String PARAM_AUTHENTICATOR = "authenticator";
+
+ /**
* Static initializer block which ensures the driver gets registered
*/
static {
@@ -204,6 +274,33 @@ public class RemoteEndpointDriver extend
List<String> usingNamedGraphs = this.getValues(props, PARAM_USING_NAMED_GRAPH_URI);
// Authentication settings
+ HttpAuthenticator authenticator = this.configureAuthenticator(queryEndpoint, updateEndpoint, props);
+
+ // Result Types
+ String selectResultsType = props.getProperty(PARAM_SELECT_RESULTS_TYPE, null);
+ String modelResultsType = props.getProperty(PARAM_MODEL_RESULTS_TYPE, null);
+
+ // Create connection
+ return openConnection(queryEndpoint, updateEndpoint, defaultGraphs, namedGraphs, usingGraphs, usingNamedGraphs,
+ authenticator, JenaConnection.DEFAULT_HOLDABILITY, compatibilityLevel, selectResultsType, modelResultsType);
+ }
+
+ protected HttpAuthenticator configureAuthenticator(String queryEndpoint, String updateEndpoint, Properties props)
+ throws SQLException {
+ // Is there a specific authenticator to use?
+ Object authObj = props.get(PARAM_AUTHENTICATOR);
+ if (authObj != null) {
+ if (authObj instanceof HttpAuthenticator) {
+ return (HttpAuthenticator) authObj;
+ } else {
+ throw new SQLException(
+ "The "
+ + PARAM_AUTHENTICATOR
+ + " parameter is specified but the value is not an object implementing the required HttpAuthenticator interface");
+ }
+ }
+
+ // Otherwise get credentials to use
String user = props.getProperty(PARAM_USERNAME, null);
if (user != null && user.trim().length() == 0)
user = null;
@@ -211,13 +308,146 @@ public class RemoteEndpointDriver extend
if (password != null && password.trim().length() == 0)
password = null;
- // Result Types
- String selectResultsType = props.getProperty(PARAM_SELECT_RESULTS_TYPE, null);
- String modelResultsType = props.getProperty(PARAM_MODEL_RESULTS_TYPE, null);
+ // If no credentials then we won't configure anything
+ if (user == null || password == null)
+ return null;
+
+ // Are we using HTTP or form based login?
+ String loginURL = props.getProperty(PARAM_FORMS_LOGIN_URL);
+ if (loginURL != null) {
+ // Determine login fields
+ String userField = props.getProperty(PARAM_FORMS_LOGIN_USER_FIELD, ApacheModAuthFormLogin.USER_FIELD);
+ String pwdField = props.getProperty(PARAM_FORMS_LOGIN_PASSWORD_FIELD, ApacheModAuthFormLogin.PASSWORD_FIELD);
+
+ // Create logins
+ Map<URI, FormLogin> logins = new HashMap<URI, FormLogin>();
+ String baseUri = this.getCommonBase(queryEndpoint, updateEndpoint);
+ if (baseUri != null) {
+ // Since both endpoints are specified and they have a common
+ // Base URI create a single login
+ try {
+ logins.put(new URI(baseUri), new FormLogin(loginURL, userField, pwdField, user, password.toCharArray()));
+ } catch (URISyntaxException e) {
+ throw new SQLException("Unable to configure form based login due to invalid Base URI", e);
+ }
+ } else {
+ // Only one endpoint is specified or they did not share a common
+ // base
+ if (queryEndpoint != null) {
+ // Add a query endpoint specific login
+ try {
+ logins.put(new URI(queryEndpoint),
+ new FormLogin(loginURL, userField, pwdField, user, password.toCharArray()));
+ } catch (URISyntaxException e) {
+ throw new SQLException("Unable to configure form based login due to invalid Query Endpoint URI", e);
+ }
+ }
+ if (updateEndpoint != null) {
+ // Add an update endpoint specific login
+ try {
+ logins.put(new URI(updateEndpoint),
+ new FormLogin(loginURL, userField, pwdField, user, password.toCharArray()));
+ } catch (URISyntaxException e) {
+ throw new SQLException("Unable to configure form based login due to invalid Update Endpoint URI", e);
+ }
+ }
+ }
+ return new FormsAuthenticator(logins);
+ } else {
+ // Do we want preemptive authentication?
+ if (this.isTrue(props, PARAM_PREEMPTIVE_AUTH)) {
+ return new PreemptiveBasicAuthenticator(new SimpleAuthenticator(user, password.toCharArray()));
+ } else {
+ // Use simple authenticator
+ return new SimpleAuthenticator(user, password.toCharArray());
+ }
+ }
+ }
- // Create connection
- return openConnection(queryEndpoint, updateEndpoint, defaultGraphs, namedGraphs, usingGraphs, usingNamedGraphs, user,
- password, JenaConnection.DEFAULT_HOLDABILITY, compatibilityLevel, selectResultsType, modelResultsType);
+ /**
+ * Determines the common base of the two URIs if there is one
+ *
+ * @param x
+ * URI
+ * @param y
+ * URI
+ * @return Common base if it exists, null otherwise
+ */
+ private String getCommonBase(String x, String y) {
+ if (x == null || y == null) {
+ return null;
+ } else if (x.equals(y)) {
+ return x;
+ } else {
+ // Is one the base of the other?
+ if (x.length() < y.length() && y.startsWith(x)) {
+ return x;
+ } else if (y.length() < x.length() && x.startsWith(y)) {
+ return y;
+ }
+
+ // Otherwise we should strip last URI component off one/both URIs
+ // and recurse
+ if (x.length() < y.length()) {
+ // y is longer so strip last component
+ y = this.stripLastComponent(y);
+ } else if (x.length() > y.length()) {
+ // x is longer so strip last component
+ x = this.stripLastComponent(x);
+ } else {
+ // Equal length so strip last component from both
+ x = this.stripLastComponent(x);
+ y = this.stripLastComponent(y);
+ }
+ return this.getCommonBase(x, y);
+ }
+ }
+
+ /**
+ * Strips the last component of the given URI if possible
+ *
+ * @param input
+ * URI
+ * @return Reduced URI or null if no further reduction is possible
+ */
+ private String stripLastComponent(String input) {
+ try {
+ URI uri = new URI(input);
+ if (uri.getFragment() != null) {
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(),
+ null).toString();
+ } else if (uri.getQuery() != null) {
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), null, null)
+ .toString();
+ } else if (uri.getPath() != null) {
+ // Try and strip off last segment of the path
+ String currPath = uri.getPath();
+ if (currPath.endsWith("/")) {
+ currPath = currPath.substring(0, currPath.length() - 1);
+ if (currPath.length() == 0)
+ currPath = null;
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null)
+ .toString();
+ } else if (currPath.contains("/")) {
+ currPath = currPath.substring(0, currPath.lastIndexOf('/') + 1);
+ if (currPath.length() == 0)
+ currPath = null;
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), currPath, null, null)
+ .toString();
+ } else {
+ // If path is non-null it must always contain a /
+ // otherwise it would be an invalid path
+ // In this case there are no further components to strip
+ return null;
+ }
+ } else {
+ // No further components to strip
+ return null;
+ }
+ } catch (URISyntaxException e) {
+ // Error stripping component
+ return null;
+ }
}
/**
@@ -242,10 +472,8 @@ public class RemoteEndpointDriver extend
* Default Graphs for updates
* @param usingNamedGraphs
* Named Graphs for updates
- * @param user
- * User name
- * @param password
- * Password
+ * @param authenticator
+ * HTTP Authenticator
* @param holdability
* Result Set holdability
* @param compatibilityLevel
@@ -259,10 +487,10 @@ public class RemoteEndpointDriver extend
* @throws SQLException
*/
protected RemoteEndpointConnection openConnection(String queryEndpoint, String updateEndpoint, List<String> defaultGraphs,
- List<String> namedGraphs, List<String> usingGraphs, List<String> usingNamedGraphs, String user, String password,
+ List<String> namedGraphs, List<String> usingGraphs, List<String> usingNamedGraphs, HttpAuthenticator authenticator,
int holdability, int compatibilityLevel, String selectResultsType, String modelResultsType) throws SQLException {
return new RemoteEndpointConnection(queryEndpoint, updateEndpoint, defaultGraphs, namedGraphs, usingGraphs,
- usingNamedGraphs, user, password, holdability, compatibilityLevel, selectResultsType, modelResultsType);
+ usingNamedGraphs, authenticator, holdability, compatibilityLevel, selectResultsType, modelResultsType);
}
@Override
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/connections/RemoteEndpointConnection.java Wed Jul 3 22:48:22 2013
@@ -25,6 +25,7 @@ import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.List;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import org.apache.jena.jdbc.JdbcCompatibility;
import org.apache.jena.jdbc.connections.JenaConnection;
import org.apache.jena.jdbc.remote.metadata.RemoteEndpointMetadata;
@@ -46,8 +47,7 @@ public class RemoteEndpointConnection ex
private List<String> namedGraphUris;
private List<String> usingGraphUris;
private List<String> usingNamedGraphUris;
- private String username;
- private char[] password;
+ private HttpAuthenticator authenticator;
private DatabaseMetaData metadata;
private String selectResultsType, modelResultsType;
@@ -67,7 +67,7 @@ public class RemoteEndpointConnection ex
*/
public RemoteEndpointConnection(String queryEndpoint, String updateEndpoint, int holdability, int compatibilityLevel)
throws SQLException {
- this(queryEndpoint, updateEndpoint, null, null, null, null, null, null, holdability, compatibilityLevel, null, null);
+ this(queryEndpoint, updateEndpoint, null, null, null, null, null, holdability, compatibilityLevel, null, null);
}
/**
@@ -85,10 +85,8 @@ public class RemoteEndpointConnection ex
* Default Graph URIs for SPARQL updates
* @param usingNamedGraphUris
* Named Graph URIs for SPARQL updates
- * @param username
- * User name to supply for HTTP basic authentication
- * @param password
- * Password to supply for HTTP basic authentication
+ * @param authenticator
+ * HTTP Authenticator
* @param holdability
* Result Set holdability
* @param compatibilityLevel
@@ -103,9 +101,9 @@ public class RemoteEndpointConnection ex
* Thrown if there is a problem creating the connection
*/
public RemoteEndpointConnection(String queryEndpoint, String updateEndpoint, List<String> defaultGraphUris,
- List<String> namedGraphUris, List<String> usingGraphUris, List<String> usingNamedGraphUris, String username,
- String password, int holdability, int compatibilityLevel, String selectResultsType, String modelResultsType)
- throws SQLException {
+ List<String> namedGraphUris, List<String> usingGraphUris, List<String> usingNamedGraphUris,
+ HttpAuthenticator authenticator, int holdability, int compatibilityLevel, String selectResultsType,
+ String modelResultsType) throws SQLException {
super(holdability, true, Connection.TRANSACTION_NONE, compatibilityLevel);
if (queryEndpoint == null && updateEndpoint == null)
throw new SQLException("Must specify one/both of a query endpoint and update endpoint");
@@ -116,8 +114,7 @@ public class RemoteEndpointConnection ex
this.namedGraphUris = namedGraphUris;
this.usingGraphUris = usingGraphUris;
this.usingNamedGraphUris = usingNamedGraphUris;
- this.username = username;
- this.password = (password != null) ? password.toCharArray() : null;
+ this.authenticator = authenticator;
this.metadata = new RemoteEndpointMetadata(this);
this.selectResultsType = selectResultsType;
this.modelResultsType = modelResultsType;
@@ -210,10 +207,11 @@ public class RemoteEndpointConnection ex
if (this.isClosed())
throw new SQLException("Cannot create a statement after the connection was closed");
if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)
- throw new SQLFeatureNotSupportedException("Remote endpoint backed connection do not support scroll sensitive result sets");
+ throw new SQLFeatureNotSupportedException(
+ "Remote endpoint backed connection do not support scroll sensitive result sets");
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
throw new SQLFeatureNotSupportedException("Remote endpoint backed connections only support read-only result sets");
- return new RemoteEndpointStatement(this, this.username, this.password, resultSetType, ResultSet.FETCH_FORWARD, 0,
+ return new RemoteEndpointStatement(this, this.authenticator, resultSetType, ResultSet.FETCH_FORWARD, 0,
resultSetHoldability);
}
@@ -223,11 +221,12 @@ public class RemoteEndpointConnection ex
if (this.isClosed())
throw new SQLException("Cannot create a statement after the connection was closed");
if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)
- throw new SQLFeatureNotSupportedException("Remote endpoint backed connection do not support scroll sensitive result sets");
+ throw new SQLFeatureNotSupportedException(
+ "Remote endpoint backed connection do not support scroll sensitive result sets");
if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
throw new SQLFeatureNotSupportedException("Remote endpoint backed connections only support read-only result sets");
- return new RemoteEndpointPreparedStatement(sparql, this, this.username, this.password, resultSetType,
- ResultSet.FETCH_FORWARD, 0, resultSetHoldability);
+ return new RemoteEndpointPreparedStatement(sparql, this, this.authenticator, resultSetType, ResultSet.FETCH_FORWARD, 0,
+ resultSetHoldability);
}
@Override
@@ -284,11 +283,13 @@ public class RemoteEndpointConnection ex
}
/**
- * Gets the username used for HTTP authentication (if any)
+ * Gets whether any HTTP authenticator has been provided. Note that the
+ * provision of an authenticator does not guarantee authentication since
+ * that will be down to the configuration of the given authenticator.
*
- * @return Username
+ * @return True if an authenticator is provided, false otherwise
*/
- public String getUserName() {
- return this.username;
+ public boolean isUsingAuthentication() {
+ return this.authenticator != null;
}
}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/metadata/RemoteEndpointMetadata.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/metadata/RemoteEndpointMetadata.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/metadata/RemoteEndpointMetadata.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/metadata/RemoteEndpointMetadata.java Wed Jul 3 22:48:22 2013
@@ -29,16 +29,19 @@ import com.hp.hpl.jena.sparql.util.Versi
/**
* Represents metadata about connections to remote endpoints
- *
+ *
*/
public class RemoteEndpointMetadata extends JenaMetadata {
-
+
private Version jdbc;
+ @SuppressWarnings("unused")
private RemoteEndpointConnection remoteConn;
-
+
/**
* Creates new metadata
- * @param connection Remote Endpoint connection
+ *
+ * @param connection
+ * Remote Endpoint connection
* @throws SQLException
*/
public RemoteEndpointMetadata(RemoteEndpointConnection connection) throws SQLException {
@@ -107,14 +110,14 @@ public class RemoteEndpointMetadata exte
// Underlying database is unknown
return null;
}
-
+
@Override
public String getUserName() throws SQLException {
- if (this.remoteConn != null) {
- return this.remoteConn.getUserName();
- } else {
- return null;
- }
+ // Even though we may be using a HTTP authenticator that may not be
+ // using a user name based login method and regardless for security
+ // reasons the authenticator APIs don't expose the underlying
+ // credentials in any way
+ return null;
}
@Override
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointPreparedStatement.java Wed Jul 3 22:48:22 2013
@@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
import org.apache.jena.jdbc.statements.JenaPreparedStatement;
import com.hp.hpl.jena.query.Query;
@@ -41,8 +42,7 @@ import com.hp.hpl.jena.update.UpdateRequ
public class RemoteEndpointPreparedStatement extends JenaPreparedStatement {
private RemoteEndpointConnection remoteConn;
- private String username;
- private char[] password;
+ private HttpAuthenticator authenticator;
/**
* Creates a new statement
@@ -55,7 +55,7 @@ public class RemoteEndpointPreparedState
* Thrown if there is an error with the statement parameters
*/
public RemoteEndpointPreparedStatement(String sparql, RemoteEndpointConnection connection) throws SQLException {
- this(sparql, connection, null, null, DEFAULT_TYPE, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
+ this(sparql, connection, null, DEFAULT_TYPE, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
}
/**
@@ -65,10 +65,8 @@ public class RemoteEndpointPreparedState
* SPARQL command
* @param connection
* Connection
- * @param username
- * Username for HTTP Basic Authentication
- * @param password
- * Username for HTTP Basic Authentication
+ * @param authenticator
+ * HTTP Authenticator
* @param type
* Result Set type for result sets produced by this statement
* @param fetchDir
@@ -81,12 +79,11 @@ public class RemoteEndpointPreparedState
* Thrown if there is an error with the statement parameters
*
*/
- public RemoteEndpointPreparedStatement(String sparql, RemoteEndpointConnection connection, String username, char[] password,
+ public RemoteEndpointPreparedStatement(String sparql, RemoteEndpointConnection connection, HttpAuthenticator authenticator,
int type, int fetchDir, int fetchSize, int holdability) throws SQLException {
super(sparql, connection, type, fetchDir, fetchSize, holdability, false, Connection.TRANSACTION_NONE);
this.remoteConn = connection;
- this.username = username;
- this.password = password;
+ this.authenticator = authenticator;
}
@Override
@@ -98,8 +95,8 @@ public class RemoteEndpointPreparedState
QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q);
// Apply authentication settings
- if (this.username != null && this.password != null) {
- exec.setBasicAuthentication(this.username, this.password);
+ if (this.authenticator != null) {
+ exec.setAuthenticator(this.authenticator);
}
// Apply default and named graphs if appropriate
@@ -109,7 +106,7 @@ public class RemoteEndpointPreparedState
if (this.remoteConn.getNamedGraphURIs() != null) {
exec.setNamedGraphURIs(this.remoteConn.getNamedGraphURIs());
}
-
+
// Set result types
if (this.remoteConn.getSelectResultsType() != null) {
exec.setSelectContentType(this.remoteConn.getSelectResultsType());
@@ -128,8 +125,8 @@ public class RemoteEndpointPreparedState
this.remoteConn.getUpdateEndpoint());
// Apply authentication settings
- if (this.username != null && this.password != null) {
- proc.setAuthentication(this.username, this.password);
+ if (this.authenticator != null) {
+ proc.setAuthenticator(this.authenticator);
}
// Apply default and named graphs if appropriate
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointStatement.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointStatement.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointStatement.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/main/java/org/apache/jena/jdbc/remote/statements/RemoteEndpointStatement.java Wed Jul 3 22:48:22 2013
@@ -22,6 +22,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
import org.apache.jena.jdbc.statements.JenaStatement;
@@ -42,8 +43,7 @@ import com.hp.hpl.jena.update.UpdateRequ
public class RemoteEndpointStatement extends JenaStatement {
private RemoteEndpointConnection remoteConn;
- private String username;
- private char[] password;
+ private HttpAuthenticator authenticator;
/**
* Creates a new statement
@@ -54,7 +54,7 @@ public class RemoteEndpointStatement ext
* Thrown if there is an error with the statement parameters
*/
public RemoteEndpointStatement(RemoteEndpointConnection connection) throws SQLException {
- this(connection, null, null, DEFAULT_TYPE, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
+ this(connection, null, DEFAULT_TYPE, DEFAULT_FETCH_DIRECTION, DEFAULT_FETCH_SIZE, DEFAULT_HOLDABILITY);
}
/**
@@ -64,10 +64,7 @@ public class RemoteEndpointStatement ext
* Connection
* @param type
* Result Set type for result sets produced by this statement
- * @param username
- * Username for HTTP Basic Authentication
- * @param password
- * Username for HTTP Basic Authentication
+ * @param authenticator HTTP Authenticator
* @param fetchDir
* Fetch Direction
* @param fetchSize
@@ -78,12 +75,11 @@ public class RemoteEndpointStatement ext
* Thrown if there is an error with the statement parameters
*
*/
- public RemoteEndpointStatement(RemoteEndpointConnection connection, String username, char[] password, int type, int fetchDir,
+ public RemoteEndpointStatement(RemoteEndpointConnection connection, HttpAuthenticator authenticator, int type, int fetchDir,
int fetchSize, int holdability) throws SQLException {
super(connection, type, fetchDir, fetchSize, holdability, false, Connection.TRANSACTION_NONE);
this.remoteConn = connection;
- this.username = username;
- this.password = password;
+ this.authenticator = authenticator;
}
@Override
@@ -95,8 +91,8 @@ public class RemoteEndpointStatement ext
QueryEngineHTTP exec = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(this.remoteConn.getQueryEndpoint(), q);
// Apply authentication settings
- if (this.username != null && this.password != null) {
- exec.setBasicAuthentication(this.username, this.password);
+ if (this.authenticator != null) {
+ exec.setAuthenticator(authenticator);
}
// Apply default and named graphs if appropriate
@@ -125,8 +121,8 @@ public class RemoteEndpointStatement ext
this.remoteConn.getUpdateEndpoint());
// Apply authentication settings
- if (this.username != null && this.password != null) {
- proc.setAuthentication(this.username, this.password);
+ if (this.authenticator != null) {
+ proc.setAuthenticator(this.authenticator);
}
// Apply default and named graphs if appropriate
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TS_JdbcDriverRemote.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TS_JdbcDriverRemote.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TS_JdbcDriverRemote.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/TS_JdbcDriverRemote.java Wed Jul 3 22:48:22 2013
@@ -18,10 +18,12 @@
package org.apache.jena.jdbc.remote;
import org.apache.jena.jdbc.remote.connections.TestRemoteEndpointConnection;
+import org.apache.jena.jdbc.remote.connections.TestRemoteEndpointConnectionWithAuth;
import org.apache.jena.jdbc.remote.connections.TestRemoteEndpointConnectionWithGraphUris;
import org.apache.jena.jdbc.remote.connections.TestRemoteEndpointConnectionWithResultSetTypes;
import org.apache.jena.jdbc.remote.metadata.TestRemoteConnectionMetadata;
import org.apache.jena.jdbc.remote.results.TestRemoteEndpointResults;
+import org.apache.jena.jdbc.remote.results.TestRemoteEndpointResultsWithAuth;
import org.apache.jena.jdbc.remote.results.TestRemoteEndpointResultsWithGraphUris;
import org.apache.jena.jdbc.remote.results.TestRemoteEndpointResultsWithResultSetTypes;
import org.apache.jena.jdbc.remote.statements.TestRemoteEndpointStatements;
@@ -36,11 +38,13 @@ import org.junit.runners.Suite;
@Suite.SuiteClasses({
TestRemoteEndpointDriver.class,
TestRemoteEndpointConnection.class,
+ TestRemoteEndpointConnectionWithAuth.class,
TestRemoteEndpointConnectionWithGraphUris.class,
TestRemoteEndpointConnectionWithResultSetTypes.class,
TestRemoteConnectionMetadata.class,
TestRemoteEndpointStatements.class,
TestRemoteEndpointResults.class,
+ TestRemoteEndpointResultsWithAuth.class,
TestRemoteEndpointResultsWithGraphUris.class,
TestRemoteEndpointResultsWithResultSetTypes.class
})
Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithAuth.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithAuth.java?rev=1499590&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithAuth.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithAuth.java Wed Jul 3 22:48:22 2013
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.remote.connections;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.SQLException;
+
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
+import org.apache.jena.atlas.web.auth.SimpleAuthenticator;
+import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.ServerTest;
+import org.apache.jena.fuseki.server.FusekiConfig;
+import org.apache.jena.fuseki.server.SPARQLServer;
+import org.apache.jena.fuseki.server.ServerConfig;
+import org.apache.jena.jdbc.JdbcCompatibility;
+import org.apache.jena.jdbc.connections.AbstractJenaConnectionTests;
+import org.apache.jena.jdbc.connections.JenaConnection;
+import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
+import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.sparql.core.DatasetGraphFactory;
+import com.hp.hpl.jena.sparql.modify.request.Target;
+import com.hp.hpl.jena.sparql.modify.request.UpdateDrop;
+import com.hp.hpl.jena.update.Update;
+import com.hp.hpl.jena.update.UpdateExecutionFactory;
+import com.hp.hpl.jena.update.UpdateProcessor;
+
+/**
+ * Tests for the {@link RemoteEndpointConnection} where we use HTTP
+ * authentication
+ *
+ */
+public class TestRemoteEndpointConnectionWithAuth extends AbstractJenaConnectionTests {
+
+ private static String USER = "test";
+ private static String PASSWORD = "letmein";
+ private static File realmFile;
+ private static SPARQLServer server;
+ private static HttpAuthenticator authenticator;
+
+ /**
+ * Setup for the tests by allocating a Fuseki instance to work with
+ * @throws IOException
+ */
+ @BeforeClass
+ public static void setup() throws IOException {
+ authenticator = new SimpleAuthenticator(USER, PASSWORD.toCharArray());
+
+ realmFile = File.createTempFile("realm", ".properties");
+
+ FileWriter writer = new FileWriter(realmFile);
+ writer.write(USER + ": " + PASSWORD + ", fuseki\n");
+ writer.close();
+
+ Log.logLevel(Fuseki.serverLog.getName(), org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+ Log.logLevel(Fuseki.requestLog.getName(), org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+ Log.logLevel("org.eclipse.jetty", org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+
+ DatasetGraph dsg = DatasetGraphFactory.createMem();
+ // This must agree with ServerTest
+ ServerConfig conf = FusekiConfig.defaultConfiguration(ServerTest.datasetPath, dsg, true);
+ conf.port = ServerTest.port;
+ conf.pagesPort = ServerTest.port;
+ conf.authConfigFile = realmFile.getAbsolutePath();
+
+ server = new SPARQLServer(conf);
+ server.start();
+ }
+
+ /**
+ * Clean up after each test by resetting the Fuseki instance
+ */
+ @After
+ public void cleanupTest() {
+ Update clearRequest = new UpdateDrop(Target.ALL) ;
+ UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, ServerTest.serviceUpdate, authenticator) ;
+ proc.execute() ;
+ }
+
+ /**
+ * Clean up after tests by de-allocating the Fuseki instance
+ */
+ @AfterClass
+ public static void cleanup() {
+ server.stop();
+ realmFile.delete();
+ }
+
+ @Override
+ protected boolean supportsTimeouts() {
+ // While timeouts are supported they are unreliable for remote
+ // connections
+ return false;
+ }
+
+ @Override
+ protected JenaConnection getConnection() throws SQLException {
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null,
+ authenticator, JenaConnection.DEFAULT_HOLDABILITY,
+ JdbcCompatibility.DEFAULT, null, null);
+ }
+
+ @Override
+ protected JenaConnection getConnection(Dataset ds) throws SQLException {
+ // Set up the dataset
+ TestUtils.copyToRemoteDataset(ds, ServerTest.serviceREST, authenticator);
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null,
+ authenticator, JenaConnection.DEFAULT_HOLDABILITY,
+ JdbcCompatibility.DEFAULT, null, null);
+ }
+}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithGraphUris.java Wed Jul 3 22:48:22 2013
@@ -20,6 +20,7 @@ package org.apache.jena.jdbc.remote.conn
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.jena.fuseki.ServerTest;
@@ -36,16 +37,18 @@ import org.junit.BeforeClass;
import com.hp.hpl.jena.query.Dataset;
/**
- * Tests for the {@link RemoteEndpointConnection} where we force the default graph to be a named graph and use connection URL parameters to ensure desired default graph is used
- *
+ * Tests for the {@link RemoteEndpointConnection} where we force the default
+ * graph to be a named graph and use connection URL parameters to ensure desired
+ * default graph is used
+ *
*/
public class TestRemoteEndpointConnectionWithGraphUris extends AbstractJenaConnectionTests {
-
+
/**
* Constant used for default graph URI in these tests
*/
private static final String DEFAULT_GRAPH_URI = "http://example.org/defaultGraph";
-
+
/**
* Setup for the tests by allocating a Fuseki instance to work with
*/
@@ -53,7 +56,7 @@ public class TestRemoteEndpointConnectio
public static void setup() {
ServerTest.allocServer();
}
-
+
/**
* Clean up after each test by resetting the Fuseki instance
*/
@@ -61,7 +64,7 @@ public class TestRemoteEndpointConnectio
public void cleanupTest() {
ServerTest.resetServer();
}
-
+
/**
* Clean up after tests by de-allocating the Fuseki instance
*/
@@ -69,10 +72,11 @@ public class TestRemoteEndpointConnectio
public static void cleanup() {
ServerTest.freeServer();
}
-
+
@Override
protected boolean supportsTimeouts() {
- // While timeouts are supported they are unreliable for remote connections
+ // While timeouts are supported they are unreliable for remote
+ // connections
return false;
}
@@ -80,26 +84,36 @@ public class TestRemoteEndpointConnectio
protected JenaConnection getConnection() throws SQLException {
List<String> defaultGraphs = new ArrayList<String>();
defaultGraphs.add(DEFAULT_GRAPH_URI);
- return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, defaultGraphs, null, defaultGraphs, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, defaultGraphs, null,
+ defaultGraphs, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
}
@Override
protected JenaConnection getConnection(Dataset ds) throws SQLException {
List<String> defaultGraphs = new ArrayList<String>();
defaultGraphs.add(DEFAULT_GRAPH_URI);
-
+ List<String> namedGraphs = new ArrayList<String>();
+ Iterator<String> names = ds.listNames();
+ while (names.hasNext()) {
+ String name = names.next();
+ if (!DEFAULT_GRAPH_URI.equals(name)) {
+ namedGraphs.add(name);
+ }
+ }
+
// Set up the dataset
ds = TestUtils.renameGraph(ds, null, DEFAULT_GRAPH_URI);
Assert.assertEquals(0, ds.getDefaultModel().size());
TestUtils.copyToRemoteDataset(ds, ServerTest.serviceREST);
- return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT);
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, defaultGraphs, namedGraphs,
+ defaultGraphs, namedGraphs, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
}
@Override
protected boolean usesNamedGraphAsDefault() {
return true;
}
-
+
@Override
protected String getDefaultGraphName() throws SQLException {
return DEFAULT_GRAPH_URI;
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithResultSetTypes.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithResultSetTypes.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithResultSetTypes.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/connections/TestRemoteEndpointConnectionWithResultSetTypes.java Wed Jul 3 22:48:22 2013
@@ -70,13 +70,13 @@ public class TestRemoteEndpointConnectio
@Override
protected JenaConnection getConnection() throws SQLException {
- return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
}
@Override
protected JenaConnection getConnection(Dataset ds) throws SQLException {
// Set up the dataset
TestUtils.copyToRemoteDataset(ds, ServerTest.serviceREST);
- return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
+ return new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
}
}
Added: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithAuth.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithAuth.java?rev=1499590&view=auto
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithAuth.java (added)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithAuth.java Wed Jul 3 22:48:22 2013
@@ -0,0 +1,136 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.jdbc.remote.results;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.apache.jena.atlas.logging.Log;
+import org.apache.jena.atlas.web.auth.HttpAuthenticator;
+import org.apache.jena.atlas.web.auth.SimpleAuthenticator;
+import org.apache.jena.fuseki.Fuseki;
+import org.apache.jena.fuseki.ServerTest;
+import org.apache.jena.fuseki.server.FusekiConfig;
+import org.apache.jena.fuseki.server.SPARQLServer;
+import org.apache.jena.fuseki.server.ServerConfig;
+import org.apache.jena.jdbc.JdbcCompatibility;
+import org.apache.jena.jdbc.connections.JenaConnection;
+import org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection;
+import org.apache.jena.jdbc.results.AbstractResultSetTests;
+import org.apache.jena.jdbc.utils.TestUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.sparql.core.DatasetGraphFactory;
+import com.hp.hpl.jena.sparql.modify.request.Target;
+import com.hp.hpl.jena.sparql.modify.request.UpdateDrop;
+import com.hp.hpl.jena.update.Update;
+import com.hp.hpl.jena.update.UpdateExecutionFactory;
+import com.hp.hpl.jena.update.UpdateProcessor;
+
+/**
+ * Tests result sets from a remote endpoint
+ *
+ */
+public class TestRemoteEndpointResultsWithAuth extends AbstractResultSetTests {
+
+ private static RemoteEndpointConnection connection;
+
+ private static String USER = "test";
+ private static String PASSWORD = "letmein";
+ private static File realmFile;
+ private static SPARQLServer server;
+ private static HttpAuthenticator authenticator;
+
+ /**
+ * Setup for the tests by allocating a Fuseki instance to work with
+ *
+ * @throws SQLException
+ * @throws IOException
+ */
+ @BeforeClass
+ public static void setup() throws SQLException, IOException {
+ authenticator = new SimpleAuthenticator(USER, PASSWORD.toCharArray());
+
+ realmFile = File.createTempFile("realm", ".properties");
+
+ FileWriter writer = new FileWriter(realmFile);
+ writer.write(USER + ": " + PASSWORD + ", fuseki\n");
+ writer.close();
+
+ Log.logLevel(Fuseki.serverLog.getName(), org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+ Log.logLevel(Fuseki.requestLog.getName(), org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+ Log.logLevel("org.eclipse.jetty", org.apache.log4j.Level.WARN, java.util.logging.Level.WARNING);
+
+ DatasetGraph dsg = DatasetGraphFactory.createMem();
+ // This must agree with ServerTest
+ ServerConfig conf = FusekiConfig.defaultConfiguration(ServerTest.datasetPath, dsg, true);
+ conf.port = ServerTest.port;
+ conf.pagesPort = ServerTest.port;
+ conf.authConfigFile = realmFile.getAbsolutePath();
+
+ server = new SPARQLServer(conf);
+ server.start();
+
+ connection = new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null,
+ authenticator, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
+ connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
+ }
+
+ /**
+ * Clean up after each test by resetting the Fuseki instance
+ */
+ @After
+ public void cleanupTest() {
+ Update clearRequest = new UpdateDrop(Target.ALL) ;
+ UpdateProcessor proc = UpdateExecutionFactory.createRemote(clearRequest, ServerTest.serviceUpdate, authenticator) ;
+ proc.execute() ;
+ }
+
+ /**
+ * Clean up after tests by de-allocating the Fuseki instance
+ *
+ * @throws SQLException
+ */
+ @AfterClass
+ public static void cleanup() throws SQLException {
+ server.stop();
+ connection.close();
+ realmFile.delete();
+ }
+
+ @Override
+ protected ResultSet createResults(Dataset ds, String query) throws SQLException {
+ return createResults(ds, query, ResultSet.TYPE_FORWARD_ONLY);
+ }
+
+ @Override
+ protected ResultSet createResults(Dataset ds, String query, int resultSetType) throws SQLException {
+ TestUtils.copyToRemoteDataset(ds, ServerTest.serviceREST, authenticator);
+ Statement stmt = connection.createStatement(resultSetType, ResultSet.CONCUR_READ_ONLY);
+ return stmt.executeQuery(query);
+ }
+}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithGraphUris.java Wed Jul 3 22:48:22 2013
@@ -60,7 +60,7 @@ public class TestRemoteEndpointResultsWi
List<String> defaultGraphUris = new ArrayList<String>();
defaultGraphUris.add(DEFAULT_GRAPH_URI);
- connection = new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, defaultGraphUris, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
+ connection = new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, defaultGraphUris, null, defaultGraphUris, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, null, null);
connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}
Modified: jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithResultSetTypes.java
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithResultSetTypes.java?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithResultSetTypes.java (original)
+++ jena/Experimental/jena-jdbc/jena-jdbc-driver-remote/src/test/java/org/apache/jena/jdbc/remote/results/TestRemoteEndpointResultsWithResultSetTypes.java Wed Jul 3 22:48:22 2013
@@ -50,7 +50,7 @@ public class TestRemoteEndpointResultsWi
public static void setup() throws SQLException {
ServerTest.allocServer();
- connection = new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
+ connection = new RemoteEndpointConnection(ServerTest.serviceQuery, ServerTest.serviceUpdate, null, null, null, null, null, JenaConnection.DEFAULT_HOLDABILITY, JdbcCompatibility.DEFAULT, WebContent.contentTypeTextTSV, WebContent.contentTypeRdfJson);
connection.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
}
Modified: jena/Experimental/jena-jdbc/pom.xml
URL: http://svn.apache.org/viewvc/jena/Experimental/jena-jdbc/pom.xml?rev=1499590&r1=1499589&r2=1499590&view=diff
==============================================================================
--- jena/Experimental/jena-jdbc/pom.xml (original)
+++ jena/Experimental/jena-jdbc/pom.xml Wed Jul 3 22:48:22 2013
@@ -103,8 +103,8 @@
Only downside to this approach is that when you bump versions you have to disable the goals temporarily
-->
- <!-- <goal>aggregate</goal>
- <goal>aggregate-jar</goal>-->
+ <goal>aggregate</goal>
+ <goal>aggregate-jar</goal>
</goals>
</execution>
</executions>