本文整理汇总了Java中org.apache.accumulo.core.security.ColumnVisibility类的典型用法代码示例。如果您正苦于以下问题:Java ColumnVisibility类的具体用法?Java ColumnVisibility怎么用?Java ColumnVisibility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ColumnVisibility类属于org.apache.accumulo.core.security包,在下文中一共展示了ColumnVisibility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: multipleWritesNotSearchableTest
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Test
public void multipleWritesNotSearchableTest() throws Exception {
List<String> rows = Arrays.asList("row1", "row2", "row3");
List<String> colFs = Arrays.asList("colF1", "colF2", "colF3");
List<String> colQs = Arrays.asList("colQ1", "colQ2", "colQ3");
List<String> colVs = Arrays.asList("secret", ColumnVisibility.quote("top secret"));
List<String> values = Arrays.asList("value1", "value2", "value3");
// Initial data.
EncryptedBatchWriter writer = getEncryptedWriter(CHARLIE, "all.ini");
writeData(writer, rows, colFs, colQs, colVs, values);
writer.close();
EncryptedBatchScanner scanner = getEncryptedScanner(CHARLIE, "all.ini");
scanner.setRanges(Collections.singletonList(new Range()));
assertThat("contains the correct data", scanner, hasData(rows, colFs, colQs, colVs, values));
// Update the data.
writer = getEncryptedWriter(CHARLIE, "all.ini");
writeData(writer, rows, colFs, colQs, colVs, Collections.singletonList("value4"));
writer.close();
scanner = getEncryptedScanner(CHARLIE, "all.ini");
scanner.setRanges(Collections.singletonList(new Range()));
assertThat("contains the correct data", scanner, hasData(rows, colFs, colQs, colVs, Arrays.asList("value1", "value2", "value3", "value4")));
}
示例2: multipleWritesSearchableTest
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Test
public void multipleWritesSearchableTest() throws Exception {
List<String> rows = Arrays.asList("row1", "row2", "row3");
List<String> colFs = Arrays.asList("colF1", "colF2", "colF3");
List<String> colQs = Arrays.asList("colQ1", "colQ2", "colQ3");
List<String> colVs = Arrays.asList("secret", ColumnVisibility.quote("top secret"));
List<String> values = Arrays.asList("value1", "value2", "value3");
// Initial data.
EncryptedBatchWriter writer = getEncryptedWriter(CHARLIE, "searchable.ini");
writeData(writer, rows, colFs, colQs, colVs, values);
writer.close();
EncryptedBatchScanner scanner = getEncryptedScanner(CHARLIE, "searchable.ini");
scanner.setRanges(Collections.singletonList(new Range()));
assertThat("contains the most recent version of the data", scanner, hasData(rows, colFs, colQs, colVs, Collections.singletonList("value3")));
// Update the data.
writer = getEncryptedWriter(CHARLIE, "searchable.ini");
writeData(writer, rows, colFs, colQs, colVs, Collections.singletonList("value4"));
writer.close();
scanner = getEncryptedScanner(CHARLIE, "searchable.ini");
scanner.setRanges(Collections.singletonList(new Range()));
assertThat("contains the most recent version of the data", scanner, hasData(rows, colFs, colQs, colVs, Collections.singletonList("value4")));
}
示例3: writeData
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
/**
* Writes the given data to Accumulo. The full combinatorial of values is written.
*
* @param rows
* Rows to write.
* @param colFs
* Column families to write.
* @param colQs
* Column qualifiers to write.
* @param colVs
* Column visibilities to write.
* @param values
* Values to write.
*/
private static void writeData(BatchWriter writer, Iterable<String> rows, Iterable<String> colFs, Iterable<String> colQs, Iterable<String> colVs,
Iterable<String> values) throws MutationsRejectedException {
List<Mutation> mutations = new ArrayList<>();
for (String row : rows) {
Mutation mutation = new Mutation(row);
mutations.add(mutation);
for (String colF : colFs) {
for (String colQ : colQs) {
for (String colV : colVs) {
for (String value : values) {
mutation.put(colF, colQ, new ColumnVisibility(colV), value);
}
}
}
}
}
writer.addMutations(mutations);
writer.flush();
}
示例4: decrypt
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
/**
* Decrypt the given entry.
*
* @param entry
* entry to decrypt.
* @return Decrypted entry.
*/
public Entry<Key,Value> decrypt(Entry<Key,Value> entry) {
checkArgument(entry != null, "entry is null");
MutableEntry wrapped = new MutableEntry(entry);
MutableEntry result = new MutableEntry(entry);
ColumnVisibility visibility = entry.getKey().getColumnVisibilityParsed();
// Decrypt the various fields.
try {
for (FieldEncryptor fieldEncryptor : encryptors) {
fieldEncryptor.decrypt(wrapped, result, visibility);
}
} catch (IOException e) { // IO exceptions won't be thrown in practice as we are operating on in-memory streams.
throw new EncryptionException(e);
}
return result.toEntry();
}
示例5: getKey
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
/**
* Get a field encryption key for use in <strong>encrypting</strong> the field.
* <p>
* Any metadata needed to retrieve this key later should be written to the DataOuput object.
*
* @param visibility
* Visibility expression for the field.
* @param out
* DataOutput object to write metadata to.
* @return Field encryption key.
* @throws IOException
* Not actually thrown.
*/
private byte[] getKey(ColumnVisibility visibility, DataOutput out) throws IOException {
if (config.encryptUsingVisibility) {
byte[] key = new byte[config.keyLength];
if (visibility.getParseTree().getType() != NodeType.EMPTY) {
random.nextBytes(key);
writeVisibilityShare(key, visibility.getParseTree(), visibility.getExpression(), out);
}
return key;
} else {
KeyWithVersion keyData = keys.getKey(config.keyId, config.keyLength);
WritableUtils.writeVInt(out, keyData.version); // Write the version of the key being used as meta-data.
return keyData.key;
}
}
示例6: put
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Override
public void put(final String tableName, final String rowId, final Collection<PutMutation> columns) throws IOException {
BatchWriter writer = batchWriter(10000000L, tableName);
Mutation mutation = new Mutation(new Text(rowId));
for (final PutMutation column : columns) {
mutation.put(new Text(column.getColumnFamily()), new Text(column.getColumnQualifier()),
new ColumnVisibility(column.getColumnVisibilty()), new Value(column.getBuffer().getBytes()));
}
try {
writer.addMutation(mutation);
writer.close();
} catch (MutationsRejectedException e) {
e.printStackTrace();
}
}
示例7: buildMutation
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
public static Mutation buildMutation(ColumnVisibility cv, String path, boolean isDir, boolean isHidden, boolean canExec, long length, long lastmod,
String hash) {
if (path.equals("/"))
path = "";
Mutation m = new Mutation(QueryUtil.getRow(path));
Text colf = null;
if (isDir)
colf = QueryUtil.DIR_COLF;
else
colf = new Text(encoder.encode(Long.MAX_VALUE - lastmod));
m.put(colf, new Text(LENGTH_CQ), cv, new Value(Long.toString(length).getBytes()));
m.put(colf, new Text(HIDDEN_CQ), cv, new Value(Boolean.toString(isHidden).getBytes()));
m.put(colf, new Text(EXEC_CQ), cv, new Value(Boolean.toString(canExec).getBytes()));
m.put(colf, new Text(LASTMOD_CQ), cv, new Value(Long.toString(lastmod).getBytes()));
if (hash != null && hash.length() > 0)
m.put(colf, new Text(HASH_CQ), cv, new Value(hash.getBytes()));
return m;
}
示例8: test
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Test
public void test() throws Exception {
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
for (Entry<Key,Value> e : data) {
Key k = e.getKey();
Mutation m = new Mutation(k.getRow());
m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp(), e.getValue());
bw.addMutation(m);
}
bw.close();
assertEquals(0, CIFTester.main(tableName, CIFTester.TestMapper.class.getName()));
assertEquals(1, assertionErrors.get(tableName).size());
}
示例9: testErrorOnNextWithoutClose
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Test
public void testErrorOnNextWithoutClose() throws Exception {
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
for (Entry<Key,Value> e : data) {
Key k = e.getKey();
Mutation m = new Mutation(k.getRow());
m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()), k.getTimestamp(), e.getValue());
bw.addMutation(m);
}
bw.close();
assertEquals(1, CIFTester.main(tableName, CIFTester.TestNoClose.class.getName()));
assertEquals(1, assertionErrors.get(tableName).size());
// this should actually exist, in addition to the dummy entry
assertEquals(2, assertionErrors.get(tableName + "_map_ioexception").size());
}
示例10: setupInstance
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@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();
}
示例11: test
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Test
public void test() throws Exception {
Scanner scanner = conn.createScanner(tableName, new Authorizations());
scanner.fetchColumn(new Text("dir"), new Text("counts"));
assertFalse(scanner.iterator().hasNext());
ScannerOpts scanOpts = new ScannerOpts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
fc.run();
ArrayList<Pair<String,String>> expected = new ArrayList<>();
expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));
int i = 0;
for (Entry<Key,Value> e : scanner) {
assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
assertEquals(e.getValue().toString(), expected.get(i).getSecond());
i++;
}
assertEquals(i, expected.size());
}
示例12: setup
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Override
public void setup(Context context) {
Configuration conf = context.getConfiguration();
tablename = new Text(WikipediaConfiguration.getTableName(conf));
indexTableName = new Text(tablename + "Index");
reverseIndexTableName = new Text(tablename + "ReverseIndex");
metadataTableName = new Text(tablename + "Metadata");
WikipediaInputSplit wiSplit = (WikipediaInputSplit)context.getInputSplit();
myGroup = wiSplit.getPartition();
numGroups = WikipediaConfiguration.getNumGroups(conf);
FileSplit split = wiSplit.getFileSplit();
String fileName = split.getPath().getName();
Matcher matcher = languagePattern.matcher(fileName);
if (matcher.matches()) {
language = matcher.group(1).replace('_', '-').toLowerCase();
} else {
throw new RuntimeException("Unknown ingest language! " + fileName);
}
extractor = new ArticleExtractor();
numPartitions = WikipediaConfiguration.getNumPartitions(conf);
cv = new ColumnVisibility(cvPrefix + language);
}
示例13: canRead
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Override
public boolean canRead(Visibility visibility) {
Preconditions.checkNotNull(visibility, "visibility is required");
// this is just a shortcut so that we don't need to construct evaluators and visibility objects to check for an empty string.
if (visibility.getVisibilityString().length() == 0) {
return true;
}
VisibilityEvaluator visibilityEvaluator = new VisibilityEvaluator(new org.apache.accumulo.core.security.Authorizations(this.getAuthorizations()));
ColumnVisibility columnVisibility = new ColumnVisibility(visibility.getVisibilityString());
try {
return visibilityEvaluator.evaluate(columnVisibility);
} catch (VisibilityParseException e) {
throw new VertexiumException("could not evaluate visibility " + visibility.getVisibilityString(), e);
}
}
示例14: markVertexHidden
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Override
public void markVertexHidden(Vertex vertex, Visibility visibility, Authorizations authorizations) {
checkNotNull(vertex, "vertex cannot be null");
Span trace = Trace.start("softDeleteVertex");
trace.data("vertexId", vertex.getId());
try {
ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(visibility);
// Delete all edges that this vertex participates.
for (Edge edge : vertex.getEdges(Direction.BOTH, authorizations)) {
markEdgeHidden(edge, visibility, authorizations);
}
addMutations(VertexiumObjectType.VERTEX, getMarkHiddenRowMutation(vertex.getId(), columnVisibility));
getSearchIndex().markElementHidden(this, vertex, visibility, authorizations);
if (hasEventListeners()) {
queueEvent(new MarkHiddenVertexEvent(this, vertex));
}
} finally {
trace.stop();
}
}
示例15: markVertexVisible
import org.apache.accumulo.core.security.ColumnVisibility; //导入依赖的package包/类
@Override
public void markVertexVisible(Vertex vertex, Visibility visibility, Authorizations authorizations) {
checkNotNull(vertex, "vertex cannot be null");
Span trace = Trace.start("softDeleteVertex");
trace.data("vertexId", vertex.getId());
try {
ColumnVisibility columnVisibility = visibilityToAccumuloVisibility(visibility);
// Delete all edges that this vertex participates.
for (Edge edge : vertex.getEdges(Direction.BOTH, FetchHint.ALL_INCLUDING_HIDDEN, authorizations)) {
markEdgeVisible(edge, visibility, authorizations);
}
addMutations(VertexiumObjectType.VERTEX, getMarkVisibleRowMutation(vertex.getId(), columnVisibility));
getSearchIndex().markElementVisible(this, vertex, visibility, authorizations);
if (hasEventListeners()) {
queueEvent(new MarkVisibleVertexEvent(this, vertex));
}
} finally {
trace.stop();
}
}