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();
}
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();
}
}
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));
}
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;
}
}
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());
}
}
Aggregations