use of org.apache.accumulo.core.util.ByteArraySet in project accumulo by apache.
the class ZKAuthenticatorTest method testAuthorizationConversion.
@Test
public void testAuthorizationConversion() {
ByteArraySet auths = new ByteArraySet();
for (int i = 0; i < 300; i += 3) auths.add(Integer.toString(i).getBytes());
Authorizations converted = new Authorizations(auths);
byte[] test = ZKSecurityTool.convertAuthorizations(converted);
Authorizations test2 = ZKSecurityTool.convertAuthorizations(test);
assertEquals(auths.size(), test2.size());
for (byte[] s : auths) {
assertTrue(test2.contains(s));
}
}
use of org.apache.accumulo.core.util.ByteArraySet in project accumulo-examples by apache.
the class ReadWriteExample method execute.
private void execute(Opts opts, ScannerOpts scanOpts) throws Exception {
conn = opts.getConnector();
// add the authorizations to the user
Authorizations userAuthorizations = conn.securityOperations().getUserAuthorizations(opts.getPrincipal());
ByteArraySet auths = new ByteArraySet(userAuthorizations.getAuthorizations());
auths.addAll(opts.auths.getAuthorizations());
if (!auths.isEmpty())
conn.securityOperations().changeUserAuthorizations(opts.getPrincipal(), new Authorizations(auths));
// create table
if (opts.createtable) {
SortedSet<Text> partitionKeys = new TreeSet<>();
for (int i = Byte.MIN_VALUE; i < Byte.MAX_VALUE; i++) partitionKeys.add(new Text(new byte[] { (byte) i }));
conn.tableOperations().create(opts.getTableName());
conn.tableOperations().addSplits(opts.getTableName(), partitionKeys);
}
// send mutations
createEntries(opts);
// read entries
if (opts.readEntries) {
// Note that the user needs to have the authorizations for the specified scan authorizations
// by an administrator first
Scanner scanner = conn.createScanner(opts.getTableName(), opts.auths);
scanner.setBatchSize(scanOpts.scanBatchSize);
for (Entry<Key, Value> entry : scanner) System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString());
}
// delete table
if (opts.deletetable)
conn.tableOperations().delete(opts.getTableName());
}
Aggregations