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 java.io.IOException;
21 import java.util.Map;
22
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.Cell;
25 import org.apache.hadoop.hbase.CellUtil;
26 import org.apache.hadoop.hbase.filter.FilterBase;
27 import org.apache.hadoop.hbase.util.ByteRange;
28 import org.apache.hadoop.hbase.util.SimpleMutableByteRange;
29
30
31
32
33
34 @InterfaceAudience.Private
35 class VisibilityLabelFilter extends FilterBase {
36
37 private final VisibilityExpEvaluator expEvaluator;
38 private final Map<ByteRange, Integer> cfVsMaxVersions;
39 private final ByteRange curFamily;
40 private final ByteRange curQualifier;
41 private int curFamilyMaxVersions;
42 private int curQualMetVersions;
43
44 public VisibilityLabelFilter(VisibilityExpEvaluator expEvaluator,
45 Map<ByteRange, Integer> cfVsMaxVersions) {
46 this.expEvaluator = expEvaluator;
47 this.cfVsMaxVersions = cfVsMaxVersions;
48 this.curFamily = new SimpleMutableByteRange();
49 this.curQualifier = new SimpleMutableByteRange();
50 }
51
52 @Override
53 public boolean filterRowKey(Cell cell) throws IOException {
54
55 return false;
56 }
57
58 @Override
59 public ReturnCode filterKeyValue(Cell cell) throws IOException {
60 if (curFamily.getBytes() == null
61 || !(CellUtil.matchingFamily(cell, curFamily.getBytes(), curFamily.getOffset(),
62 curFamily.getLength()))) {
63 curFamily.set(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength());
64
65
66
67 curFamilyMaxVersions = cfVsMaxVersions.get(curFamily);
68
69 curQualifier.unset();
70 }
71 if (curQualifier.getBytes() == null
72 || !(CellUtil.matchingQualifier(cell, curQualifier.getBytes(), curQualifier.getOffset(),
73 curQualifier.getLength()))) {
74 curQualifier.set(cell.getQualifierArray(), cell.getQualifierOffset(),
75 cell.getQualifierLength());
76 curQualMetVersions = 0;
77 }
78 curQualMetVersions++;
79 if (curQualMetVersions > curFamilyMaxVersions) {
80 return ReturnCode.SKIP;
81 }
82
83 return this.expEvaluator.evaluate(cell) ? ReturnCode.INCLUDE : ReturnCode.SKIP;
84 }
85
86 @Override
87 public void reset() throws IOException {
88 this.curFamily.unset();
89 this.curQualifier.unset();
90 this.curFamilyMaxVersions = 0;
91 this.curQualMetVersions = 0;
92 }
93 }