Search in sources :

Example 86 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestParameterizedSparqlString method test_param_string_injection_07.

@Test(expected = ARQException.class)
public void test_param_string_injection_07() {
    // This injection attempt is prevented by forbidding injection of
    // variable parameters immediately surrounded by quotes
    String str = "PREFIX : <http://example/>\nINSERT DATA { <s> <p> \"?var\" }";
    ParameterizedSparqlString pss = new ParameterizedSparqlString(str);
    pss.setLiteral("var", " . } ; DROP ALL ; INSERT DATA { <s> <p> ");
    UpdateRequest updates = pss.asUpdate();
    Assert.fail("Attempt to do SPARQL injection should result in an exception");
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) Test(org.junit.Test)

Example 87 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_01.

@Test(expected = HttpException.class)
public void update_with_auth_01() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // No auth credentials should result in an error
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 88 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_07.

@Test
public void update_with_auth_07() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password
    ue.setClient(withBasicAuth(ANY, "allowed", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 89 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project jena by apache.

the class TestAuth method update_with_auth_03.

@Test
public void update_with_auth_03() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password
    ue.setClient(withBasicAuth(ANY, "allowed", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 90 with UpdateRequest

use of org.apache.jena.update.UpdateRequest in project webofneeds by researchstudio-sat.

the class SparqlUpdateCrawlerCallback method onDatasetCrawled.

@Override
public void onDatasetCrawled(final URI uri, final Dataset dataset) {
    if (null == sparqlEndpoint) {
        logger.warn("no SPARQL endpoint defined");
        return;
    }
    Iterator<String> graphNames = dataset.listNames();
    while (graphNames.hasNext()) {
        StringBuilder quadpatterns = new StringBuilder();
        String graphName = graphNames.next();
        Model model = dataset.getNamedModel(graphName);
        StringWriter sw = new StringWriter();
        RDFDataMgr.write(sw, model, Lang.NTRIPLES);
        quadpatterns.append("\nINSERT DATA { GRAPH <").append(graphName).append("> { ").append(sw).append("}};\n");
        logger.info(quadpatterns.toString());
        UpdateRequest update = UpdateFactory.create(quadpatterns.toString());
        UpdateProcessRemote riStore = (UpdateProcessRemote) UpdateExecutionFactory.createRemote(update, sparqlEndpoint);
        riStore.execute();
    }
}
Also used : StringWriter(java.io.StringWriter) UpdateRequest(org.apache.jena.update.UpdateRequest) Model(org.apache.jena.rdf.model.Model) UpdateProcessRemote(org.apache.jena.sparql.modify.UpdateProcessRemote)

Aggregations

UpdateRequest (org.apache.jena.update.UpdateRequest)130 Test (org.junit.Test)85 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)20 UpdateProcessor (org.apache.jena.update.UpdateProcessor)14 UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 Model (org.apache.jena.rdf.model.Model)10 Dataset (org.apache.jena.query.Dataset)9 UpdateExecution (org.apache.jena.update.UpdateExecution)9 Node (org.apache.jena.graph.Node)7 RDFNode (org.apache.jena.rdf.model.RDFNode)6 Resource (org.apache.jena.rdf.model.Resource)6 HttpTest (org.apache.jena.fuseki.test.HttpTest)5 URI (java.net.URI)4 HashMap (java.util.HashMap)4 Syntax (org.apache.jena.query.Syntax)4 Context (org.apache.jena.sparql.util.Context)4 AuthScope (org.apache.http.auth.AuthScope)3 Literal (org.apache.jena.rdf.model.Literal)3 Update (org.apache.jena.update.Update)3 StringWriter (java.io.StringWriter)2