Search in sources :

Example 26 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class ConditionalComparatorTest method testComparator.

@Test
public void testComparator() {
    Condition c1 = new Condition("a", "b");
    Condition c2 = new Condition("a", "c");
    Condition c3 = new Condition("b", "c");
    Condition c4 = new Condition("a", "b").setTimestamp(5);
    Condition c5 = new Condition("a", "b").setTimestamp(6);
    Condition c6 = new Condition("a", "b").setVisibility(new ColumnVisibility("A&B"));
    Condition c7 = new Condition("a", "b").setVisibility(new ColumnVisibility("A&C"));
    ConditionComparator comparator = new ConditionComparator();
    Assert.assertTrue(comparator.compare(c1, c1) == 0);
    Assert.assertTrue(comparator.compare(c1, c2) < 0);
    Assert.assertTrue(comparator.compare(c2, c1) > 0);
    Assert.assertTrue(comparator.compare(c1, c3) < 0);
    Assert.assertTrue(comparator.compare(c3, c1) > 0);
    Assert.assertTrue(comparator.compare(c1, c4) < 0);
    Assert.assertTrue(comparator.compare(c4, c1) > 0);
    Assert.assertTrue(comparator.compare(c5, c4) < 0);
    Assert.assertTrue(comparator.compare(c4, c5) > 0);
    Assert.assertTrue(comparator.compare(c1, c7) < 0);
    Assert.assertTrue(comparator.compare(c7, c1) > 0);
    Assert.assertTrue(comparator.compare(c6, c7) < 0);
    Assert.assertTrue(comparator.compare(c7, c6) > 0);
}
Also used : Condition(org.apache.accumulo.core.data.Condition) ConditionComparator(org.apache.accumulo.core.client.impl.ConditionalWriterImpl.ConditionComparator) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Test(org.junit.Test)

Example 27 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class TabletServerBatchDeleter method delete.

@Override
public void delete() throws MutationsRejectedException, TableNotFoundException {
    BatchWriter bw = null;
    try {
        bw = new BatchWriterImpl(context, tableId, bwConfig);
        Iterator<Entry<Key, Value>> iter = super.iterator();
        while (iter.hasNext()) {
            Entry<Key, Value> next = iter.next();
            Key k = next.getKey();
            Mutation m = new Mutation(k.getRow());
            m.putDelete(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp());
            bw.addMutation(m);
        }
    } finally {
        if (bw != null)
            bw.close();
    }
}
Also used : Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key)

Example 28 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class OfflineIterator method createIterator.

private SortedKeyValueIterator<Key, Value> createIterator(KeyExtent extent, List<String> absFiles) throws TableNotFoundException, AccumuloException, IOException {
    // TODO share code w/ tablet - ACCUMULO-1303
    // possible race condition here, if table is renamed
    String tableName = Tables.getTableName(conn.getInstance(), tableId);
    AccumuloConfiguration acuTableConf = new ConfigurationCopy(conn.tableOperations().getProperties(tableName));
    Configuration conf = CachedConfiguration.getInstance();
    for (SortedKeyValueIterator<Key, Value> reader : readers) {
        ((FileSKVIterator) reader).close();
    }
    readers.clear();
    SamplerConfiguration scannerSamplerConfig = options.getSamplerConfiguration();
    SamplerConfigurationImpl scannerSamplerConfigImpl = scannerSamplerConfig == null ? null : new SamplerConfigurationImpl(scannerSamplerConfig);
    SamplerConfigurationImpl samplerConfImpl = SamplerConfigurationImpl.newSamplerConfig(acuTableConf);
    if (scannerSamplerConfigImpl != null && ((samplerConfImpl != null && !scannerSamplerConfigImpl.equals(samplerConfImpl)) || samplerConfImpl == null)) {
        throw new SampleNotPresentException();
    }
    // TODO need to close files - ACCUMULO-1303
    for (String file : absFiles) {
        FileSystem fs = VolumeConfiguration.getVolume(file, conf, config).getFileSystem();
        FileSKVIterator reader = FileOperations.getInstance().newReaderBuilder().forFile(file, fs, conf).withTableConfiguration(acuTableConf).build();
        if (scannerSamplerConfigImpl != null) {
            reader = reader.getSample(scannerSamplerConfigImpl);
            if (reader == null)
                throw new SampleNotPresentException();
        }
        readers.add(reader);
    }
    MultiIterator multiIter = new MultiIterator(readers, extent);
    OfflineIteratorEnvironment iterEnv = new OfflineIteratorEnvironment(authorizations, acuTableConf, false, samplerConfImpl == null ? null : samplerConfImpl.toSamplerConfiguration());
    byte[] defaultSecurityLabel;
    ColumnVisibility cv = new ColumnVisibility(acuTableConf.get(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY));
    defaultSecurityLabel = cv.getExpression();
    SortedKeyValueIterator<Key, Value> visFilter = IteratorUtil.setupSystemScanIterators(multiIter, new HashSet<>(options.fetchedColumns), authorizations, defaultSecurityLabel);
    return iterEnv.getTopLevelIterator(IteratorUtil.loadIterators(IteratorScope.scan, visFilter, extent, acuTableConf, options.serverSideIteratorList, options.serverSideIteratorOptions, iterEnv, false));
}
Also used : FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) MultiIterator(org.apache.accumulo.core.iterators.system.MultiIterator) Configuration(org.apache.hadoop.conf.Configuration) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) VolumeConfiguration(org.apache.accumulo.core.volume.VolumeConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) CachedConfiguration(org.apache.accumulo.core.util.CachedConfiguration) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) FileSystem(org.apache.hadoop.fs.FileSystem) KeyValue(org.apache.accumulo.core.data.KeyValue) Value(org.apache.accumulo.core.data.Value) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) PartialKey(org.apache.accumulo.core.data.PartialKey) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 29 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo by apache.

