Search in sources :

Example 6 with UpdateProcessRemoteBase

use of org.apache.jena.sparql.modify.UpdateProcessRemoteBase in project jena by apache.

the class TestAuth method update_with_auth_08.

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

Example 7 with UpdateProcessRemoteBase

use of org.apache.jena.sparql.modify.UpdateProcessRemoteBase in project jena by apache.

the class TestAuth method update_with_auth_09.

@Test(expected = HttpException.class)
public void update_with_auth_09() throws URISyntaxException {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password but scoped to
    // wrong URI
    ue.setClient(withBasicAuth(new AuthScope("example", authPort), "allowed", "password"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) AuthScope(org.apache.http.auth.AuthScope) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) Test(org.junit.Test)

Example 8 with UpdateProcessRemoteBase

use of org.apache.jena.sparql.modify.UpdateProcessRemoteBase in project jena by apache.

the class TestAuth method update_with_auth_05.

@Test(expected = HttpException.class)
public void update_with_auth_05() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(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 9 with UpdateProcessRemoteBase

use of org.apache.jena.sparql.modify.UpdateProcessRemoteBase in project jena by apache.

the class TestAuth method update_with_auth_04.

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

Example 10 with UpdateProcessRemoteBase

use of org.apache.jena.sparql.modify.UpdateProcessRemoteBase in project jena by apache.

the class TestService method update_service_context_application_02.

@SuppressWarnings("unchecked")
@Test
public void update_service_context_application_02() {
    // This test requires no service context to be set
    Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap == null) {
        ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
        serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    }
    if (serviceContextMap.get(SERVICE) == null) {
        serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
    }
    Context serviceContext = serviceContextMap.get(SERVICE);
    try {
        HttpClient testClient = HttpClients.custom().build();
        serviceContext.put(Service.queryClient, testClient);
        UpdateRequest updates = UpdateFactory.create("CREATE GRAPH <http://example>");
        UpdateProcessRemoteBase engine = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, SERVICE);
        Assert.assertNotNull(engine);
        // Check that client settings were changed
        Assert.assertEquals(testClient, engine.getClient());
    } finally {
        serviceContext.remove(Service.queryClient);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) UpdateRequest(org.apache.jena.update.UpdateRequest) HttpClient(org.apache.http.client.HttpClient) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

UpdateProcessRemoteBase (org.apache.jena.sparql.modify.UpdateProcessRemoteBase)13 UpdateRequest (org.apache.jena.update.UpdateRequest)13 Test (org.junit.Test)13 AuthScope (org.apache.http.auth.AuthScope)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 HttpClient (org.apache.http.client.HttpClient)2 Context (org.apache.jena.sparql.util.Context)2 URI (java.net.URI)1 HttpHost (org.apache.http.HttpHost)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 AuthCache (org.apache.http.client.AuthCache)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 BasicScheme (org.apache.http.impl.auth.BasicScheme)1 BasicAuthCache (org.apache.http.impl.client.BasicAuthCache)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1