Search in sources :

Example 11 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DisjunctiveNormalFormConverterTest method testTruthTableNullNode.

/**
 * Test truth table with a {@code null} {@link Node}.
 */
@Test(expected = NullPointerException.class)
public void testTruthTableNullNode() {
    final Node node = null;
    final byte[] expression = new DocumentVisibility("A").getExpression();
    DisjunctiveNormalFormConverter.createTruthTableInputs(node, expression);
}
Also used : Node(org.apache.accumulo.core.security.ColumnVisibility.Node) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Example 12 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class MongoDBRyaDAO2IT method testReconstructDao.

@Test
public void testReconstructDao() throws RyaDAOException, IOException {
    MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setSubject(new RyaURI("http://subject.com"));
        builder.setObject(new RyaURI("http://object.com"));
        builder.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
    // Test reinitializing the same instance
    try {
        dao.init();
    } finally {
        dao.destroy();
    }
    // Reconstruct new DAO and try again
    dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setSubject(new RyaURI("http://subject.com"));
        builder.setObject(new RyaURI("http://object.com"));
        builder.setColumnVisibility(new DocumentVisibility("B").flatten());
        final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME));
        final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName());
        dao.add(builder.build());
        assertEquals(coll.count(), 1);
        final Document dbo = coll.find().first();
        assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY));
        assertTrue(dbo.containsKey(TIMESTAMP));
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase) Test(org.junit.Test)

Example 13 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DocumentVisibilityUtil method doesUserHaveDocumentAccess.

/**
 * Checks if the user's authorizations allows them to have access to the
 * provided document based on its document visibility.
 * @param authorizations the {@link Authorizations}.
 * @param documentVisibility the document visibility byte expression.
 * @return {@code true} if the user has access to the document.
 * {@code false} otherwise.
 */
public static boolean doesUserHaveDocumentAccess(final Authorizations authorizations, final byte[] documentVisibilityExpression) {
    final byte[] expression = documentVisibilityExpression != null ? documentVisibilityExpression : MongoDbRdfConstants.EMPTY_DV.getExpression();
    final DocumentVisibility documentVisibility = new DocumentVisibility(expression);
    return doesUserHaveDocumentAccess(authorizations, documentVisibility);
}
Also used : DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility)

Example 14 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class DocumentVisibilityUtil method toMultidimensionalArray.

/**
 * Converts a {@link DocumentVisibility} object into a multidimensional
 * array representation of the boolean expression.
 * @param dv the {@link DocumentVisibility}. (not {@code null})
 * @return the multidimensional array representation of the boolean
 * expression.
 * @throws DocumentVisibilityConversionException
 */
public static Object[] toMultidimensionalArray(final DocumentVisibility dv) throws DocumentVisibilityConversionException {
    checkNotNull(dv);
    final byte[] expression = dv.flatten();
    final DocumentVisibility flattenedDv = DisjunctiveNormalFormConverter.createDnfDocumentVisibility(expression);
    final Object[] result = toMultidimensionalArray(flattenedDv.getParseTree(), flattenedDv.getExpression());
    // (i.e. "A" should be ["A"])
    if (result.length > 0 && result[0] instanceof String) {
        final List<Object[]> formattedResult = new ArrayList<>();
        formattedResult.add(result);
        return formattedResult.toArray(new Object[0]);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility)

Example 15 with DocumentVisibility

use of org.apache.rya.mongodb.document.visibility.DocumentVisibility in project incubator-rya by apache.

the class MongoDBRyaDAOIT method testDeleteWildcard.

@Test
public void testDeleteWildcard() throws RyaDAOException {
    final MongoDBRyaDAO dao = new MongoDBRyaDAO();
    try {
        dao.setConf(conf);
        dao.init();
        final RyaStatementBuilder builder = new RyaStatementBuilder();
        builder.setPredicate(new RyaURI("http://temp.com"));
        builder.setColumnVisibility(new DocumentVisibility("A").flatten());
        dao.delete(builder.build(), conf);
    } finally {
        dao.destroy();
    }
}
Also used : RyaURI(org.apache.rya.api.domain.RyaURI) RyaStatementBuilder(org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder) DocumentVisibility(org.apache.rya.mongodb.document.visibility.DocumentVisibility) Test(org.junit.Test)

Aggregations

DocumentVisibility (org.apache.rya.mongodb.document.visibility.DocumentVisibility)18 Test (org.junit.Test)12 RyaURI (org.apache.rya.api.domain.RyaURI)7 RyaStatementBuilder (org.apache.rya.api.domain.RyaStatement.RyaStatementBuilder)6 MongoDatabase (com.mongodb.client.MongoDatabase)5 Document (org.bson.Document)5 RyaStatement (org.apache.rya.api.domain.RyaStatement)3 ArrayList (java.util.ArrayList)2 Node (org.apache.accumulo.core.security.ColumnVisibility.Node)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 RyaType (org.apache.rya.api.domain.RyaType)1 StatementMetadata (org.apache.rya.api.domain.StatementMetadata)1 MalformedDocumentVisibilityException (org.apache.rya.mongodb.document.visibility.DocumentVisibilityAdapter.MalformedDocumentVisibilityException)1