@Test public void testSetAuthorizations() { Scan scan = new Scan(); try { scan.setAuthorizations(new Authorizations("\u002b|\u0029")); scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a")); scan.setAuthorizations(new Authorizations("A|B")); scan.setAuthorizations(new Authorizations("A&B")); scan.setAuthorizations(new Authorizations("!B")); scan.setAuthorizations(new Authorizations("A", "(A)")); scan.setAuthorizations(new Authorizations("A", "{A")); scan.setAuthorizations(new Authorizations(" ")); scan.setAuthorizations(new Authorizations(":B")); scan.setAuthorizations(new Authorizations("-B")); scan.setAuthorizations(new Authorizations(".B")); scan.setAuthorizations(new Authorizations("/B")); } catch (IllegalArgumentException e) { fail("should not throw exception"); } }
return; Scan scan = new Scan(); scan.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL)); scan.addColumn(LABELS_TABLE_FAMILY, LABEL_QUALIFIER); ResultScanner scanner = null; try { scanner = labelsTable.getScanner(scan); Result next = null; while ((next = scanner.next()) != null) { byte[] row = next.getRow(); byte[] value = next.getValue(LABELS_TABLE_FAMILY, LABEL_QUALIFIER);
@Test public void testVisibilityLabelsInScanThatDoesNotMatchAnyDefinedLabels() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try ( Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)){ Scan s = new Scan(); s.setAuthorizations(new Authorizations("SAMPLE")); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 0); } }
@VisibleForTesting static Scan getScanFromCommandLine(Configuration conf, String[] args) throws IOException { Scan s = new Scan(); labels = Arrays.asList(conf.getStrings(EXPORT_VISIBILITY_LABELS)); if (!labels.isEmpty()) { s.setAuthorizations(new Authorizations(labels));
protected ResultScanner getResults(final Table table, final byte[] startRow, final byte[] endRow, final Collection<Column> columns, List<String> authorizations) throws IOException { final Scan scan = new Scan(); scan.setStartRow(startRow); scan.setStopRow(endRow); if (authorizations != null && authorizations.size() > 0) { scan.setAuthorizations(new Authorizations(authorizations)); } if (columns != null && columns.size() > 0) { for (Column col : columns) { if (col.getQualifier() == null) { scan.addFamily(col.getFamily()); } else { scan.addColumn(col.getFamily(), col.getQualifier()); } } } return table.getScanner(scan); }
private Job doVerify(Configuration conf, HTableDescriptor htd, String... auths) throws IOException, InterruptedException, ClassNotFoundException { Path outputDir = getTestDir(TEST_NAME, "verify-output"); Job job = new Job(conf); job.setJarByClass(this.getClass()); job.setJobName(TEST_NAME + " Verification for " + htd.getTableName()); setJobScannerConf(job); Scan scan = new Scan(); scan.setAuthorizations(new Authorizations(auths)); TableMapReduceUtil.initTableMapperJob(htd.getTableName().getNameAsString(), scan, VerifyMapper.class, NullWritable.class, NullWritable.class, job); TableMapReduceUtil.addDependencyJarsForClasses(job.getConfiguration(), AbstractHBaseTool.class); int scannerCaching = conf.getInt("verify.scannercaching", SCANNER_CACHING); TableMapReduceUtil.setScannerCaching(job, scannerCaching); job.setNumReduceTasks(0); FileOutputFormat.setOutputPath(job, outputDir); assertTrue(job.waitForCompletion(true)); return job; }
protected ResultScanner getResults(final Table table, final byte[] startRow, final byte[] endRow, final Collection<Column> columns, List<String> authorizations) throws IOException { final Scan scan = new Scan(); scan.setStartRow(startRow); scan.setStopRow(endRow); if (authorizations != null && authorizations.size() > 0) { scan.setAuthorizations(new Authorizations(authorizations)); } if (columns != null && columns.size() > 0) { for (Column col : columns) { if (col.getQualifier() == null) { scan.addFamily(col.getFamily()); } else { scan.addColumn(col.getFamily(), col.getQualifier()); } } } return table.getScanner(scan); }
private int doVerify(Path outputDir, int numReducers) throws IOException, InterruptedException, ClassNotFoundException { job = new Job(getConf()); job.setJobName("Link Verifier"); job.setNumReduceTasks(numReducers); job.setJarByClass(getClass()); setJobScannerConf(job); Scan scan = new Scan(); scan.addColumn(FAMILY_NAME, COLUMN_PREV); scan.setCaching(10000); scan.setCacheBlocks(false); String[] split = labels.split(COMMA); scan.setAuthorizations(new Authorizations(split[this.labelIndex * 2], split[(this.labelIndex * 2) + 1])); TableMapReduceUtil.initTableMapperJob(tableName.getName(), scan, VerifyMapper.class, BytesWritable.class, BytesWritable.class, job); TableMapReduceUtil.addDependencyJars(job.getConfiguration(), AbstractHBaseTool.class); job.getConfiguration().setBoolean("mapreduce.map.speculative", false); job.setReducerClass(VerifyReducer.class); job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); boolean success = job.waitForCompletion(true); return success ? 0 : 1; }
@Test public void testVisibilityLabelsThatDoesNotPassTheCriteria() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)){ Scan s = new Scan(); s.setAuthorizations(new Authorizations(PUBLIC)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 0); } }
job.getConfiguration().set("LABELS", labels); job.setJarByClass(getClass()); scan = new Scan(); scan.setCacheBlocks(false); scan.setRaw(true); scan.setAuthorizations(new Authorizations(split[this.labelIndex * 2], split[(this.labelIndex * 2) + 1])); if (delete) {
@Override public Void run() throws Exception { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { ResultScanner scanner = t.getScanner(s); Result[] result = scanner.next(5); assertTrue(result.length == 2); } return null; } };
public static Scan scanFromThrift(TScan in) throws IOException { Scan out = new Scan(); out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels()));
protected ResultScanner getResults(final Table table, final Collection<Column> columns, final Filter filter, final long minTime, List<String> authorizations) throws IOException { // Create a new scan. We will set the min timerange as the latest timestamp that // we have seen so far. The minimum timestamp is inclusive, so we will get duplicates. // We will record any cells that have the latest timestamp, so that when we scan again, // we know to throw away those duplicates. final Scan scan = new Scan(); scan.setTimeRange(minTime, Long.MAX_VALUE); if (authorizations != null && authorizations.size() > 0) { scan.setAuthorizations(new Authorizations(authorizations)); } if (filter != null) { scan.setFilter(filter); } if (columns != null) { for (Column col : columns) { if (col.getQualifier() == null) { scan.addFamily(col.getFamily()); } else { scan.addColumn(col.getFamily(), col.getQualifier()); } } } return table.getScanner(scan); }
@Test public void testSetAuthorizations() { Scan scan = new Scan(); try { scan.setAuthorizations(new Authorizations("\u002b|\u0029")); scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a")); scan.setAuthorizations(new Authorizations("A|B")); scan.setAuthorizations(new Authorizations("A&B")); scan.setAuthorizations(new Authorizations("!B")); scan.setAuthorizations(new Authorizations("A", "(A)")); scan.setAuthorizations(new Authorizations("A", "{A")); scan.setAuthorizations(new Authorizations(" ")); scan.setAuthorizations(new Authorizations(":B")); scan.setAuthorizations(new Authorizations("-B")); scan.setAuthorizations(new Authorizations(".B")); scan.setAuthorizations(new Authorizations("/B")); } catch (IllegalArgumentException e) { fail("should not throw exception"); } }
protected ResultScanner getResults(final Table table, final Collection<Column> columns, final Filter filter, final long minTime, List<String> authorizations) throws IOException { // Create a new scan. We will set the min timerange as the latest timestamp that // we have seen so far. The minimum timestamp is inclusive, so we will get duplicates. // We will record any cells that have the latest timestamp, so that when we scan again, // we know to throw away those duplicates. final Scan scan = new Scan(); scan.setTimeRange(minTime, Long.MAX_VALUE); if (authorizations != null && authorizations.size() > 0) { scan.setAuthorizations(new Authorizations(authorizations)); } if (filter != null) { scan.setFilter(filter); } if (columns != null) { for (Column col : columns) { if (col.getQualifier() == null) { scan.addFamily(col.getFamily()); } else { scan.addColumn(col.getFamily(), col.getQualifier()); } } } return table.getScanner(scan); }
@Test public void testScanCopyConstructor() throws Exception { Scan scan = new Scan(); .setAsyncPrefetch(false) .setAttribute("test_key", Bytes.toBytes("test_value")) .setAuthorizations(new Authorizations("test_label")) .setBatch(10) .setCacheBlocks(false) Scan scanCopy = new Scan(scan);
SECRET + "|" + CONFIDENTIAL, PRIVATE + "|" + CONFIDENTIAL)) { Scan s = new Scan(); s.setAuthorizations(new Authorizations()); try (ResultScanner scanner = t.getScanner(s)) { Result[] next = scanner.next(10); assertEquals(4, next.length); s = new Scan(); s.setAuthorizations(new Authorizations(SECRET)); try (ResultScanner scanner = t.getScanner(s)) { Result[] next = scanner.next(10); assertEquals(4, next.length); s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (ResultScanner scanner = t.getScanner(s)) { Result[] next = scanner.next(10); assertEquals(4, next.length); s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE)); try (ResultScanner scanner = t.getScanner(s)) { Result[] next = scanner.next(10);
admin.scan(tableName, new Scan()); // co VisibilityLabelExample-08-Scans Scan the table twice, as different users. The admin can see more than the application due to the visibility expressions. app1.scan(tableName, new Scan()); new Scan().setAuthorizations(new Authorizations("low"))); // co VisibilityLabelExample-09-SetAuthScan1 Lower the visibility for the scans. Result will include subset of cells. admin.scan(tableName, new Scan().setAuthorizations(new Authorizations("high"))); // co VisibilityLabelExample-10-SetAuthScan2 Raise the visibility for the scans. Result will include no labelled cell as the user is not allowed to see those.
@Override public Void run() throws Exception { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); try (Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(table.getName())) { ResultScanner scanner = t.getScanner(s); Result result = scanner.next(); assertTrue(!result.isEmpty()); assertTrue(Bytes.equals(Bytes.toBytes("row2"), result.getRow())); result = scanner.next(); assertNull(result); } return null; } };
@Test public void testScanCopyConstructor() throws Exception { Scan scan = new Scan(); .setAsyncPrefetch(false) .setAttribute("test_key", Bytes.toBytes("test_value")) .setAuthorizations(new Authorizations("test_label")) .setBatch(10) .setCacheBlocks(false) Scan scanCopy = new Scan(scan);