Search in sources :

Example 21 with SailConnection

use of org.openrdf.sail.SailConnection in project incubator-rya by apache.

the class AccumuloAddUserIT method userAddedCanInsert.

/**
 * Ensure a user that has been added to the Rya instance can interact with it.
 */
@Test
public void userAddedCanInsert() throws Exception {
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();
    final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
    // Create the user that will not be added to the instance of Rya, but will try to scan it.
    secOps.createLocalUser(user, new PasswordToken(user));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Add the user.
    userAClient.getAddUser().get().addUser(getRyaInstanceName(), user);
    // Try to add a statement to the Rya instance. This should succeed.
    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userDConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userDConf);
        sailConn = sail.getConnection();
        final ValueFactory vf = sail.getValueFactory();
        sailConn.begin();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
        sailConn.close();
    } finally {
        if (sailConn != null) {
            sailConn.close();
        }
        if (sail != null) {
            sail.shutDown();
        }
    }
}
Also used : PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) Test(org.junit.Test)

Example 22 with SailConnection

use of org.openrdf.sail.SailConnection in project incubator-rya by apache.

the class AccumuloAddUserIT method userNotAddedCanNotInsert.

/**
 * Ensure a user that has not been added to the Rya instance can not interact with it.
 */
@Test
public void userNotAddedCanNotInsert() throws Exception {
    final String user = testInstance.createUniqueUser();
    final SecurityOperations secOps = super.getConnector().securityOperations();
    final RyaClient userAClient = AccumuloRyaClientFactory.build(new AccumuloConnectionDetails(ADMIN_USER, ADMIN_USER.toCharArray(), getInstanceName(), getZookeepers()), super.getClusterInstance().getCluster().getConnector(ADMIN_USER, ADMIN_USER));
    // Install the instance of Rya.
    userAClient.getInstall().install(getRyaInstanceName(), InstallConfiguration.builder().build());
    // Create the user that will not be added to the instance of Rya, but will try to scan it.
    secOps.createLocalUser(user, new PasswordToken(user));
    // Try to add a statement the Rya instance with the unauthorized user. This should fail.
    boolean securityExceptionThrown = false;
    Sail sail = null;
    SailConnection sailConn = null;
    try {
        final AccumuloRdfConfiguration userCConf = makeRyaConfig(getRyaInstanceName(), user, user, getInstanceName(), getZookeepers());
        sail = RyaSailFactory.getInstance(userCConf);
        sailConn = sail.getConnection();
        final ValueFactory vf = sail.getValueFactory();
        sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:talksTo"), vf.createURI("urn:Bob"));
    } catch (final RuntimeException e) {
        final Throwable cause = e.getCause();
        if (cause instanceof AccumuloSecurityException) {
            securityExceptionThrown = true;
        }
    } finally {
        if (sailConn != null) {
            sailConn.close();
        }
        if (sail != null) {
            sail.shutDown();
        }
    }
    assertTrue(securityExceptionThrown);
}
Also used : SecurityOperations(org.apache.accumulo.core.client.admin.SecurityOperations) RyaClient(org.apache.rya.api.client.RyaClient) ValueFactory(org.openrdf.model.ValueFactory) AccumuloRdfConfiguration(org.apache.rya.accumulo.AccumuloRdfConfiguration) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) SailConnection(org.openrdf.sail.SailConnection) Sail(org.openrdf.sail.Sail) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Test(org.junit.Test)

Example 23 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class SailGraph method commit.

public void commit() {
    try {
        SailConnection sc = this.sailConnection.get();
        sc.commit();
        sc.begin();
    } catch (SailException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException)

Example 24 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class SailGraph method saveRDF.

/**
     * Save RDF data from the SailGraph.
     * Supported formats include rdf-xml, n-triples, turtle, n3, trix, or trig.
     *
     * @param output the OutputStream to which to write RDF data
     * @param format supported formats include rdf-xml, n-triples, turtle, n3, trix, or trig
     */
public void saveRDF(final OutputStream output, final String format) {
    try {
        this.commit();
        final SailConnection c = this.rawGraph.getConnection();
        try {
            c.begin();
            RDFWriter w = Rio.createWriter(getFormat(format), output);
            w.startRDF();
            CloseableIteration<? extends Statement, SailException> iter = c.getStatements(null, null, null, false);
            try {
                while (iter.hasNext()) {
                    w.handleStatement(iter.next());
                }
            } finally {
                iter.close();
            }
            w.endRDF();
        } finally {
            c.rollback();
            c.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) RDFWriter(org.openrdf.rio.RDFWriter) SailException(org.openrdf.sail.SailException) SailException(org.openrdf.sail.SailException) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) RDFHandlerException(org.openrdf.rio.RDFHandlerException)

Example 25 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class SailGraph method rollback.

public void rollback() {
    try {
        SailConnection sc = this.sailConnection.get();
        sc.rollback();
        sc.begin();
    } catch (SailException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException)

Aggregations

SailConnection (org.openrdf.sail.SailConnection)55 Test (org.junit.Test)34 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)28 URI (org.openrdf.model.URI)25 SailException (org.openrdf.sail.SailException)14 Sail (org.openrdf.sail.Sail)10 ValueFactory (org.openrdf.model.ValueFactory)9 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)8 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)5 RyaClient (org.apache.rya.api.client.RyaClient)5 Literal (org.openrdf.model.Literal)5 Resource (org.openrdf.model.Resource)5 Statement (org.openrdf.model.Statement)5 ParsedQuery (org.openrdf.query.parser.ParsedQuery)5 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)5 URIImpl (org.openrdf.model.impl.URIImpl)4 BindingSet (org.openrdf.query.BindingSet)4 Vertex (com.tinkerpop.blueprints.Vertex)3 EmptyBindingSet (org.openrdf.query.impl.EmptyBindingSet)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3