Search in sources :

Example 1 with UpdateProcessRemoteBase

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

the class TestAuth method update_with_auth_11.

@Test
public void update_with_auth_11() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemote(updates, authServiceUpdate);
    // Auth credentials for valid user with correct password scoped to correct URI
    // Also using pre-emptive auth
    BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
    URI scope = URI.create(authServiceUpdate);
    credsProv.setCredentials(new AuthScope(scope.getHost(), scope.getPort()), new UsernamePasswordCredentials("allowed", "password"));
    // Create AuthCache instance
    AuthCache authCache = new BasicAuthCache();
    // Generate BASIC scheme object and add it to the local auth cache
    BasicScheme basicAuth = new BasicScheme();
    authCache.put(new HttpHost(scope.getHost()), basicAuth);
    // Add AuthCache to the execution context
    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProv);
    context.setAuthCache(authCache);
    HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
    ue.setClient(client);
    ue.setHttpContext(context);
    ue.execute();
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) UpdateRequest(org.apache.jena.update.UpdateRequest) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) AuthScope(org.apache.http.auth.AuthScope) AuthCache(org.apache.http.client.AuthCache) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) BasicAuthCache(org.apache.http.impl.client.BasicAuthCache) URI(java.net.URI) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Test(org.junit.Test)

Example 2 with UpdateProcessRemoteBase

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

the class TestService method update_service_context_application_01.

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

Example 3 with UpdateProcessRemoteBase

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

the class TestAuth method update_with_auth_10.

@Test
public void update_with_auth_10() 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 scoped to
    // correct URI
    ue.setClient(withBasicAuth(new AuthScope("localhost", 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 4 with UpdateProcessRemoteBase

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

the class TestAuth method update_with_auth_02.

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

Example 5 with UpdateProcessRemoteBase

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

the class TestAuth method update_with_auth_06.

@Test(expected = HttpException.class)
public void update_with_auth_06() {
    UpdateRequest updates = UpdateFactory.create("CREATE SILENT GRAPH <http://graph>");
    UpdateProcessRemoteBase ue = (UpdateProcessRemoteBase) UpdateExecutionFactory.createRemoteForm(updates, authServiceUpdate);
    // Auth credentials for valid user with bad password
    ue.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
    ue.execute();
}
Also used : UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateProcessRemoteBase(org.apache.jena.sparql.modify.UpdateProcessRemoteBase) 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