@Override public Get beforeGet(long rowkeyBase, Get get) { get.setAuthorizations(new Authorizations( authorizations[(int) (rowkeyBase % authorizations.length)])); return get; } }
@Test public void testVisibilityLabelsInGetThatDoesNotMatchAnyDefinedLabels() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)) { Get get = new Get(row1); get.setAuthorizations(new Authorizations("SAMPLE")); Result result = table.get(get); assertTrue(result.isEmpty()); } }
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(!result.isEmpty()); } return null; } };
@Override public Void run() throws Exception { Get g = new Get(row1); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { Result result = t.get(g); assertTrue(result.isEmpty()); } return null; } };
@Test public void testDeleteWithNoVisibilitiesForPutsAndDeletes() throws Exception { TableName tableName = createTable(5); Put p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); Table table = TEST_UTIL.getConnection().getTable(tableName); table.put(p); p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual1, value); table.put(p); p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual, value); table.put(p); p = new Put(Bytes.toBytes("row2")); p.addColumn(fam, qual1, value); table.put(p); Delete d = new Delete(Bytes.toBytes("row1")); table.delete(d); Get g = new Get(Bytes.toBytes("row1")); g.readAllVersions(); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); Result result = table.get(g); assertEquals(0, result.rawCells().length); p = new Put(Bytes.toBytes("row1")); p.addColumn(fam, qual, value); table.put(p); result = table.get(g); assertEquals(1, result.rawCells().length); }
@Test public void testVisibilityLabelsWithGet() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL + "&!" + PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE)) { Get get = new Get(row1); get.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); Result result = table.get(get); assertTrue(!result.isEmpty()); Cell cell = result.getColumnLatestCell(fam, qual); assertTrue(Bytes.equals(value, 0, value.length, cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); } }
@Test public void testMutateRow() throws Exception { final byte[] qual2 = Bytes.toBytes("qual2"); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); HTableDescriptor desc = new HTableDescriptor(tableName); HColumnDescriptor col = new HColumnDescriptor(fam); desc.addFamily(col); TEST_UTIL.getAdmin().createTable(desc); try (Table table = TEST_UTIL.getConnection().getTable(tableName)){ Put p1 = new Put(row1); p1.addColumn(fam, qual, value); p1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); Put p2 = new Put(row1); p2.addColumn(fam, qual2, value); p2.setCellVisibility(new CellVisibility(SECRET)); RowMutations rm = new RowMutations(row1); rm.add(p1); rm.add(p2); table.mutateRow(rm); Get get = new Get(row1); get.setAuthorizations(new Authorizations(CONFIDENTIAL)); Result result = table.get(get); assertTrue(result.containsColumn(fam, qual)); assertFalse(result.containsColumn(fam, qual2)); get.setAuthorizations(new Authorizations(SECRET)); result = table.get(get); assertFalse(result.containsColumn(fam, qual)); assertTrue(result.containsColumn(fam, qual2)); } }
Result r = table.get(new Get(row1)); assertEquals(0, r.size()); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(1, r.size()); assertEquals(Bytes.toString(value1), Bytes.toString(CellUtil.cloneValue(r.rawCells()[0]))); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(1, r.size()); assertEquals(Bytes.toString(value1), Bytes.toString(CellUtil.cloneValue(r.rawCells()[0]))); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(0, r.size());
assertEquals(1, r.size()); assertEquals(Bytes.toString(value1), Bytes.toString(CellUtil.cloneValue(r.rawCells()[0]))); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(1, r.size()); assertEquals(Bytes.toString(value1), Bytes.toString(CellUtil.cloneValue(r.rawCells()[0]))); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(0, r.size()); r = table.get(new Get(row1).setAuthorizations(new Authorizations(PRIVATE))); assertEquals(0, r.size());
@Test public void testLabelsWithAppend() throws Throwable { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = TEST_UTIL.createTable(tableName, fam)) { byte[] row1 = Bytes.toBytes("row1"); byte[] val = Bytes.toBytes("a"); Put put = new Put(row1); put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val); put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL)); table.put(put); Get get = new Get(row1); get.setAuthorizations(new Authorizations(SECRET)); Result result = table.get(get); assertTrue(result.isEmpty()); Append append = new Append(row1); append.addColumn(fam, qual, Bytes.toBytes("b")); table.append(append); result = table.get(get); assertTrue(result.isEmpty()); append = new Append(row1); append.addColumn(fam, qual, Bytes.toBytes("c")); append.setCellVisibility(new CellVisibility(SECRET)); table.append(append); result = table.get(get); assertTrue(!result.isEmpty()); } }
@Test public void testLabelsWithIncrement() throws Throwable { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = TEST_UTIL.createTable(tableName, fam)) { byte[] row1 = Bytes.toBytes("row1"); byte[] val = Bytes.toBytes(1L); Put put = new Put(row1); put.addColumn(fam, qual, HConstants.LATEST_TIMESTAMP, val); put.setCellVisibility(new CellVisibility(SECRET + " & " + CONFIDENTIAL)); table.put(put); Get get = new Get(row1); get.setAuthorizations(new Authorizations(SECRET)); Result result = table.get(get); assertTrue(result.isEmpty()); table.incrementColumnValue(row1, fam, qual, 2L); result = table.get(get); assertTrue(result.isEmpty()); Increment increment = new Increment(row1); increment.addColumn(fam, qual, 2L); increment.setCellVisibility(new CellVisibility(SECRET)); table.increment(increment); result = table.get(get); assertTrue(!result.isEmpty()); } }
Cell current; Get get = new Get(row); get.setAuthorizations(new Authorizations(auths)); Result result = table2.get(get); cellScanner = result.cellScanner();
Cell current; Get get = new Get(row); get.setAuthorizations(new Authorizations(auths)); Result result = table2.get(get); cellScanner = result.cellScanner();
g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); Result result = table.get(g); assertEquals(0, result.rawCells().length); g.setAuthorizations(new Authorizations(SECRET, PRIVATE)); result = table.get(g); assertEquals(0, result.rawCells().length);
@Override public Void run() throws Exception { try (Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(tableName)) { // Test that we enforce the defined set Get get = new Get(ROW_1); get.setAuthorizations(new Authorizations(new String[] { SECRET, CONFIDENTIAL })); Result result = table.get(get); assertFalse("Inappropriate authorization", result.containsColumn(CF, Q1)); assertTrue("Missing authorization", result.containsColumn(CF, Q2)); assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3)); // Test that we also enforce the defined set for the user if no auths are provided get = new Get(ROW_1); result = table.get(get); assertFalse("Inappropriate authorization", result.containsColumn(CF, Q1)); assertTrue("Missing authorization", result.containsColumn(CF, Q2)); assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3)); return null; } } });
.setReplicaId(3) .setACL("test_user", new Permission(Permission.Action.READ)) .setAuthorizations(new Authorizations("test_label")) .setPriority(3);
out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
Get get = new Get(ROW); get.setFilter(null); get.setAuthorizations(new Authorizations("foo")); get.setACL("u", new Permission(Permission.Action.READ)); get.setConsistency(Consistency.TIMELINE);
.setReplicaId(3) .setACL("test_user", new Permission(Permission.Action.READ)) .setAuthorizations(new Authorizations("test_label")) .setPriority(3);
Get get = new Get(ROW); get.setFilter(null); get.setAuthorizations(new Authorizations("foo")); get.setACL("u", new Permission(Permission.Action.READ)); get.setConsistency(Consistency.TIMELINE);