Search in sources :

Example 6 with NonLeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode in project hbase by apache.

the class TestExpressionExpander method testPositiveCases.

@Test
public void testPositiveCases() throws Exception {
    ExpressionExpander expander = new ExpressionExpander();
    // (!a) -> (!a)
    NonLeafExpressionNode exp1 = new NonLeafExpressionNode(Operator.NOT, new LeafExpressionNode("a"));
    ExpressionNode result = expander.expand(exp1);
    assertTrue(result instanceof NonLeafExpressionNode);
    NonLeafExpressionNode nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.NOT, nlResult.getOperator());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    // (a | b) -> (a | b)
    NonLeafExpressionNode exp2 = new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b"));
    result = expander.expand(exp2);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    // (a & b) -> (a & b)
    NonLeafExpressionNode exp3 = new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("a"), new LeafExpressionNode("b"));
    result = expander.expand(exp3);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.AND, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    // ((a | b) | c) -> (a | b | c)
    NonLeafExpressionNode exp4 = new NonLeafExpressionNode(Operator.OR, new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")), new LeafExpressionNode("c"));
    result = expander.expand(exp4);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(3, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) nlResult.getChildExps().get(2)).getIdentifier());
    // ((a & b) & c) -> (a & b & c)
    NonLeafExpressionNode exp5 = new NonLeafExpressionNode(Operator.AND, new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("a"), new LeafExpressionNode("b")), new LeafExpressionNode("c"));
    result = expander.expand(exp5);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.AND, nlResult.getOperator());
    assertEquals(3, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) nlResult.getChildExps().get(2)).getIdentifier());
    // (a | b) & c -> ((a & c) | (b & c))
    NonLeafExpressionNode exp6 = new NonLeafExpressionNode(Operator.AND, new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")), new LeafExpressionNode("c"));
    result = expander.expand(exp6);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    NonLeafExpressionNode temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // (a & b) | c -> ((a & b) | c)
    NonLeafExpressionNode exp7 = new NonLeafExpressionNode(Operator.OR, new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("a"), new LeafExpressionNode("b")), new LeafExpressionNode("c"));
    result = expander.expand(exp7);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    nlResult = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    // ((a & b) | c) & d -> (((a & b) & d) | (c & d))
    NonLeafExpressionNode exp8 = new NonLeafExpressionNode(Operator.AND);
    exp8.addChildExp(new NonLeafExpressionNode(Operator.OR, new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("a"), new LeafExpressionNode("b")), new LeafExpressionNode("c")));
    exp8.addChildExp(new LeafExpressionNode("d"));
    result = expander.expand(exp8);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // (a | b) | (c | d) -> (a | b | c | d)
    NonLeafExpressionNode exp9 = new NonLeafExpressionNode(Operator.OR);
    exp9.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")));
    exp9.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("c"), new LeafExpressionNode("d")));
    result = expander.expand(exp9);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(4, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) nlResult.getChildExps().get(2)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) nlResult.getChildExps().get(3)).getIdentifier());
    // (a & b) & (c & d) -> (a & b & c & d)
    NonLeafExpressionNode exp10 = new NonLeafExpressionNode(Operator.AND);
    exp10.addChildExp(new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("a"), new LeafExpressionNode("b")));
    exp10.addChildExp(new NonLeafExpressionNode(Operator.AND, new LeafExpressionNode("c"), new LeafExpressionNode("d")));
    result = expander.expand(exp10);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.AND, nlResult.getOperator());
    assertEquals(4, nlResult.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlResult.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlResult.getChildExps().get(1)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) nlResult.getChildExps().get(2)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) nlResult.getChildExps().get(3)).getIdentifier());
    // (a | b) & (c | d) -> ((a & c) | (a & d) | (b & c) | (b & d))
    NonLeafExpressionNode exp11 = new NonLeafExpressionNode(Operator.AND);
    exp11.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")));
    exp11.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("c"), new LeafExpressionNode("d")));
    result = expander.expand(exp11);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(4, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(2);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(3);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // (((a | b) | c) | d) & e -> ((a & e) | (b & e) | (c & e) | (d & e))
    NonLeafExpressionNode exp12 = new NonLeafExpressionNode(Operator.AND);
    NonLeafExpressionNode tempExp1 = new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b"));
    NonLeafExpressionNode tempExp2 = new NonLeafExpressionNode(Operator.OR, tempExp1, new LeafExpressionNode("c"));
    NonLeafExpressionNode tempExp3 = new NonLeafExpressionNode(Operator.OR, tempExp2, new LeafExpressionNode("d"));
    exp12.addChildExp(tempExp3);
    exp12.addChildExp(new LeafExpressionNode("e"));
    result = expander.expand(exp12);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(4, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(2);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(3);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // (a | b | c) & d -> ((a & d) | (b & d) | (c & d))
    NonLeafExpressionNode exp13 = new NonLeafExpressionNode(Operator.AND, new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b"), new LeafExpressionNode("c")), new LeafExpressionNode("d"));
    result = expander.expand(exp13);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(3, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(2);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // ((a | b) & (c | d)) & (e | f) -> (((a & c) & e) | ((a & c) & f) | ((a & d) & e) | ((a & d) &
    // f) | ((b & c) & e) | ((b & c) & f) | ((b & d) & e) | ((b & d) & f))
    NonLeafExpressionNode exp15 = new NonLeafExpressionNode(Operator.AND);
    NonLeafExpressionNode temp1 = new NonLeafExpressionNode(Operator.AND);
    temp1.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")));
    temp1.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("c"), new LeafExpressionNode("d")));
    exp15.addChildExp(temp1);
    exp15.addChildExp(new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("e"), new LeafExpressionNode("f")));
    result = expander.expand(exp15);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.OR, nlResult.getOperator());
    assertEquals(8, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("f", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(2);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(3);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("f", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(4);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(5);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("f", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("c", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(6);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("e", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(7);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("f", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    temp = (NonLeafExpressionNode) temp.getChildExps().get(0);
    assertEquals(Operator.AND, temp.getOperator());
    assertEquals(2, temp.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) temp.getChildExps().get(1)).getIdentifier());
    // !(a | b) -> ((!a) & (!b))
    NonLeafExpressionNode exp16 = new NonLeafExpressionNode(Operator.NOT, new NonLeafExpressionNode(Operator.OR, new LeafExpressionNode("a"), new LeafExpressionNode("b")));
    result = expander.expand(exp16);
    assertTrue(result instanceof NonLeafExpressionNode);
    nlResult = (NonLeafExpressionNode) result;
    assertEquals(Operator.AND, nlResult.getOperator());
    assertEquals(2, nlResult.getChildExps().size());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(0);
    assertEquals(Operator.NOT, temp.getOperator());
    assertEquals("a", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
    temp = (NonLeafExpressionNode) nlResult.getChildExps().get(1);
    assertEquals(Operator.NOT, temp.getOperator());
    assertEquals("b", ((LeafExpressionNode) temp.getChildExps().get(0)).getIdentifier());
}
Also used : NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) ExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) Test(org.junit.Test)

Example 7 with NonLeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode in project hbase by apache.

the class TestExpressionParser method testPositiveCases.

@Test
public void testPositiveCases() throws Exception {
    // abc -> (abc)
    ExpressionNode node = parser.parse("abc");
    assertTrue(node instanceof LeafExpressionNode);
    assertEquals("abc", ((LeafExpressionNode) node).getIdentifier());
    // a&b|c&d -> (((a & b) | c) & )
    node = parser.parse("a&b|c&d");
    assertTrue(node instanceof NonLeafExpressionNode);
    NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("d", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // (a) -> (a)
    node = parser.parse("(a)");
    assertTrue(node instanceof LeafExpressionNode);
    assertEquals("a", ((LeafExpressionNode) node).getIdentifier());
    // (a&b) -> (a & b)
    node = parser.parse(" ( a & b )");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // ((((a&b)))) -> (a & b)
    node = parser.parse("((((a&b))))");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // (a|b)&(cc|def) -> ((a | b) & (cc | def))
    node = parser.parse("( a | b ) & (cc|def)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    NonLeafExpressionNode nlNodeLeft = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    NonLeafExpressionNode nlNodeRight = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.OR, nlNodeLeft.getOperator());
    assertEquals(2, nlNodeLeft.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(1)).getIdentifier());
    assertEquals(Operator.OR, nlNodeRight.getOperator());
    assertEquals(2, nlNodeRight.getChildExps().size());
    assertEquals("cc", ((LeafExpressionNode) nlNodeRight.getChildExps().get(0)).getIdentifier());
    assertEquals("def", ((LeafExpressionNode) nlNodeRight.getChildExps().get(1)).getIdentifier());
    // a&(cc|de) -> (a & (cc | de))
    node = parser.parse("a&(cc|de)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("cc", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("de", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // (a&b)|c -> ((a & b) | c)
    node = parser.parse("(a&b)|c");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // (a&b&c)|d -> (((a & b) & c) | d)
    node = parser.parse("(a&b&c)|d");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("d", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // a&(b|(c|d)) -> (a & (b | (c | d)))
    node = parser.parse("a&(b|(c|d))");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("d", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // (!a) -> (!a)
    node = parser.parse("(!a)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // a&(!b) -> (a & (!b))
    node = parser.parse("a&(!b)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals(1, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // !a&b -> ((!a) & b)
    node = parser.parse("!a&b");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals(1, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // !a&(!b) -> ((!a) & (!b))
    node = parser.parse("!a&(!b)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNodeLeft = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    nlNodeRight = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.NOT, nlNodeLeft.getOperator());
    assertEquals(1, nlNodeLeft.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(0)).getIdentifier());
    assertEquals(Operator.NOT, nlNodeRight.getOperator());
    assertEquals(1, nlNodeRight.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNodeRight.getChildExps().get(0)).getIdentifier());
    // !a&!b -> ((!a) & (!b))
    node = parser.parse("!a&!b");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNodeLeft = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    nlNodeRight = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.NOT, nlNodeLeft.getOperator());
    assertEquals(1, nlNodeLeft.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(0)).getIdentifier());
    assertEquals(Operator.NOT, nlNodeRight.getOperator());
    assertEquals(1, nlNodeRight.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNodeRight.getChildExps().get(0)).getIdentifier());
    // !(a&b) -> (!(a & b))
    node = parser.parse("!(a&b)");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals(1, nlNode.getChildExps().size());
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    // a&!b -> (a & (!b))
    node = parser.parse("a&!b");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("a", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals(1, nlNode.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    // !((a|b)&!(c&!b)) -> (!((a | b) & (!(c & (!b)))))
    node = parser.parse("!((a | b) & !(c & !b))");
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.NOT, nlNode.getOperator());
    assertEquals(1, nlNode.getChildExps().size());
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    assertTrue(nlNode.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNodeLeft = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    nlNodeRight = (NonLeafExpressionNode) nlNode.getChildExps().get(1);
    assertEquals(Operator.OR, nlNodeLeft.getOperator());
    assertEquals("a", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(0)).getIdentifier());
    assertEquals("b", ((LeafExpressionNode) nlNodeLeft.getChildExps().get(1)).getIdentifier());
    assertEquals(Operator.NOT, nlNodeRight.getOperator());
    assertEquals(1, nlNodeRight.getChildExps().size());
    nlNodeRight = (NonLeafExpressionNode) nlNodeRight.getChildExps().get(0);
    assertEquals(Operator.AND, nlNodeRight.getOperator());
    assertEquals(2, nlNodeRight.getChildExps().size());
    assertEquals("c", ((LeafExpressionNode) nlNodeRight.getChildExps().get(0)).getIdentifier());
    assertTrue(nlNodeRight.getChildExps().get(1) instanceof NonLeafExpressionNode);
    nlNodeRight = (NonLeafExpressionNode) nlNodeRight.getChildExps().get(1);
    assertEquals(Operator.NOT, nlNodeRight.getOperator());
    assertEquals(1, nlNodeRight.getChildExps().size());
    assertEquals("b", ((LeafExpressionNode) nlNodeRight.getChildExps().get(0)).getIdentifier());
}
Also used : NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) ExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) Test(org.junit.Test)

Example 8 with NonLeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode in project hbase by apache.

the class TestExpressionParser method testNonAsciiCases.

@Test
public void testNonAsciiCases() throws Exception {
    ExpressionNode node = parser.parse(CellVisibility.quote("'") + "&" + CellVisibility.quote("+") + "|" + CellVisibility.quote("-") + "&" + CellVisibility.quote("?"));
    assertTrue(node instanceof NonLeafExpressionNode);
    NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("?", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("-", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("+", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertEquals("'", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
    node = parser.parse(CellVisibility.quote("'") + "&" + CellVisibility.quote("+") + "|" + CellVisibility.quote("-") + "&" + CellVisibility.quote("?"));
    assertTrue(node instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) node;
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("?", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.OR, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("-", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertTrue(nlNode.getChildExps().get(0) instanceof NonLeafExpressionNode);
    nlNode = (NonLeafExpressionNode) nlNode.getChildExps().get(0);
    assertEquals(Operator.AND, nlNode.getOperator());
    assertEquals(2, nlNode.getChildExps().size());
    assertEquals("+", ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier());
    assertEquals("'", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier());
}
Also used : NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) ExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) Test(org.junit.Test)

Example 9 with NonLeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode in project hbase by apache.

the class ExpAsStringVisibilityLabelServiceImpl method extractLabels.

private void extractLabels(ExpressionNode node, List<String> labels, List<String> notLabels) {
    if (node.isSingleNode()) {
        if (node instanceof NonLeafExpressionNode) {
            // This is a NOT node.
            LeafExpressionNode lNode = (LeafExpressionNode) ((NonLeafExpressionNode) node).getChildExps().get(0);
            notLabels.add(lNode.getIdentifier());
        } else {
            labels.add(((LeafExpressionNode) node).getIdentifier());
        }
    } else {
        // A non leaf expression of labels with & operator.
        NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node;
        assert nlNode.getOperator() == Operator.AND;
        List<ExpressionNode> childExps = nlNode.getChildExps();
        for (ExpressionNode child : childExps) {
            extractLabels(child, labels, notLabels);
        }
    }
}
Also used : ExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode)

Example 10 with NonLeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode in project hbase by apache.

the class ExpAsStringVisibilityLabelServiceImpl method createVisibilityExpTags.

@Override
public List<Tag> createVisibilityExpTags(String visExpression, boolean withSerializationFormat, boolean checkAuths) throws IOException {
    ExpressionNode node = null;
    try {
        node = this.expressionParser.parse(visExpression);
    } catch (ParseException e) {
        throw new IOException(e);
    }
    node = this.expressionExpander.expand(node);
    List<Tag> tags = new ArrayList<>();
    if (withSerializationFormat) {
        tags.add(STRING_SERIALIZATION_FORMAT_TAG);
    }
    if (node instanceof NonLeafExpressionNode && ((NonLeafExpressionNode) node).getOperator() == Operator.OR) {
        for (ExpressionNode child : ((NonLeafExpressionNode) node).getChildExps()) {
            tags.add(createTag(child));
        }
    } else {
        tags.add(createTag(node));
    }
    return tags;
}
Also used : ExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode) LeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArrayBackedTag(org.apache.hadoop.hbase.ArrayBackedTag) Tag(org.apache.hadoop.hbase.Tag) NonLeafExpressionNode(org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode)

Aggregations

ExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode)15 LeafExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode)15 NonLeafExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode)15 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 ArrayBackedTag (org.apache.hadoop.hbase.ArrayBackedTag)2 Tag (org.apache.hadoop.hbase.Tag)2 Operator (org.apache.hadoop.hbase.security.visibility.expression.Operator)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 Stack (java.util.Stack)1