Search in sources :

Example 1 with ByteArraySet

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));
    }
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) ByteArraySet(org.apache.accumulo.core.util.ByteArraySet) Test(org.junit.Test)

Example 2 with ByteArraySet

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());
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) TreeSet(java.util.TreeSet) ByteArraySet(org.apache.accumulo.core.util.ByteArraySet) Value(org.apache.accumulo.core.data.Value) Text(org.apache.hadoop.io.Text) Key(org.apache.accumulo.core.data.Key)

Aggregations

Authorizations (org.apache.accumulo.core.security.Authorizations)2 ByteArraySet (org.apache.accumulo.core.util.ByteArraySet)2 TreeSet (java.util.TreeSet)1 Scanner (org.apache.accumulo.core.client.Scanner)1 Key (org.apache.accumulo.core.data.Key)1 Value (org.apache.accumulo.core.data.Value)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1