/** * Helps in quoting authentication Strings. Use this if unicode characters to * be used in expression or special characters like '(', ')', * '"','\','&','|','!' */ public static String quote(String auth) { return quote(Bytes.toBytes(auth)); }
.append(VisibilityConstants.NOT_OPERATOR).append(CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR) .append(VisibilityConstants.NOT_OPERATOR).append(CellVisibility.quote(label)); if (expressionStart) { visibilityString.append(VisibilityConstants.OPEN_PARAN).append( CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR).append( CellVisibility.quote(label));
if (expressionStart) { visibilityString.append(VisibilityConstants.OPEN_PARAN + VisibilityConstants.NOT_OPERATOR + CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR + VisibilityConstants.NOT_OPERATOR + CellVisibility.quote(label)); visibilityString.append(VisibilityConstants.OPEN_PARAN + CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR + CellVisibility.quote(label));
} catch (ParseException e) { node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\"") + "|" + CellVisibility.quote("\u002b" + "&" + "\u003f")); assertTrue(node instanceof NonLeafExpressionNode); NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assertEquals("\u0027", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier()); try { node = parser.parse(CellVisibility.quote("\u0027&\\") + "|" + CellVisibility.quote("\u002b" + "&" + "\\") + CellVisibility.quote("$$\"")); fail("Excpetion must be thrown as there is not operator"); } catch (ParseException e) { node = parser.parse(CellVisibility.quote("\u0027" + "&" + "\\") + "|" + CellVisibility.quote("\u003f" + "&" + "\\") + "&" + CellVisibility.quote("$$\"")); assertTrue(node instanceof NonLeafExpressionNode); nlNode = (NonLeafExpressionNode) node; ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier()); try { node = parser.parse(CellVisibility.quote("\u002b&\\") + "|" + CellVisibility.quote("\u0027&\\") + "&" + "\"$$"); fail("Excpetion must be thrown as there is no end quote");
@Test public void testNonAsciiCases() throws Exception { ExpressionNode node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\u002b") + "|" + CellVisibility.quote("\u002d") + "&" + CellVisibility.quote("\u003f")); assertTrue(node instanceof NonLeafExpressionNode); NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assertEquals("\u0027", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier()); node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\u002b") + "|" + CellVisibility.quote("\u002d") + "&" + CellVisibility.quote("\u003f")); assertTrue(node instanceof NonLeafExpressionNode); nlNode = (NonLeafExpressionNode) node;
/** * Helps in quoting authentication Strings. Use this if unicode characters to * be used in expression or special characters like '(', ')', * '"','\','&','|','!' */ public static String quote(String auth) { return quote(Bytes.toBytes(auth)); }
@Test public void testAuthorizationsWithSpecialUnicodeCharacters() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, CellVisibility.quote(UC1) + "|" + CellVisibility.quote(UC2), CellVisibility.quote(UC1), CellVisibility.quote(UNICODE_VIS_TAG))) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(UC1, UC2, ACCENT, UNICODE_VIS_TAG)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 3); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); cellScanner = next[2].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row3, 0, row3.length)); } }
@Test public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT) + "&" + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL, CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT, UNICODE_VIS_TAG)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 3); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); cellScanner = next[2].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row3, 0, row3.length)); } }
+ ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|" + TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET, CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, TOPSECRET,
/** * Helps in quoting authentication Strings. Use this if unicode characters to * be used in expression or special characters like '(', ')', * '"','\','&','|','!' */ public static String quote(String auth) { return quote(Bytes.toBytes(auth)); }
/** * Helps in quoting authentication Strings. Use this if unicode characters to * be used in expression or special characters like '(', ')', * '"','\','&','|','!' */ public static String quote(String auth) { return quote(Bytes.toBytes(auth)); }
.append(VisibilityConstants.NOT_OPERATOR).append(CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR) .append(VisibilityConstants.NOT_OPERATOR).append(CellVisibility.quote(label)); if (expressionStart) { visibilityString.append(VisibilityConstants.OPEN_PARAN).append( CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR).append( CellVisibility.quote(label));
if (expressionStart) { visibilityString.append(VisibilityConstants.OPEN_PARAN + VisibilityConstants.NOT_OPERATOR + CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR + VisibilityConstants.NOT_OPERATOR + CellVisibility.quote(label)); visibilityString.append(VisibilityConstants.OPEN_PARAN + CellVisibility.quote(label)); } else { visibilityString.append(VisibilityConstants.AND_OPERATOR + CellVisibility.quote(label));
} catch (ParseException e) { node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\"") + "|" + CellVisibility.quote("\u002b" + "&" + "\u003f")); assertTrue(node instanceof NonLeafExpressionNode); NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assertEquals("\u0027", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier()); try { node = parser.parse(CellVisibility.quote("\u0027&\\") + "|" + CellVisibility.quote("\u002b" + "&" + "\\") + CellVisibility.quote("$$\"")); fail("Excpetion must be thrown as there is not operator"); } catch (ParseException e) { node = parser.parse(CellVisibility.quote("\u0027" + "&" + "\\") + "|" + CellVisibility.quote("\u003f" + "&" + "\\") + "&" + CellVisibility.quote("$$\"")); assertTrue(node instanceof NonLeafExpressionNode); nlNode = (NonLeafExpressionNode) node; ((LeafExpressionNode) nlNode.getChildExps().get(1)).getIdentifier()); try { node = parser.parse(CellVisibility.quote("\u002b&\\") + "|" + CellVisibility.quote("\u0027&\\") + "&" + "\"$$"); fail("Excpetion must be thrown as there is no end quote");
@Test public void testNonAsciiCases() throws Exception { ExpressionNode node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\u002b") + "|" + CellVisibility.quote("\u002d") + "&" + CellVisibility.quote("\u003f")); assertTrue(node instanceof NonLeafExpressionNode); NonLeafExpressionNode nlNode = (NonLeafExpressionNode) node; assertEquals("\u0027", ((LeafExpressionNode) nlNode.getChildExps().get(0)).getIdentifier()); node = parser.parse(CellVisibility.quote("\u0027") + "&" + CellVisibility.quote("\u002b") + "|" + CellVisibility.quote("\u002d") + "&" + CellVisibility.quote("\u003f")); assertTrue(node instanceof NonLeafExpressionNode); nlNode = (NonLeafExpressionNode) node;
@Test public void testAuthorizationsWithSpecialUnicodeCharacters() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, CellVisibility.quote(UC1) + "|" + CellVisibility.quote(UC2), CellVisibility.quote(UC1), CellVisibility.quote(UNICODE_VIS_TAG))) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(UC1, UC2, ACCENT, UNICODE_VIS_TAG)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 3); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); cellScanner = next[2].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row3, 0, row3.length)); } }
@Test public void testSimpleVisibilityLabelsWithUniCodeCharacters() throws Exception { TableName tableName = TableName.valueOf(TEST_NAME.getMethodName()); try (Table table = createTableAndWriteDataWithLabels(tableName, SECRET + "|" + CellVisibility.quote(COPYRIGHT), "(" + CellVisibility.quote(COPYRIGHT) + "&" + CellVisibility.quote(ACCENT) + ")|" + CONFIDENTIAL, CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET)) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, COPYRIGHT, ACCENT, UNICODE_VIS_TAG)); ResultScanner scanner = table.getScanner(s); Result[] next = scanner.next(3); assertTrue(next.length == 3); CellScanner cellScanner = next[0].cellScanner(); cellScanner.advance(); Cell current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row1, 0, row1.length)); cellScanner = next[1].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row2, 0, row2.length)); cellScanner = next[2].cellScanner(); cellScanner.advance(); current = cellScanner.current(); assertTrue(Bytes.equals(current.getRowArray(), current.getRowOffset(), current.getRowLength(), row3, 0, row3.length)); } }
+ ")&(" + TOPSECRET + ")", "(" + PRIVATE + "|" + CONFIDENTIAL + ")&(" + PUBLIC + "|" + TOPSECRET + ")", "(" + SECRET + "|" + CONFIDENTIAL + ")" + "&" + "!" + TOPSECRET, CellVisibility.quote(UNICODE_VIS_TAG) + "&" + SECRET);) { Scan s = new Scan(); s.setAuthorizations(new Authorizations(SECRET, CONFIDENTIAL, PRIVATE, TOPSECRET,