1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.security.visibility;
19
20 import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_FAMILY;
21 import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.NavigableMap;
26
27 import org.apache.hadoop.hbase.HConstants;
28 import org.apache.hadoop.hbase.testclassification.MediumTests;
29 import org.apache.hadoop.hbase.TableName;
30 import org.apache.hadoop.hbase.client.Result;
31 import org.apache.hadoop.hbase.security.User;
32 import org.apache.hadoop.hbase.util.Bytes;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37 @Category(MediumTests.class)
38 public class TestVisibilityLabelsWithCustomVisLabService extends TestVisibilityLabels {
39
40 @BeforeClass
41 public static void setupBeforeClass() throws Exception {
42
43 conf = TEST_UTIL.getConfiguration();
44 conf.setBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false);
45 VisibilityTestUtil.enableVisiblityLabels(conf);
46 conf.setClass(VisibilityUtils.VISIBILITY_LABEL_GENERATOR_CLASS, SimpleScanLabelGenerator.class,
47 ScanLabelGenerator.class);
48 conf.setClass(VisibilityLabelServiceManager.VISIBILITY_LABEL_SERVICE_CLASS,
49 ExpAsStringVisibilityLabelServiceImpl.class, VisibilityLabelService.class);
50 conf.set("hbase.superuser", "admin");
51 TEST_UTIL.startMiniCluster(2);
52 SUPERUSER = User.createUserForTesting(conf, "admin", new String[] { "supergroup" });
53
54
55 TEST_UTIL.waitTableEnabled(LABELS_TABLE_NAME.getName(), 50000);
56 addLabels();
57 }
58
59
60 @Test
61 public void testVisibilityLabelsInPutsThatDoesNotMatchAnyDefinedLabels() throws Exception {
62 TableName tableName = TableName.valueOf(TEST_NAME.getMethodName());
63
64 createTableAndWriteDataWithLabels(tableName, "SAMPLE_LABEL", "TEST");
65 }
66
67 protected List<String> extractAuths(String user, List<Result> results) {
68 List<String> auths = new ArrayList<String>();
69 for (Result result : results) {
70 if (Bytes.equals(result.getRow(), Bytes.toBytes(user))) {
71 NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(LABELS_TABLE_FAMILY);
72 for (byte[] q : familyMap.keySet()) {
73 auths.add(Bytes.toString(q, 0, q.length));
74 }
75 }
76 }
77 return auths;
78 }
79 }