HBASE-13332 Fix the usage of doAs/runAs in Visibility Controller tests (Srikanth Srungarapu)

This commit is contained in:
Andrew Purtell 2015-03-26 21:54:29 -07:00
parent a78effcdc6
commit b6b1e3b86e
11 changed files with 228 additions and 494 deletions

View File

@ -20,7 +20,6 @@ package org.apache.hadoop.hbase.security.visibility;
import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME; import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import java.io.IOException; import java.io.IOException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
@ -33,8 +32,6 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
@ -106,9 +103,8 @@ public class TestDefaultScanLabelGeneratorStack {
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = TEST_UTIL.createTable(tableName, CF); Table table = TEST_UTIL.createTable(tableName, CF)) {
try {
Put put = new Put(ROW_1); Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1); put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1);
put.setCellVisibility(new CellVisibility(SECRET)); put.setCellVisibility(new CellVisibility(SECRET));
@ -121,9 +117,6 @@ public class TestDefaultScanLabelGeneratorStack {
put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3); put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3);
table.put(put); table.put(put);
return null; return null;
} finally {
table.close();
connection.close();
} }
} }
}); });
@ -131,9 +124,8 @@ public class TestDefaultScanLabelGeneratorStack {
// Test that super user can see all the cells. // Test that super user can see all the cells.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
Scan s = new Scan(); Scan s = new Scan();
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(1); Result[] next = scanner.next(1);
@ -161,18 +153,14 @@ public class TestDefaultScanLabelGeneratorStack {
assertTrue(Bytes.equals(current.getValue(), value3)); assertTrue(Bytes.equals(current.getValue(), value3));
return null; return null;
} finally {
table.close();
connection.close();
} }
} }
}); });
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() { TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
// Test scan with no auth attribute // Test scan with no auth attribute
Scan s = new Scan(); Scan s = new Scan();
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
@ -239,9 +227,6 @@ public class TestDefaultScanLabelGeneratorStack {
assertFalse(cellScanner2.advance()); assertFalse(cellScanner2.advance());
return null; return null;
} finally {
table.close();
connection.close();
} }
} }
}); });

View File

@ -101,8 +101,8 @@ public class TestEnforcingScanLabelGenerator {
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Table table = TEST_UTIL.createTable(tableName, CF); try (Connection connection = ConnectionFactory.createConnection(conf);
try { Table table = TEST_UTIL.createTable(tableName, CF)) {
Put put = new Put(ROW_1); Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value); put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value);
put.setCellVisibility(new CellVisibility(SECRET)); put.setCellVisibility(new CellVisibility(SECRET));
@ -115,8 +115,6 @@ public class TestEnforcingScanLabelGenerator {
put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value); put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value);
table.put(put); table.put(put);
return null; return null;
} finally {
table.close();
} }
} }
}); });
@ -124,9 +122,8 @@ public class TestEnforcingScanLabelGenerator {
// Test that super user can see all the cells. // Test that super user can see all the cells.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
// Test that super user can see all the cells. // Test that super user can see all the cells.
Get get = new Get(ROW_1); Get get = new Get(ROW_1);
Result result = table.get(get); Result result = table.get(get);
@ -134,18 +131,14 @@ public class TestEnforcingScanLabelGenerator {
assertTrue("Missing authorization", result.containsColumn(CF, Q2)); assertTrue("Missing authorization", result.containsColumn(CF, Q2));
assertTrue("Missing authorization", result.containsColumn(CF, Q3)); assertTrue("Missing authorization", result.containsColumn(CF, Q3));
return null; return null;
} finally {
table.close();
connection.close();
} }
} }
}); });
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() { TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
// Test that we enforce the defined set // Test that we enforce the defined set
Get get = new Get(ROW_1); Get get = new Get(ROW_1);
get.setAuthorizations(new Authorizations(new String[] { SECRET, CONFIDENTIAL })); get.setAuthorizations(new Authorizations(new String[] { SECRET, CONFIDENTIAL }));
@ -160,9 +153,6 @@ public class TestEnforcingScanLabelGenerator {
assertTrue("Missing authorization", result.containsColumn(CF, Q2)); assertTrue("Missing authorization", result.containsColumn(CF, Q2));
assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3)); assertTrue("Inappropriate filtering", result.containsColumn(CF, Q3));
return null; return null;
} finally {
table.close();
connection.close();
} }
} }
}); });

View File

@ -36,13 +36,11 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Tag; import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin; import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
@ -139,25 +137,15 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
// Wait for the labels table to become available // Wait for the labels table to become available
TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
TEST_UTIL1.startMiniCluster(1); TEST_UTIL1.startMiniCluster(1);
HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin();
HTableDescriptor table = new HTableDescriptor(TABLE_NAME); HTableDescriptor table = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor desc = new HColumnDescriptor(fam); HColumnDescriptor desc = new HColumnDescriptor(fam);
desc.setScope(HConstants.REPLICATION_SCOPE_GLOBAL); desc.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
table.addFamily(desc); table.addFamily(desc);
try { try (HBaseAdmin hBaseAdmin = TEST_UTIL.getHBaseAdmin()) {
hBaseAdmin.createTable(table); hBaseAdmin.createTable(table);
} finally {
if (hBaseAdmin != null) {
hBaseAdmin.close();
}
} }
HBaseAdmin hBaseAdmin1 = TEST_UTIL1.getHBaseAdmin(); try (HBaseAdmin hBaseAdmin1 = TEST_UTIL1.getHBaseAdmin()){
try {
hBaseAdmin1.createTable(table); hBaseAdmin1.createTable(table);
} finally {
if (hBaseAdmin1 != null) {
hBaseAdmin1.close();
}
} }
addLabels(); addLabels();
setAuths(conf); setAuths(conf);
@ -174,13 +162,10 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
final boolean nullExpected, final String... auths) throws IOException, final boolean nullExpected, final String... auths) throws IOException,
InterruptedException { InterruptedException {
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
Table table2 = null;
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = null; try (Connection connection = ConnectionFactory.createConnection(conf1);
try { Table table2 = connection.getTable(TABLE_NAME)) {
connection = ConnectionFactory.createConnection(conf1);
table2 = connection.getTable(TABLE_NAME);
CellScanner cellScanner; CellScanner cellScanner;
Cell current; Cell current;
Get get = new Get(row); Get get = new Get(row);
@ -206,13 +191,6 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
doAssert(row, visString); doAssert(row, visString);
assertTrue(foundNonVisTag); assertTrue(foundNonVisTag);
return null; return null;
} finally {
if (table2 != null) {
table2.close();
}
if(connection != null){
connection.close();
}
} }
} }
}; };