the class ConditionalWriterImpl method isVisible.

private boolean isVisible(ByteSequence cv) {
    Text testVis = new Text(cv.toArray());
    if (testVis.getLength() == 0)
        return true;
    Boolean b = cache.get(testVis);
    if (b != null)
        return b;
    try {
        Boolean bb = ve.evaluate(new ColumnVisibility(testVis));
        cache.put(new Text(testVis), bb);
        return bb;
    } catch (VisibilityParseException | BadArgumentException e) {
        return false;
    }
}
Also used : BadArgumentException(org.apache.accumulo.core.util.BadArgumentException) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) VisibilityParseException(org.apache.accumulo.core.security.VisibilityParseException)

Example 30 with ColumnVisibility

use of org.apache.accumulo.core.security.ColumnVisibility in project accumulo-examples by apache.

the class CountIT method setupInstance.

@Before
public void setupInstance() throws Exception {
    tableName = getUniqueNames(1)[0];
    conn = getConnector();
    conn.tableOperations().create(tableName);
    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
    ColumnVisibility cv = new ColumnVisibility();
    // / has 1 dir
    // /local has 2 dirs 1 file
    // /local/user1 has 2 files
    bw.addMutation(Ingest.buildMutation(cv, "/local", true, false, true, 272, 12345, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/user1", true, false, true, 272, 12345, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/user2", true, false, true, 272, 12345, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 12345, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/file", false, false, false, 1024, 23456, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/user1/file1", false, false, false, 2024, 12345, null));
    bw.addMutation(Ingest.buildMutation(cv, "/local/user1/file2", false, false, false, 1028, 23456, null));
    bw.close();
}
Also used : BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Before(org.junit.Before)

Aggregations

ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)145 Mutation (org.apache.accumulo.core.data.Mutation)62 Text (org.apache.hadoop.io.Text)59 Value (org.apache.accumulo.core.data.Value)57 Key (org.apache.accumulo.core.data.Key)43 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 Test (org.junit.Test)23 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)19 Test (org.junit.jupiter.api.Test)18 ArrayList (java.util.ArrayList)17 Entry (java.util.Map.Entry)17 Authorizations (org.apache.accumulo.core.security.Authorizations)17 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 Scanner (org.apache.accumulo.core.client.Scanner)14 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)13 Configuration (org.apache.hadoop.conf.Configuration)13 ColumnUpdate (org.apache.accumulo.core.data.ColumnUpdate)12 AccumuloException (org.apache.accumulo.core.client.AccumuloException)11 TMutation (org.apache.accumulo.core.dataImpl.thrift.TMutation)11 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10