本文整理汇总了Java中org.apache.accumulo.core.data.Key类的典型用法代码示例。如果您正苦于以下问题:Java Key类的具体用法?Java Key怎么用?Java Key使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Key类属于org.apache.accumulo.core.data包,在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasData
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
/**
* Matches the set of entries against the given set of values. The full combinatorial of values passed in is expected in the output set.
*
* @param rows
* Rows to check for.
* @param colFs
* Column families to check for.
* @param colQs
* Column qualifiers to check for.
* @param colVs
* Column visibilities to check for.
* @param values
* Values to check for.
* @return Hamcrest matcher.
*/
@Factory
@SuppressWarnings("unchecked")
public static Matcher<Iterable<Entry<Key,Value>>> hasData(Collection<String> rows, Collection<String> colFs, Collection<String> colQs,
Collection<String> colVs, Collection<String> values) {
int size = rows.size() * colFs.size() * colQs.size() * colVs.size() * values.size();
ArrayList<Matcher<? super Iterable<Entry<Key,Value>>>> matchers = new ArrayList<>(size + 1);
matchers.add(IsIterableWithSize.iterableWithSize(size));
for (String row : rows) {
for (String colF : colFs) {
for (String colQ : colQs) {
for (String colV : colVs) {
for (String value : values) {
matchers.add(hasItems(equalToRow(row, colF, colQ, colV, value)));
}
}
}
}
}
return allOf(matchers);
}
示例2: getRandomData
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
/**
* Get random data.
*
* @param count
* Number of entries to create.
* @param rowSize
* Size (in bytes) of the row.
* @param colFSize
* Size (in bytes) of the column family.
* @param colQSize
* Size (in bytes) of the column qualifier.
* @param colVisValue
* Value to use for colVis.
* @param valueSize
* Size (in bytes) of the value.
* @return Random data.
*/
static SortedMap<Key,Value> getRandomData(int count, int rowSize, int colFSize, int colQSize, byte[] colVisValue, int valueSize) {
SortedMap<Key,Value> data = new TreeMap<>();
for (int i = 0; i < count; i++) {
byte[] row = new byte[rowSize];
byte[] colF = new byte[colFSize];
byte[] colQ = new byte[colQSize];
byte[] colVis = colVisValue.clone();
byte[] value = new byte[valueSize];
random.nextBytes(row);
random.nextBytes(colF);
random.nextBytes(colQ);
random.nextBytes(value);
long timestamp = random.nextLong();
data.put(new Key(row, colF, colQ, colVis, timestamp, false, false), new Value(value));
}
return data;
}
示例3: runTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
/**
* Run a specific test for a given version and configuration.
*
* @param dataScanner
* Scanner for the unsigned data.
* @param signedScanner
* Scanner for the signed data.
* @param verifier
* Verifier for the signed data.
* @param signatureConfig
* Configuration for the verifier.
*/
private void runTest(Scanner dataScanner, Scanner signedScanner, EntrySigner verifier, SignatureConfig signatureConfig) {
Iterator<Entry<Key,Value>> iterator = signedScanner.iterator();
for (Entry<Key,Value> entry : dataScanner) {
assertThat("should have more entries", iterator.hasNext(), is(true));
Entry<Key,Value> signedEntry = iterator.next();
Entry<Key,Value> verifiedEntry;
if (signatureConfig.isSignatureInSeparateTable()) {
assertThat("keys should match", signedEntry.getKey(), equalTo(entry.getKey()));
assertThat("values should not match", signedEntry.getValue().get(), not(equalTo(entry.getValue().get())));
verifiedEntry = verifier.verify(entry, signedEntry);
} else {
verifiedEntry = verifier.verify(signedEntry);
}
assertThat("entries should match", verifiedEntry, Matchers.equalTo(entry));
}
assertThat("should have no more entries", iterator.hasNext(), is(false));
}
示例4: check
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
public void check(SignatureConfig config) throws Exception {
Scanner scanner = AccumuloInstance.getConnector(USER).createScanner(UNSIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations);
Scanner signedScanner;
if (!config.isSignatureInSeparateTable()) {
signedScanner = new SignedScanner(AccumuloInstance.getConnector(USER), SIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations, config,
AccumuloInstance.getUser(USER).signatureKeys.get(config.getAlgorithm()));
} else {
signedScanner = new SignedScanner(AccumuloInstance.getConnector(USER), UNSIGNED_TEST_TABLE, AccumuloInstance.getUser(USER).authorizations, config,
AccumuloInstance.getUser(USER).signatureKeys.get(config.getAlgorithm()));
}
Iterator<Entry<Key,Value>> iterator = signedScanner.iterator();
for (Entry<Key,Value> entry : scanner) {
assertThat("should have an entry that matches", iterator.hasNext(), is(true));
assertThat("entries match", iterator.next(), equalTo(entry));
}
assertThat("should have no more entries", iterator.hasNext(), is(false));
}
示例5: setRangesTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
private void setRangesTest(String configuration) throws Exception {
List<String> rows = Arrays.asList("row1", "row2");
List<String> colFs = Arrays.asList("colF1", "colF2");
List<String> colQs = Arrays.asList("colQ1", "colQ2");
List<String> colVs = Collections.singletonList("");
List<String> values = Collections.singletonList("value");
clearTable();
EncryptedBatchWriter writer = getEncryptedWriter(CHARLIE, configuration);
writeData(writer, rows, colFs, colQs, colVs, values);
writer.close();
EncryptedBatchScanner scanner = getEncryptedScanner(CHARLIE, configuration);
scanner.setRanges(Collections.singletonList(new Range(new Key("row1", "colF1", "colQ1"), true, new Key("row1", "colF1", "colQ2")
.followingKey(PartialKey.ROW_COLFAM_COLQUAL), false)));
assertThat("contains the filtered data", scanner, hasData(Collections.singletonList("row1"), Collections.singletonList("colF1"), colQs, colVs, values));
}
示例6: decrypt
import org.apache.accumulo.core.data.Key; //导入依赖的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();
}
示例7: getDeleteKeys
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
/**
* Given a key for deletion, generate the appropriate server side keys to delete.
*
* @param key
* Key to delete.
* @return Set of encrypted keys to delete.
*/
public Collection<Key> getDeleteKeys(Key key) {
checkArgument(canBeDeleteServerSide(), "canBeDeleteServerSide is false");
checkArgument(key != null, "key is null");
MutableEntry searchKey = new MutableEntry(key);
// Pair up the correct answers.
Collection<byte[]> rowValues = getDeleteValues(searchKey, EntryField.ROW);
Collection<byte[]> colFValues = getDeleteValues(searchKey, EntryField.COLUMN_FAMILY);
Collection<byte[]> colQValues = getDeleteValues(searchKey, EntryField.COLUMN_QUALIFIER);
return rowValues
.stream()
.flatMap(
r -> colFValues.stream().flatMap(
cf -> colQValues.stream().map(cq -> new Key(r, cf, cq, key.getColumnVisibilityData().getBackingArray(), key.getTimestamp(), true, true))))
.collect(Collectors.toList());
}
示例8: signVerifyInValueTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void signVerifyInValueTest() throws Exception {
MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
"secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));
MutableEntry signed;
Entry<Key,Value> verified;
EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));
signed = new MutableEntry(signer.sign(entry.toEntry(), true));
assertThat("row should not have changed", signed.row, is(entry.row));
assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
assertThat("delete should not have changed", signed.delete, is(entry.delete));
assertThat("value should have changed", signed.value, is(not(entry.value)));
verified = verifier.verify(signed.toEntry());
assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
示例9: signVerifyInSeparateTableTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void signVerifyInSeparateTableTest() throws Exception {
MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
"secret".getBytes(VISIBILITY_CHARSET), (long) 5, false), new Value(new byte[] {6})));
MutableEntry signed;
Entry<Key,Value> verified;
EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));
signed = new MutableEntry(signer.sign(entry.toEntry(), true));
assertThat("row should not have changed", signed.row, is(entry.row));
assertThat("colFamily should not have changed", signed.colF, is(entry.colF));
assertThat("colQualifier should not have changed", signed.colQ, is(entry.colQ));
assertThat("colVisibility should not have changed", signed.colVis, is(entry.colVis));
assertThat("timestamp should not have changed", signed.timestamp, is(entry.timestamp));
assertThat("delete should not have changed", signed.delete, is(entry.delete));
assertThat("value should have changed", signed.value, is(not(entry.value)));
verified = verifier.verify(entry.toEntry(), signed.toEntry());
assertThat("original and verified records are the same.", verified, Matchers.equalTo(entry.toEntry()));
}
示例10: hasNoTimestampTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void hasNoTimestampTest() throws Exception {
MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
"secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
MutableEntry signed;
EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));
try {
signed = new MutableEntry(signer.sign(entry.toEntry(), true));
signed.timestamp = 1000L;
verifier.verify(signed.toEntry());
fail("changing the timestamp should cause the signature to fail");
} catch (SignatureException e) { /* expected */}
signed = new MutableEntry(signer.sign(entry.toEntry(), false));
signed.timestamp = 1000L;
verifier.verify(signed.toEntry());
}
示例11: badSignatureTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void badSignatureTest() throws Exception {
MutableEntry entry = new MutableEntry(new SimpleImmutableEntry<>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
"secret".getBytes(VISIBILITY_CHARSET), (long) 0, false), new Value(new byte[] {6})));
Entry<Key,Value> signed;
// Sign to value;
EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));
signed = signer.sign(entry.toEntry(), true);
entry.value = new byte[] {7};
try {
verifier.verify(entry.toEntry(), signed);
fail("bad signature should thrown an exception");
} catch (SignatureException e) { /* expected */}
}
示例12: internalUnprocessedTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void internalUnprocessedTest() throws Exception {
EntrySigner signer = getSigner("config1.ini", aliceKeyContainers.get(ValueSigner.RSA_PSS));
EntrySigner verifier = getSigner("config1.ini", bobKeyContainers.get(ValueSigner.RSA_PSS));
List<Entry<Key,Value>> entries = new ArrayList<>();
byte[] row = new byte[] {1};
Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
false), new Value(new byte[] {4}));
entries.add(signer.sign(entry, true));
SignedInlineScannerIterator iterator = new SignedInlineScannerIterator(entries.iterator(), verifier);
iterator.next();
assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
示例13: externalUnprocessedTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void externalUnprocessedTest() throws Exception {
EntrySigner signer = getSigner("config3.ini", aliceKeyContainers.get(ValueSigner.ECDSA));
EntrySigner verifier = getSigner("config3.ini", bobKeyContainers.get(ValueSigner.ECDSA));
List<Entry<Key,Value>> entries = new ArrayList<>();
List<Entry<Key,Value>> signedEntries = new ArrayList<>();
byte[] row = new byte[] {1};
Entry<Key,Value> entry = new SimpleImmutableEntry<>(new Key(row, new byte[] {2}, new byte[] {3}, "secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false,
false), new Value(new byte[] {4}));
entries.add(entry);
signedEntries.add(signer.sign(entry, true));
SignedExternalScannerIterator iterator = new SignedExternalScannerIterator(entries.iterator(), signedEntries.iterator(), verifier, true);
iterator.next();
assertThat("unprocessed item is correct", iterator.unprocessed(), Matchers.equalTo(entries.get(0)));
}
示例14: getDeleteKeysTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void getDeleteKeysTest() throws Exception {
EntryEncryptor encryptor = getEncryptor("deterministic.ini");
MutableEntry searchKey = new MutableEntry(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3}, "secret".getBytes(VISIBILITY_CHARSET), (long) 5, false));
Collection<Key> keys = encryptor.getDeleteKeys(searchKey.toKey());
assertThat("has correct number of delete keys", keys, hasSize(2));
for (Key deleteKey : keys) {
MutableEntry key = new MutableEntry(deleteKey);
assertThat("row is encrypted", key.row, not(equalTo(searchKey.row)));
assertThat("colF is zeroes", key.colF, equalTo(EMPTY));
assertThat("colQ is plaintext", key.colQ, equalTo(searchKey.colQ));
assertThat("colQ is plaintext", key.colVis, equalTo(searchKey.colVis));
assertThat("colQ is plaintext", key.timestamp, equalTo(searchKey.timestamp));
assertThat("delete is true", key.delete, is(true));
}
}
示例15: hasNextTest
import org.apache.accumulo.core.data.Key; //导入依赖的package包/类
@Test
public void hasNextTest() throws Exception {
EntryEncryptor encryptor = new EntryEncryptor(getConfig("config.ini"), KEYS);
List<Entry<Key,Value>> entries = new ArrayList<>();
Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(new Key(new byte[] {1}, new byte[] {2}, new byte[] {3},
"secret".getBytes(Utils.VISIBILITY_CHARSET), 0, false, false), new Value(new byte[] {4}));
entries.add(encryptor.encrypt(entry));
EncryptedScannerIterator iterator = new EncryptedScannerIterator(entries.iterator(), encryptor, Collections.singletonList(new Range()),
new TreeSet<Column>());
assertThat("has next item", iterator.hasNext(), is(true));
assertThat("has next item", iterator.hasNext(), is(true));
iterator.next();
assertThat("does not have a next item", iterator.hasNext(), is(false));
}