Search in sources :

Example 1 with LeafExpressionNode

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

the class ExpressionExpander method negate.

private ExpressionNode negate(NonLeafExpressionNode nlExp) {
    ExpressionNode notChild = nlExp.getChildExps().get(0);
    if (notChild instanceof LeafExpressionNode) {
        return nlExp;
    }
    NonLeafExpressionNode nlNotChild = (NonLeafExpressionNode) notChild;
    if (nlNotChild.getOperator() == Operator.NOT) {
        // negate the negate
        return nlNotChild.getChildExps().get(0);
    }
    Operator negateOp = nlNotChild.getOperator() == Operator.AND ? Operator.OR : Operator.AND;
    NonLeafExpressionNode newNode = new NonLeafExpressionNode(negateOp);
    for (ExpressionNode expNode : nlNotChild.getChildExps()) {
        NonLeafExpressionNode negateNode = new NonLeafExpressionNode(Operator.NOT);
        negateNode.addChildExp(expNode.deepClone());
        newNode.addChildExp(expand(negateNode));
    }
    return newNode;
}
Also used : Operator(org.apache.hadoop.hbase.security.visibility.expression.Operator) 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)

Example 2 with LeafExpressionNode

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

the class VisibilityUtils method getLabelOrdinals.

private static void getLabelOrdinals(ExpressionNode node, List<Integer> labelOrdinals, Set<Integer> auths, boolean checkAuths, VisibilityLabelOrdinalProvider ordinalProvider) throws IOException, InvalidLabelException {
    if (node.isSingleNode()) {
        String identifier = null;
        int labelOrdinal = 0;
        if (node instanceof LeafExpressionNode) {
            identifier = ((LeafExpressionNode) node).getIdentifier();
            if (LOG.isTraceEnabled()) {
                LOG.trace("The identifier is " + identifier);
            }
            labelOrdinal = ordinalProvider.getLabelOrdinal(identifier);
            checkAuths(auths, labelOrdinal, identifier, checkAuths);
        } else {
            // This is a NOT node.
            LeafExpressionNode lNode = (LeafExpressionNode) ((NonLeafExpressionNode) node).getChildExps().get(0);
            identifier = lNode.getIdentifier();
            labelOrdinal = ordinalProvider.getLabelOrdinal(identifier);
            checkAuths(auths, labelOrdinal, identifier, checkAuths);
            // Store NOT node as -ve ordinal.
            labelOrdinal = -1 * labelOrdinal;
        }
        if (labelOrdinal == 0) {
            throw new InvalidLabelException("Invalid visibility label " + identifier);
        }
        labelOrdinals.add(labelOrdinal);
    } else {
        List<ExpressionNode> childExps = ((NonLeafExpressionNode) node).getChildExps();
        for (ExpressionNode child : childExps) {
            getLabelOrdinals(child, labelOrdinals, auths, checkAuths, ordinalProvider);
        }
    }
}
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 3 with LeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode 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 4 with LeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode 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 5 with LeafExpressionNode

use of org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode 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)

Aggregations

ExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.ExpressionNode)8 LeafExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.LeafExpressionNode)8 NonLeafExpressionNode (org.apache.hadoop.hbase.security.visibility.expression.NonLeafExpressionNode)8 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)1 Stack (java.util.Stack)1 Operator (org.apache.hadoop.hbase.security.visibility.expression.Operator)1