View File

@ -114,9 +114,8 @@ public abstract class TestVisibilityLabels {
@Test @Test
public void testSimpleVisibilityLabels() throws Exception { public void testSimpleVisibilityLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL, try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CONFIDENTIAL,
PRIVATE + "|" + CONFIDENTIAL); PRIVATE + "|" + CONFIDENTIAL)) {
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE)); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
@ -133,21 +132,16 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception { public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, try (Table table = createTableAndWriteDataWithLabels(tableName,
SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT) + "&" SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT)
+ CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL, + "&" + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL,
CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET); CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) {
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT, s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT,
UNICODE_VIS_TAG)); UNICODE_VIS_TAG));
@ -169,20 +163,15 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row3, 0, row3.length)); current.getRowLength(), row3, 0, row3.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testAuthorizationsWithSpecialUnicodeCharacters() throws Exception { public void testAuthorizationsWithSpecialUnicodeCharacters() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, try (Table table = createTableAndWriteDataWithLabels(tableName,
CellVisibility.quote(UC1) + "|" + CellVisibility.quote(UC2), CellVisibility.quote(UC1), CellVisibility.quote(UC1) + "|" + CellVisibility.quote(UC2), CellVisibility.quote(UC1),
CellVisibility.quote(UNICODE_VIS_TAG)); CellVisibility.quote(UNICODE_VIS_TAG))) {
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(UC1, UC2, ACCENT, s.setAuthorizations(new Authorizations(UC1, UC2, ACCENT,
UNICODE_VIS_TAG)); UNICODE_VIS_TAG));
@ -204,21 +193,16 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row3, 0, row3.length)); current.getRowLength(), row3, 0, row3.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testVisibilityLabelsWithComplexLabels() throws Exception { public void testVisibilityLabelsWithComplexLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|"
+ ")" + "&" + "!" + TOPSECRET, "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET, "(" + PRIVATE + "&" + CONFIDENTIAL + "&"
+ PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL + SECRET + ")", "(" + PRIVATE + "&" + CONFIDENTIAL + "&" + SECRET + ")", "(" + PRIVATE
+ "&" + SECRET + ")"); + "&" + CONFIDENTIAL + "&" + SECRET + ")")) {
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(TOPSECRET, CONFIDENTIAL, PRIVATE, PUBLIC, SECRET)); s.setAuthorizations(new Authorizations(TOPSECRET, CONFIDENTIAL, PRIVATE, PUBLIC, SECRET));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
@ -239,28 +223,19 @@ public abstract class TestVisibilityLabels {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row4, 0, row4.length)); current.getRowLength(), row4, 0, row4.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testVisibilityLabelsThatDoesNotPassTheCriteria() throws Exception { public void testVisibilityLabelsThatDoesNotPassTheCriteria() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL try (Table table = createTableAndWriteDataWithLabels(tableName,
+ ")", PRIVATE); "(" + SECRET + "|" + CONFIDENTIAL + ")", PRIVATE)){
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(PUBLIC)); s.setAuthorizations(new Authorizations(PUBLIC));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3); Result[] next = scanner.next(3);
assertTrue(next.length == 0); assertTrue(next.length == 0);
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -277,27 +252,21 @@ public abstract class TestVisibilityLabels {
@Test @Test
public void testVisibilityLabelsInScanThatDoesNotMatchAnyDefinedLabels() throws Exception { public void testVisibilityLabelsInScanThatDoesNotMatchAnyDefinedLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL try ( Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|"
+ ")", PRIVATE); + CONFIDENTIAL + ")", PRIVATE)){
try {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations("SAMPLE")); s.setAuthorizations(new Authorizations("SAMPLE"));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3); Result[] next = scanner.next(3);
assertTrue(next.length == 0); assertTrue(next.length == 0);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testVisibilityLabelsWithGet() throws Exception { public void testVisibilityLabelsWithGet() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL + "&!" try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE); + "&!" + PRIVATE, SECRET + "&" + CONFIDENTIAL + "&" + PRIVATE)) {
try {
Get get = new Get(row1); Get get = new Get(row1);
get.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); get.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Result result = table.get(get); Result result = table.get(get);
@ -305,10 +274,6 @@ public abstract class TestVisibilityLabels {
Cell cell = result.getColumnLatestCell(fam, qual); Cell cell = result.getColumnLatestCell(fam, qual);
assertTrue(Bytes.equals(value, 0, value.length, cell.getValueArray(), cell.getValueOffset(), assertTrue(Bytes.equals(value, 0, value.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength())); cell.getValueLength()));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -378,26 +343,18 @@ public abstract class TestVisibilityLabels {
} }
TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000); TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
t.join(); t.join();
Table table = null; try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
try {
table = TEST_UTIL.getConnection().getTable(tableName);
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET)); s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3); Result[] next = scanner.next(3);
assertTrue(next.length == 1); assertTrue(next.length == 1);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test(timeout = 60 * 1000) @Test(timeout = 60 * 1000)
public void testVisibilityLabelsOnRSRestart() throws Exception { public void testVisibilityLabelsOnRSRestart() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ ")", PRIVATE);
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster() List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster()
.getRegionServerThreads(); .getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) { for (RegionServerThread rsThread : regionServerThreads) {
@ -406,16 +363,13 @@ public abstract class TestVisibilityLabels {
// Start one new RS // Start one new RS
RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer(); RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
waitForLabelsRegionAvailability(rs.getRegionServer()); waitForLabelsRegionAvailability(rs.getRegionServer());
try { try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ ")", PRIVATE);) {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET)); s.setAuthorizations(new Authorizations(SECRET));
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(3); Result[] next = scanner.next(3);
assertTrue(next.length == 1); assertTrue(next.length == 1);
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -444,17 +398,12 @@ public abstract class TestVisibilityLabels {
@Test @Test
public void testVisibilityLabelsInGetThatDoesNotMatchAnyDefinedLabels() throws Exception { public void testVisibilityLabelsInGetThatDoesNotMatchAnyDefinedLabels() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL try (Table table = createTableAndWriteDataWithLabels(tableName, "(" + SECRET + "|" + CONFIDENTIAL
+ ")", PRIVATE); + ")", PRIVATE)) {
try {
Get get = new Get(row1); Get get = new Get(row1);
get.setAuthorizations(new Authorizations("SAMPLE")); get.setAuthorizations(new Authorizations("SAMPLE"));
Result result = table.get(get); Result result = table.get(get);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -472,9 +421,7 @@ public abstract class TestVisibilityLabels {
} }
}; };
SUPERUSER.runAs(action); SUPERUSER.runAs(action);
Table ht = null; try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);) {
try {
ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
Scan scan = new Scan(); Scan scan = new Scan();
scan.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL)); scan.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
ResultScanner scanner = ht.getScanner(scan); ResultScanner scanner = ht.getScanner(scan);
@ -487,10 +434,6 @@ public abstract class TestVisibilityLabels {
assertTrue(auths.contains(SECRET)); assertTrue(auths.contains(SECRET));
assertTrue(auths.contains(CONFIDENTIAL)); assertTrue(auths.contains(CONFIDENTIAL));
assertEquals(2, auths.size()); assertEquals(2, auths.size());
} finally {
if (ht != null) {
ht.close();
}
} }
action = new PrivilegedExceptionAction<Void>() { action = new PrivilegedExceptionAction<Void>() {
@ -583,11 +526,8 @@ public abstract class TestVisibilityLabels {
"org.apache.hadoop.hbase.security.visibility.InvalidLabelException: " "org.apache.hadoop.hbase.security.visibility.InvalidLabelException: "
+ "Label 'public' is not set for the user testUser")); + "Label 'public' is not set for the user testUser"));
assertTrue(resultList.get(2).getException().getValue().isEmpty()); assertTrue(resultList.get(2).getException().getValue().isEmpty());
Connection connection = null; try (Connection connection = ConnectionFactory.createConnection(conf);
Table ht = null; Table ht = connection.getTable(LABELS_TABLE_NAME)) {
try {
connection = ConnectionFactory.createConnection(conf);
ht = connection.getTable(LABELS_TABLE_NAME);
ResultScanner scanner = ht.getScanner(new Scan()); ResultScanner scanner = ht.getScanner(new Scan());
Result result = null; Result result = null;
List<Result> results = new ArrayList<Result>(); List<Result> results = new ArrayList<Result>();
@ -597,13 +537,6 @@ public abstract class TestVisibilityLabels {
List<String> curAuths = extractAuths(user, results); List<String> curAuths = extractAuths(user, results);
assertTrue(curAuths.contains(PRIVATE)); assertTrue(curAuths.contains(PRIVATE));
assertEquals(1, curAuths.size()); assertEquals(1, curAuths.size());
} finally {
if (ht != null) {
ht.close();
}
if (connection != null){
connection.close();
}
} }
GetAuthsResponse authsResponse = null; GetAuthsResponse authsResponse = null;
@ -627,9 +560,7 @@ public abstract class TestVisibilityLabels {
@Test @Test
public void testLabelsWithCheckAndPut() throws Throwable { public void testLabelsWithCheckAndPut() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = TEST_UTIL.createTable(tableName, fam)) {
try {
table = TEST_UTIL.createTable(tableName, fam);
byte[] row1 = Bytes.toBytes("row1"); byte[] row1 = Bytes.toBytes("row1");
Put put = new Put(row1); Put put = new Put(row1);
put.add(fam, qual, HConstants.LATEST_TIMESTAMP, value); put.add(fam, qual, HConstants.LATEST_TIMESTAMP, value);
@ -649,19 +580,13 @@ public abstract class TestVisibilityLabels {
assertTrue(Bytes.equals(row2, result.getRow())); assertTrue(Bytes.equals(row2, result.getRow()));
result = scanner.next(); result = scanner.next();
assertNull(result); assertNull(result);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testLabelsWithIncrement() throws Throwable { public void testLabelsWithIncrement() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = TEST_UTIL.createTable(tableName, fam)) {
try {
table = TEST_UTIL.createTable(tableName, fam);
byte[] row1 = Bytes.toBytes("row1"); byte[] row1 = Bytes.toBytes("row1");
byte[] val = Bytes.toBytes(1L); byte[] val = Bytes.toBytes(1L);
Put put = new Put(row1); Put put = new Put(row1);
@ -681,19 +606,13 @@ public abstract class TestVisibilityLabels {
table.increment(increment); table.increment(increment);
result = table.get(get); result = table.get(get);
assertTrue(!result.isEmpty()); assertTrue(!result.isEmpty());
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testLabelsWithAppend() throws Throwable { public void testLabelsWithAppend() throws Throwable {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = TEST_UTIL.createTable(tableName, fam);) {
try {
table = TEST_UTIL.createTable(tableName, fam);
byte[] row1 = Bytes.toBytes("row1"); byte[] row1 = Bytes.toBytes("row1");
byte[] val = Bytes.toBytes("a"); byte[] val = Bytes.toBytes("a");
Put put = new Put(row1); Put put = new Put(row1);
@ -715,10 +634,6 @@ public abstract class TestVisibilityLabels {
table.append(append); table.append(append);
result = table.get(get); result = table.get(get);
assertTrue(!result.isEmpty()); assertTrue(!result.isEmpty());
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -779,9 +694,7 @@ public abstract class TestVisibilityLabels {
col.setMaxVersions(5); col.setMaxVersions(5);
desc.addFamily(col); desc.addFamily(col);
TEST_UTIL.getHBaseAdmin().createTable(desc); TEST_UTIL.getHBaseAdmin().createTable(desc);
Table table = null; try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
try {
table = TEST_UTIL.getConnection().getTable(tableName);
Put put = new Put(r1); Put put = new Put(r1);
put.add(fam, qual, 3l, v1); put.add(fam, qual, 3l, v1);
put.add(fam, qual2, 3l, v1); put.add(fam, qual2, 3l, v1);
@ -854,10 +767,6 @@ public abstract class TestVisibilityLabels {
assertNotNull(cell); assertNotNull(cell);
assertTrue(Bytes.equals(v2, 0, v2.length, cell.getValueArray(), cell.getValueOffset(), assertTrue(Bytes.equals(v2, 0, v2.length, cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength())); cell.getValueLength()));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -869,8 +778,7 @@ public abstract class TestVisibilityLabels {
HColumnDescriptor col = new HColumnDescriptor(fam); HColumnDescriptor col = new HColumnDescriptor(fam);
desc.addFamily(col); desc.addFamily(col);
TEST_UTIL.getHBaseAdmin().createTable(desc); TEST_UTIL.getHBaseAdmin().createTable(desc);
Table table = TEST_UTIL.getConnection().getTable(tableName); try (Table table = TEST_UTIL.getConnection().getTable(tableName)){
try {
Put p1 = new Put(row1); Put p1 = new Put(row1);
p1.add(fam, qual, value); p1.add(fam, qual, value);
p1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); p1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
@ -895,8 +803,6 @@ public abstract class TestVisibilityLabels {
result = table.get(get); result = table.get(get);
assertFalse(result.containsColumn(fam, qual)); assertFalse(result.containsColumn(fam, qual));
assertTrue(result.containsColumn(fam, qual2)); assertTrue(result.containsColumn(fam, qual2));
} finally {
table.close();
} }
} }

View File

@ -219,12 +219,11 @@ public class TestVisibilityLabelsReplication {
@Test @Test
public void testVisibilityReplication() throws Exception { public void testVisibilityReplication() throws Exception {
Table table = writeData(TABLE_NAME, "(" + SECRET + "&" + PUBLIC + ")" + "|(" + CONFIDENTIAL
+ ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|"
+ TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET,
CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);
int retry = 0; int retry = 0;
try { try (Table table = writeData(TABLE_NAME, "(" + SECRET + "&" + PUBLIC + ")" + "|(" + CONFIDENTIAL
+ ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|"
+ TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET,
CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);) {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, TOPSECRET, s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, TOPSECRET,
UNICODE_VIS_TAG)); UNICODE_VIS_TAG));
@ -252,9 +251,7 @@ public class TestVisibilityLabelsReplication {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row4, 0, row4.length)); current.getRowLength(), row4, 0, row4.length));
Table table2 = null; try (Table table2 = TEST_UTIL1.getConnection().getTable(TABLE_NAME);) {
try {
table2 = TEST_UTIL1.getConnection().getTable(TABLE_NAME);
s = new Scan(); s = new Scan();
// Ensure both rows are replicated // Ensure both rows are replicated
scanner = table2.getScanner(s); scanner = table2.getScanner(s);
@ -273,14 +270,6 @@ public class TestVisibilityLabelsReplication {
verifyGet(row3, expectedVisString[2], expected[2], false, PRIVATE, SECRET); verifyGet(row3, expectedVisString[2], expected[2], false, PRIVATE, SECRET);
verifyGet(row3, "", expected[3], true, TOPSECRET, SECRET); verifyGet(row3, "", expected[3], true, TOPSECRET, SECRET);
verifyGet(row4, expectedVisString[3], expected[4], false, UNICODE_VIS_TAG, SECRET); verifyGet(row4, expectedVisString[3], expected[4], false, UNICODE_VIS_TAG, SECRET);
} finally {
if (table2 != null) {
table2.close();
}
}
} finally {
if (table != null) {
table.close();
} }
} }
} }
@ -314,13 +303,9 @@ public class TestVisibilityLabelsReplication {
final boolean nullExpected, final String... auths) throws IOException, final boolean nullExpected, final String... auths) throws IOException,
InterruptedException { InterruptedException {
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
Table table2 = null;
Connection connection = null;
public Void run() throws Exception { public Void run() throws Exception {
try { try (Connection connection = ConnectionFactory.createConnection(conf1);
connection = ConnectionFactory.createConnection(conf1); Table table2 = connection.getTable(TABLE_NAME)) {
table2 = connection.getTable(TABLE_NAME);
CellScanner cellScanner; CellScanner cellScanner;
Cell current; Cell current;
Get get = new Get(row); Get get = new Get(row);
@ -354,13 +339,6 @@ public class TestVisibilityLabelsReplication {
doAssert(row, visString); doAssert(row, visString);
assertTrue(foundNonVisTag); assertTrue(foundNonVisTag);
return null; return null;
} finally {
if (table2 != null) {
table2.close();
}
if(connection != null) {
connection.close();
}
} }
} }
}; };

View File

@ -34,7 +34,6 @@ import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
@ -118,7 +117,7 @@ public class TestVisibilityLabelsWithACL {
String user = "user2"; String user = "user2";
VisibilityClient.setAuths(conf, auths, user); VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE); + "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName, SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName,
null, null, Permission.Action.READ); null, null, Permission.Action.READ);
@ -126,18 +125,14 @@ public class TestVisibilityLabelsWithACL {
public Void run() throws Exception { public Void run() throws Exception {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(table.getName()); Table t = connection.getTable(table.getName())) {
try {
ResultScanner scanner = t.getScanner(s); ResultScanner scanner = t.getScanner(s);
Result result = scanner.next(); Result result = scanner.next();
assertTrue(!result.isEmpty()); assertTrue(!result.isEmpty());
assertTrue(Bytes.equals(Bytes.toBytes("row2"), result.getRow())); assertTrue(Bytes.equals(Bytes.toBytes("row2"), result.getRow()));
result = scanner.next(); result = scanner.next();
assertNull(result); assertNull(result);
} finally {
t.close();
connection.close();
} }
return null; return null;
} }
@ -151,19 +146,17 @@ public class TestVisibilityLabelsWithACL {
String user = "admin"; String user = "admin";
VisibilityClient.setAuths(conf, auths, user); VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE); + "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Table t = TEST_UTIL.getConnection().getTable(table.getName()); try (Connection connection = ConnectionFactory.createConnection(conf);
try { Table t = connection.getTable(table.getName())) {
ResultScanner scanner = t.getScanner(s); ResultScanner scanner = t.getScanner(s);
Result[] result = scanner.next(5); Result[] result = scanner.next(5);
assertTrue(result.length == 2); assertTrue(result.length == 2);
} finally {
t.close();
} }
return null; return null;
} }
@ -177,18 +170,16 @@ public class TestVisibilityLabelsWithACL {
String user = "admin"; String user = "admin";
VisibilityClient.setAuths(conf, auths, user); VisibilityClient.setAuths(conf, auths, user);
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + CONFIDENTIAL
+ "&!" + PRIVATE, SECRET + "&!" + PRIVATE); + "&!" + PRIVATE, SECRET + "&!" + PRIVATE);
PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> scanAction = new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Get g = new Get(row1); Get g = new Get(row1);
g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Table t = TEST_UTIL.getConnection().getTable(table.getName()); try (Connection connection = ConnectionFactory.createConnection(conf);
try { Table t = connection.getTable(table.getName())) {
Result result = t.get(g); Result result = t.get(g);
assertTrue(!result.isEmpty()); assertTrue(!result.isEmpty());
} finally {
t.close();
} }
return null; return null;
} }
@ -203,7 +194,7 @@ public class TestVisibilityLabelsWithACL {
VisibilityClient.clearAuths(conf, auths, user); // Removing all auths if any. VisibilityClient.clearAuths(conf, auths, user); // Removing all auths if any.
VisibilityClient.setAuths(conf, auths, "user1"); VisibilityClient.setAuths(conf, auths, "user1");
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final HTable table = createTableAndWriteDataWithLabels(tableName, SECRET); final Table table = createTableAndWriteDataWithLabels(tableName, SECRET);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER1.getShortName(), tableName, SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER1.getShortName(), tableName,
null, null, Permission.Action.READ); null, null, Permission.Action.READ);
SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName, SecureTestUtil.grantOnTable(TEST_UTIL, NORMAL_USER2.getShortName(), tableName,
@ -212,14 +203,10 @@ public class TestVisibilityLabelsWithACL {
public Void run() throws Exception { public Void run() throws Exception {
Get g = new Get(row1); Get g = new Get(row1);
g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL)); g.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL));
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table t = connection.getTable(table.getName()); Table t = connection.getTable(table.getName())) {
try {
Result result = t.get(g); Result result = t.get(g);
assertTrue(result.isEmpty()); assertTrue(result.isEmpty());
} finally {
t.close();
connection.close();
} }
return null; return null;
} }
@ -315,9 +302,9 @@ public class TestVisibilityLabelsWithACL {
assertTrue(authsList.contains(PRIVATE)); assertTrue(authsList.contains(PRIVATE));
} }
private static HTable createTableAndWriteDataWithLabels(TableName tableName, String... labelExps) private static Table createTableAndWriteDataWithLabels(TableName tableName, String... labelExps)
throws Exception { throws Exception {
HTable table = null; Table table = null;
try { try {
table = TEST_UTIL.createTable(tableName, fam); table = TEST_UTIL.createTable(tableName, fam);
int i = 1; int i = 1;

View File

@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Scan;
@ -150,10 +149,10 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili
// Scan the visibility label // Scan the visibility label
Scan s = new Scan(); Scan s = new Scan();
s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL)); s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
int i = 0; int i = 0;
try { try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
ResultScanner scanner = ht.getScanner(s); ResultScanner scanner = ht.getScanner(s)) {
while (true) { while (true) {
Result next = scanner.next(); Result next = scanner.next();
if (next == null) { if (next == null) {
@ -161,10 +160,6 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili
} }
i++; i++;
} }
} finally {
if (ht != null) {
ht.close();
}
} }
// One label is the "system" label. // One label is the "system" label.
Assert.assertEquals("The count should be 13", 13, i); Assert.assertEquals("The count should be 13", 13, i);

View File

@ -26,6 +26,8 @@ import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
@ -112,13 +114,14 @@ public class TestVisibilityLabelsWithDeletes {
public void testVisibilityLabelsWithDeleteColumns() throws Throwable { public void testVisibilityLabelsWithDeleteColumns() throws Throwable {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "&" + TOPSECRET,
SECRET); try (Table table = createTableAndWriteDataWithLabels(tableName,
try { SECRET + "&" + TOPSECRET, SECRET)) {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "&" + SECRET)); d.setCellVisibility(new CellVisibility(TOPSECRET + "&" + SECRET));
d.addColumns(fam, qual); d.addColumns(fam, qual);
@ -143,10 +146,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -154,13 +153,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testVisibilityLabelsWithDeleteFamily() throws Exception { public void testVisibilityLabelsWithDeleteFamily() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
final Table table = createTableAndWriteDataWithLabels(tableName, SECRET, CONFIDENTIAL + "|" try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET,
+ TOPSECRET); CONFIDENTIAL + "|" + TOPSECRET);) {
try {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row2); Delete d = new Delete(row2);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.addFamily(fam); d.addFamily(fam);
@ -184,10 +183,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current(); Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row1, 0, row1.length)); current.getRowLength(), row1, 0, row1.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -196,13 +191,13 @@ public class TestVisibilityLabelsWithDeletes {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
long[] ts = new long[] { 123l, 125l }; long[] ts = new long[] { 123l, 125l };
final Table table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|" try (Table table = createTableAndWriteDataWithLabels(tableName, ts,
+ TOPSECRET, SECRET); CONFIDENTIAL + "|" + TOPSECRET, SECRET)) {
try {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.deleteFamilyVersion(fam, 123l); d.deleteFamilyVersion(fam, 123l);
@ -226,10 +221,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current(); Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -238,13 +229,13 @@ public class TestVisibilityLabelsWithDeletes {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
long[] ts = new long[] { 123l, 125l }; long[] ts = new long[] { 123l, 125l };
final Table table = createTableAndWriteDataWithLabels(tableName, ts, CONFIDENTIAL + "|" try (Table table = createTableAndWriteDataWithLabels(tableName, ts,
+ TOPSECRET, SECRET); CONFIDENTIAL + "|" + TOPSECRET, SECRET);) {
try {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(TOPSECRET + "|" + CONFIDENTIAL));
d.addColumn(fam, qual, 123l); d.addColumn(fam, qual, 123l);
@ -268,10 +259,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current(); Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -284,7 +271,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")")); SECRET + "&" + TOPSECRET+")"));
@ -339,7 +327,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d1 = new Delete(row1); Delete d1 = new Delete(row1);
d1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d1.addColumns(fam, qual); d1.addColumns(fam, qual);
@ -388,7 +377,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumns(fam, qual); d.addColumns(fam, qual);
@ -440,7 +430,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d1 = new Delete(row1); Delete d1 = new Delete(row1);
d1.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d1.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d1.addFamily(fam); d1.addFamily(fam);
@ -499,7 +490,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam); d.addFamily(fam);
@ -524,7 +516,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET)); d.setCellVisibility(new CellVisibility(SECRET));
d.addFamily(fam); d.addFamily(fam);
@ -573,7 +566,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumns(fam, qual); d.addColumns(fam, qual);
@ -598,7 +592,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET)); d.setCellVisibility(new CellVisibility(SECRET));
d.addColumns(fam, qual); d.addColumns(fam, qual);
@ -646,7 +641,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET)); d.setCellVisibility(new CellVisibility(SECRET));
d.addColumns(fam, qual, 126l); d.addColumns(fam, qual, 126l);
@ -655,7 +651,8 @@ public class TestVisibilityLabelsWithDeletes {
throw new IOException(t); throw new IOException(t);
} }
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumn(fam, qual, 123l); d.addColumn(fam, qual, 123l);
@ -707,14 +704,16 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addColumn(fam, qual, 123l); d.addColumn(fam, qual, 123l);
table.delete(d); table.delete(d);
} }
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET)); d.setCellVisibility(new CellVisibility(SECRET));
d.addColumn(fam, qual, 123l); d.addColumn(fam, qual, 123l);
@ -759,7 +758,8 @@ public class TestVisibilityLabelsWithDeletes {
+ SECRET + "&" + TOPSECRET + ")")); + SECRET + "&" + TOPSECRET + ")"));
d3.addFamily(fam); d3.addFamily(fam);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2, d3)); table.delete(createList(d1, d2, d3));
} catch (Throwable t) { } catch (Throwable t) {
throw new IOException(t); throw new IOException(t);
@ -803,7 +803,8 @@ public class TestVisibilityLabelsWithDeletes {
Delete d2 = new Delete(row1); Delete d2 = new Delete(row1);
d2.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d2.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d2.addColumns(fam, qual); d2.addColumns(fam, qual);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2)); table.delete(createList(d1, d2));
} catch (Throwable t) { } catch (Throwable t) {
throw new IOException(t); throw new IOException(t);
@ -992,7 +993,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")")); SECRET + "&" + TOPSECRET+")"));
@ -1056,7 +1058,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual); d.addColumn(fam, qual);
@ -1109,9 +1112,7 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception { public void testDeleteColumnWithLatestTimeStampWhenNoVersionMatches() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPuts(tableName)) {
try {
table = doPuts(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
Put put = new Put(Bytes.toBytes("row1")); Put put = new Put(Bytes.toBytes("row1"));
put.add(fam, qual, 128l, value); put.add(fam, qual, 128l, value);
@ -1120,7 +1121,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET )); d.setCellVisibility(new CellVisibility(SECRET ));
d.addColumn(fam, qual); d.addColumn(fam, qual);
@ -1190,10 +1192,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row1, 0, row1.length)); current.getRowLength(), row1, 0, row1.length));
assertEquals(current.getTimestamp(), 129l); assertEquals(current.getTimestamp(), 129l);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
@ -1201,14 +1199,13 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception { throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPuts(tableName)) {
try {
table = doPuts(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual); d.addColumn(fam, qual);
@ -1261,10 +1258,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1272,14 +1265,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception { public void testDeleteFamilyLatestTimeStampWithMulipleVersions() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPuts(tableName)) {
try {
table = doPuts(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addFamily(fam); d.addFamily(fam);
@ -1315,10 +1307,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1326,9 +1314,7 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception { public void testDeleteColumnswithMultipleColumnsWithMultipleVersions() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPutsWithDiffCols(tableName)) {
try {
table = doPutsWithDiffCols(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
@ -1336,7 +1322,8 @@ public class TestVisibilityLabelsWithDeletes {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumns(fam, qual, 125l); d.addColumns(fam, qual, 125l);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
table.delete(d); table.delete(d);
} catch (Throwable t) { } catch (Throwable t) {
throw new IOException(t); throw new IOException(t);
@ -1378,10 +1365,6 @@ public class TestVisibilityLabelsWithDeletes {
assertEquals(current.getTimestamp(), 127l); assertEquals(current.getTimestamp(), 127l);
assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(), assertTrue(Bytes.equals(current.getQualifierArray(), current.getQualifierOffset(),
current.getQualifierLength(), qual2, 0, qual2.length)); current.getQualifierLength(), qual2, 0, qual2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1415,7 +1398,8 @@ public class TestVisibilityLabelsWithDeletes {
d2.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d2.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d2.addColumns(fam, qual1, 125l); d2.addColumns(fam, qual1, 125l);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2)); table.delete(createList(d1, d2));
} catch (Throwable t) { } catch (Throwable t) {
throw new IOException(t); throw new IOException(t);
@ -1462,7 +1446,8 @@ public class TestVisibilityLabelsWithDeletes {
d2.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d2.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d2.addColumns(fam, qual1, 126l); d2.addColumns(fam, qual1, 126l);
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
table.delete(createList(d1, d2)); table.delete(createList(d1, d2));
} catch (Throwable t) { } catch (Throwable t) {
throw new IOException(t); throw new IOException(t);
@ -1483,14 +1468,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception { public void testDeleteFamilyWithoutCellVisibilityWithMulipleVersions() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPutsWithoutVisibility(tableName)) {
try {
table = doPutsWithoutVisibility(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addFamily(fam); d.addFamily(fam);
table.delete(d); table.delete(d);
@ -1515,10 +1499,6 @@ public class TestVisibilityLabelsWithDeletes {
Cell current = cellScanner.current(); Cell current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1527,13 +1507,12 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception { throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPutsWithoutVisibility(tableName)) {
try {
table = doPutsWithoutVisibility(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addFamily(fam); d.addFamily(fam);
@ -1583,10 +1562,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1594,14 +1569,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilySpecificTimeStampWithMulipleVersions() throws Exception { public void testDeleteFamilySpecificTimeStampWithMulipleVersions() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPuts(tableName)) {
try {
table = doPuts(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ SECRET + "&" + TOPSECRET + ")")); + SECRET + "&" + TOPSECRET + ")"));
@ -1643,10 +1617,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1654,14 +1624,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testScanAfterCompaction() throws Exception { public void testScanAfterCompaction() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = doPuts(tableName)) {
try {
table = doPuts(tableName);
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" + d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" +
SECRET + "&" + TOPSECRET+")")); SECRET + "&" + TOPSECRET+")"));
@ -1701,10 +1670,6 @@ public class TestVisibilityLabelsWithDeletes {
current = cellScanner.current(); current = cellScanner.current();
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1712,14 +1677,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception { public void testDeleteFamilySpecificTimeStampWithMulipleVersionsDoneTwice() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; // Do not flush here.
try { try (Table table = doPuts(tableName)) {
// Do not flush here.
table = doPuts(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -1770,7 +1734,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -1806,10 +1771,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l); assertEquals(current.getTimestamp(), 127l);
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -1833,7 +1794,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.deleteFamilyVersion(fam, 123l); d.deleteFamilyVersion(fam, 123l);
@ -1884,7 +1846,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET + ")")); + TOPSECRET + "&" + SECRET + ")"));
@ -1929,7 +1892,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam); d.addFamily(fam);
@ -1981,7 +1945,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET + ")")); + TOPSECRET + "&" + SECRET + ")"));
@ -2027,7 +1992,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(CONFIDENTIAL)); d.setCellVisibility(new CellVisibility(CONFIDENTIAL));
d.addFamily(fam); d.addFamily(fam);
@ -2067,7 +2033,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 125l); d.addColumn(fam, qual, 125l);
@ -2117,7 +2084,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2165,14 +2133,13 @@ public class TestVisibilityLabelsWithDeletes {
public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice1() throws Exception { public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice1() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; // Do not flush here.
try { try (Table table = doPuts(tableName)) {
// Do not flush here.
table = doPuts(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")" + d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")" +
"|(" + TOPSECRET + "&" + SECRET + ")")); "|(" + TOPSECRET + "&" + SECRET + ")"));
@ -2223,7 +2190,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 127l); d.addColumn(fam, qual, 127l);
@ -2268,24 +2236,20 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l); assertEquals(current.getTimestamp(), 127l);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice2() throws Exception { public void testDeleteColumnSpecificTimeStampWithMulipleVersionsDoneTwice2() throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null;
try { // Do not flush here.
// Do not flush here. try (Table table = doPuts(tableName)) {
table = doPuts(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2341,7 +2305,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2387,10 +2352,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l); assertEquals(current.getTimestamp(), 127l);
} finally {
if (table != null) {
table.close();
}
} }
} }
@Test @Test
@ -2398,14 +2359,13 @@ public class TestVisibilityLabelsWithDeletes {
throws Exception { throws Exception {
setAuths(); setAuths();
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; // Do not flush here.
try { try (Table table = doPuts(tableName)) {
// Do not flush here.
table = doPuts(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET)); d.setCellVisibility(new CellVisibility(SECRET + "&" + TOPSECRET));
d.addColumn(fam, qual, 125l); d.addColumn(fam, qual, 125l);
@ -2455,7 +2415,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2491,10 +2452,6 @@ public class TestVisibilityLabelsWithDeletes {
assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(),
current.getRowLength(), row2, 0, row2.length)); current.getRowLength(), row2, 0, row2.length));
assertEquals(current.getTimestamp(), 127l); assertEquals(current.getTimestamp(), 127l);
} finally {
if (table != null) {
table.close();
}
} }
} }
@ -2523,7 +2480,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|(" d.setCellVisibility(new CellVisibility("(" + PRIVATE + "&" + CONFIDENTIAL + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2574,7 +2532,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|(" d.setCellVisibility(new CellVisibility("(" + CONFIDENTIAL + "&" + PRIVATE + ")|("
+ TOPSECRET + "&" + SECRET+")")); + TOPSECRET + "&" + SECRET+")"));
@ -2626,7 +2585,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addColumn(fam, qual, 125l); d.addColumn(fam, qual, 125l);
table.delete(d); table.delete(d);
@ -2649,7 +2609,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addColumns(fam, qual, 125l); d.addColumns(fam, qual, 125l);
table.delete(d); table.delete(d);
@ -2673,7 +2634,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addFamily(fam, 125l); d.addFamily(fam, 125l);
table.delete(d); table.delete(d);
@ -2697,7 +2659,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addFamily(fam); d.addFamily(fam);
table.delete(d); table.delete(d);
@ -2721,7 +2684,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addColumns(fam, qual); d.addColumns(fam, qual);
table.delete(d); table.delete(d);
@ -2745,7 +2709,8 @@ public class TestVisibilityLabelsWithDeletes {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.deleteFamilyVersion(fam, 126l); d.deleteFamilyVersion(fam, 126l);
table.delete(d); table.delete(d);
@ -2825,7 +2790,8 @@ public class TestVisibilityLabelsWithDeletes {
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName)) {
Delete d = new Delete(row1); Delete d = new Delete(row1);
d.addColumn(fam, qual, 124l); d.addColumn(fam, qual, 124l);
d.setCellVisibility(new CellVisibility(PRIVATE )); d.setCellVisibility(new CellVisibility(PRIVATE ));

View File

@ -82,9 +82,7 @@ public class TestVisibilityLabelsWithSLGStack {
@Test @Test
public void testWithSAGStack() throws Exception { public void testWithSAGStack() throws Exception {
TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = TEST_UTIL.createTable(tableName, CF)) {
try {
table = TEST_UTIL.createTable(tableName, CF);
Put put = new Put(ROW_1); Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value); put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value);
put.setCellVisibility(new CellVisibility(SECRET)); put.setCellVisibility(new CellVisibility(SECRET));
@ -101,10 +99,6 @@ public class TestVisibilityLabelsWithSLGStack {
Result next = scanner.next(); Result next = scanner.next();
assertNotNull(next.getColumnLatestCell(CF, Q1)); assertNotNull(next.getColumnLatestCell(CF, Q1));
assertNull(next.getColumnLatestCell(CF, Q2)); assertNull(next.getColumnLatestCell(CF, Q2));
} finally {
if (table != null) {
table.close();
}
} }
} }

View File

@ -112,12 +112,13 @@ public class TestVisibilityLablesWithGroups {
@Test @Test
public void testGroupAuths() throws Exception { public void testGroupAuths() throws Exception {
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
// create the table
// create the table and put data. TEST_UTIL.createTable(tableName, CF);
// put the data.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Table table = TEST_UTIL.createTable(tableName, CF); try (Connection connection = ConnectionFactory.createConnection(conf);
try { Table table = connection.getTable(tableName)) {
Put put = new Put(ROW_1); Put put = new Put(ROW_1);
put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1); put.add(CF, Q1, HConstants.LATEST_TIMESTAMP, value1);
put.setCellVisibility(new CellVisibility(SECRET)); put.setCellVisibility(new CellVisibility(SECRET));
@ -129,8 +130,6 @@ public class TestVisibilityLablesWithGroups {
put = new Put(ROW_1); put = new Put(ROW_1);
put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3); put.add(CF, Q3, HConstants.LATEST_TIMESTAMP, value3);
table.put(put); table.put(put);
} finally {
table.close();
} }
return null; return null;
} }
@ -139,9 +138,8 @@ public class TestVisibilityLablesWithGroups {
// 'admin' user is part of 'supergroup', thus can see all the cells. // 'admin' user is part of 'supergroup', thus can see all the cells.
SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() { SUPERUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
Scan s = new Scan(); Scan s = new Scan();
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
Result[] next = scanner.next(1); Result[] next = scanner.next(1);
@ -167,10 +165,6 @@ public class TestVisibilityLablesWithGroups {
current.getRowLength(), ROW_1, 0, ROW_1.length)); current.getRowLength(), ROW_1, 0, ROW_1.length));
assertTrue(Bytes.equals(current.getQualifier(), Q3)); assertTrue(Bytes.equals(current.getQualifier(), Q3));
assertTrue(Bytes.equals(current.getValue(), value3)); assertTrue(Bytes.equals(current.getValue(), value3));
} finally {
table.close();
connection.close();
} }
return null; return null;
} }
@ -198,9 +192,8 @@ public class TestVisibilityLablesWithGroups {
// Test that test user can see what 'testgroup' has been authorized to. // Test that test user can see what 'testgroup' has been authorized to.
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() { TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
// Test scan with no auth attribute // Test scan with no auth attribute
Scan s = new Scan(); Scan s = new Scan();
ResultScanner scanner = table.getScanner(s); ResultScanner scanner = table.getScanner(s);
@ -265,9 +258,6 @@ public class TestVisibilityLablesWithGroups {
assertTrue(Bytes.equals(current2.getValue(), value3)); assertTrue(Bytes.equals(current2.getValue(), value3));
assertFalse(cellScanner2.advance()); assertFalse(cellScanner2.advance());
} finally {
table.close();
connection.close();
} }
return null; return null;
} }
@ -307,9 +297,8 @@ public class TestVisibilityLablesWithGroups {
// Test that test user cannot see the cells with the labels anymore. // Test that test user cannot see the cells with the labels anymore.
TESTUSER.runAs(new PrivilegedExceptionAction<Void>() { TESTUSER.runAs(new PrivilegedExceptionAction<Void>() {
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(tableName); Table table = connection.getTable(tableName)) {
try {
Scan s1 = new Scan(); Scan s1 = new Scan();
// test user is not entitled to 'CONFIDENTIAL' anymore since we dropped // test user is not entitled to 'CONFIDENTIAL' anymore since we dropped
// testgroup's label. test user has no auth labels now. // testgroup's label. test user has no auth labels now.
@ -329,9 +318,6 @@ public class TestVisibilityLablesWithGroups {
assertTrue(Bytes.equals(current1.getValue(), value3)); assertTrue(Bytes.equals(current1.getValue(), value3));
assertFalse(cellScanner1.advance()); assertFalse(cellScanner1.advance());
} finally {
table.close();
connection.close();
} }
return null; return null;
} }

View File

@ -33,7 +33,6 @@ import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Append;
import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse;
@ -129,15 +128,13 @@ public class TestVisibilityWithCheckAuths {
HTableDescriptor desc = new HTableDescriptor(tableName); HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(colDesc); desc.addFamily(colDesc);
hBaseAdmin.createTable(desc); hBaseAdmin.createTable(desc);
Table table = null;
try { try {
TEST_UTIL.getHBaseAdmin().flush(tableName); TEST_UTIL.getHBaseAdmin().flush(tableName);
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
Table table = null; try (Connection connection = ConnectionFactory.createConnection(conf);
try { Table table = connection.getTable(tableName)) {
table = TEST_UTIL.getConnection().getTable(tableName);
Put p = new Put(row1); Put p = new Put(row1);
p.setCellVisibility(new CellVisibility(PUBLIC + "&" + TOPSECRET)); p.setCellVisibility(new CellVisibility(PUBLIC + "&" + TOPSECRET));
p.add(fam, qual, 125l, value); p.add(fam, qual, 125l, value);
@ -145,8 +142,6 @@ public class TestVisibilityWithCheckAuths {
Assert.fail("Testcase should fail with AccesDeniedException"); Assert.fail("Testcase should fail with AccesDeniedException");
} catch (Throwable t) { } catch (Throwable t) {
assertTrue(t.getMessage().contains("AccessDeniedException")); assertTrue(t.getMessage().contains("AccessDeniedException"));
} finally {
table.close();
} }
return null; return null;
} }
@ -173,25 +168,18 @@ public class TestVisibilityWithCheckAuths {
}; };
SUPERUSER.runAs(action); SUPERUSER.runAs(action);
final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); final TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
Table table = null; try (Table table = TEST_UTIL.createTable(tableName, fam)) {
try {
table = TEST_UTIL.createTable(tableName, fam);
final byte[] row1 = Bytes.toBytes("row1"); final byte[] row1 = Bytes.toBytes("row1");
final byte[] val = Bytes.toBytes("a"); final byte[] val = Bytes.toBytes("a");
PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() { PrivilegedExceptionAction<Void> actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = null; Table table = connection.getTable(tableName)) {
try {
table = connection.getTable(tableName);
Put put = new Put(row1); Put put = new Put(row1);
put.add(fam, qual, HConstants.LATEST_TIMESTAMP, val); put.add(fam, qual, HConstants.LATEST_TIMESTAMP, val);
put.setCellVisibility(new CellVisibility(TOPSECRET)); put.setCellVisibility(new CellVisibility(TOPSECRET));
table.put(put); table.put(put);
} finally {
table.close();
connection.close();
} }
return null; return null;
} }
@ -200,16 +188,11 @@ public class TestVisibilityWithCheckAuths {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
Connection connection = ConnectionFactory.createConnection(conf); try (Connection connection = ConnectionFactory.createConnection(conf);
Table table = null; Table table = connection.getTable(tableName)) {
try {
table = TEST_UTIL.getConnection().getTable(tableName);
Append append = new Append(row1); Append append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("b")); append.add(fam, qual, Bytes.toBytes("b"));
table.append(append); table.append(append);
} finally {
table.close();
connection.close();
} }
return null; return null;
} }
@ -218,11 +201,8 @@ public class TestVisibilityWithCheckAuths {
actiona = new PrivilegedExceptionAction<Void>() { actiona = new PrivilegedExceptionAction<Void>() {
@Override @Override
public Void run() throws Exception { public Void run() throws Exception {
Table table = null; try (Connection connection = ConnectionFactory.createConnection(conf);
Connection connection = null; Table table = connection.getTable(tableName)) {
try {
connection = ConnectionFactory.createConnection(conf);
table = connection.getTable(tableName);
Append append = new Append(row1); Append append = new Append(row1);
append.add(fam, qual, Bytes.toBytes("c")); append.add(fam, qual, Bytes.toBytes("c"));
append.setCellVisibility(new CellVisibility(PUBLIC)); append.setCellVisibility(new CellVisibility(PUBLIC));
@ -230,22 +210,11 @@ public class TestVisibilityWithCheckAuths {
Assert.fail("Testcase should fail with AccesDeniedException"); Assert.fail("Testcase should fail with AccesDeniedException");
} catch (Throwable t) { } catch (Throwable t) {
assertTrue(t.getMessage().contains("AccessDeniedException")); assertTrue(t.getMessage().contains("AccessDeniedException"));
} finally {
if (table != null) {
table.close();
}
if (connection != null) {
connection.close();
}
} }
return null; return null;
} }
}; };
USER.runAs(actiona); USER.runAs(actiona);
} finally {
if (table != null) {
table.close();
}
} }
} }
} }