Search in sources :

Example 46 with ColumnVisibility

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

the class DefaultFormatter method formatEntry.

public static String formatEntry(Entry<Key, Value> entry, FormatterConfig config) {
    // originally from BinaryFormatter
    StringBuilder sb = new StringBuilder();
    Key key = entry.getKey();
    Text buffer = new Text();
    final int shownLength = config.getShownLength();
    appendText(sb, key.getRow(buffer), shownLength).append(" ");
    appendText(sb, key.getColumnFamily(buffer), shownLength).append(":");
    appendText(sb, key.getColumnQualifier(buffer), shownLength).append(" ");
    sb.append(new ColumnVisibility(key.getColumnVisibility(buffer)));
    // append timestamp
    if (config.willPrintTimestamps() && config.getDateFormatSupplier() != null) {
        tmpDate.get().setTime(entry.getKey().getTimestamp());
        sb.append(" ").append(config.getDateFormatSupplier().get().format(tmpDate.get()));
    }
    // append value
    Value value = entry.getValue();
    if (value != null && value.getSize() > 0) {
        sb.append("\t");
        appendValue(sb, value, shownLength);
    }
    return sb.toString();
}
Also used : Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key)

Example 47 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 48 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 49 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 50 with ColumnVisibility

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

the class ConditionalWriterIT method testFields.

@Test
public void testFields() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    String user = null;
    ClientConfiguration clientConf = cluster.getClientConfig();
    final boolean saslEnabled = clientConf.hasSasl();
    ClusterUser user1 = getUser(0);
    user = user1.getPrincipal();
    if (saslEnabled) {
        // The token is pointless for kerberos
        conn.securityOperations().createLocalUser(user, null);
    } else {
        conn.securityOperations().createLocalUser(user, new PasswordToken(user1.getPassword()));
    }
    Authorizations auths = new Authorizations("A", "B");
    conn.securityOperations().changeUserAuthorizations(user, auths);
    conn.securityOperations().grantSystemPermission(user, SystemPermission.CREATE_TABLE);
    conn = conn.getInstance().getConnector(user, user1.getToken());
    conn.tableOperations().create(tableName);
    try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(auths));
        Scanner scanner = conn.createScanner(tableName, auths)) {
        ColumnVisibility cva = new ColumnVisibility("A");
        ColumnVisibility cvb = new ColumnVisibility("B");
        ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva));
        cm0.put("name", "last", cva, "doe");
        cm0.put("name", "first", cva, "john");
        cm0.put("tx", "seq", cva, "1");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
        scanner.setRange(new Range("99006"));
        // TODO verify all columns
        scanner.fetchColumn(new Text("tx"), new Text("seq"));
        Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        long ts = entry.getKey().getTimestamp();
        // test wrong colf
        ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("txA", "seq").setVisibility(cva).setValue("1"));
        cm1.put("name", "last", cva, "Doe");
        cm1.put("name", "first", cva, "John");
        cm1.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
        // test wrong colq
        ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seqA").setVisibility(cva).setValue("1"));
        cm2.put("name", "last", cva, "Doe");
        cm2.put("name", "first", cva, "John");
        cm2.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
        // test wrong colv
        ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
        cm3.put("name", "last", cva, "Doe");
        cm3.put("name", "first", cva, "John");
        cm3.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
        // test wrong timestamp
        ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts + 1).setValue("1"));
        cm4.put("name", "last", cva, "Doe");
        cm4.put("name", "first", cva, "John");
        cm4.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
        // test wrong timestamp
        ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts - 1).setValue("1"));
        cm5.put("name", "last", cva, "Doe");
        cm5.put("name", "first", cva, "John");
        cm5.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
        // ensure no updates were made
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        // set all columns correctly
        ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts).setValue("1"));
        cm6.put("name", "last", cva, "Doe");
        cm6.put("name", "first", cva, "John");
        cm6.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("2", entry.getValue().toString());
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Value(org.apache.accumulo.core.data.Value) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Aggregations

ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)131 Mutation (org.apache.accumulo.core.data.Mutation)57 Text (org.apache.hadoop.io.Text)57 Value (org.apache.accumulo.core.data.Value)52 Key (org.apache.accumulo.core.data.Key)39 Test (org.junit.Test)37 BatchWriter (org.apache.accumulo.core.client.BatchWriter)28 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)20 Authorizations (org.apache.accumulo.core.security.Authorizations)17 ArrayList (java.util.ArrayList)16 Entry (java.util.Map.Entry)16 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 Scanner (org.apache.accumulo.core.client.Scanner)14 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)12 Configuration (org.apache.hadoop.conf.Configuration)12 Connector (org.apache.accumulo.core.client.Connector)10 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)10 TMutation (org.apache.accumulo.core.data.thrift.TMutation)10 Element (uk.gov.gchq.gaffer.data.element.Element)9