MemoryStoreUtils { protected static boolean isAuthorized(final byte[] visibility, final String[] authorizations) { if ((visibility == null) || (visibility.length == 0)) { return true; } VisibilityExpression expr; try { expr = new VisibilityExpressionParser().parse(visibility); } catch (final IOException e) { LOGGER.error("invalid visibility", e); return false; } return expr.ok(authorizations); }    }
@Test public void testVisibility() { assertTrue( MemoryStoreUtils.isAuthorized("aaa&ccc".getBytes(), new String[] {"aaa", "bbb", "ccc"})); assertFalse(MemoryStoreUtils.isAuthorized("aaa&ccc".getBytes(), new String[] {"aaa", "bbb"})); assertTrue( MemoryStoreUtils.isAuthorized( "aaa&(ccc|eee)".getBytes(), new String[] {"aaa", "eee", "xxx"})); assertTrue( MemoryStoreUtils.isAuthorized( "aaa|(ccc&eee)".getBytes(), new String[] {"bbb", "eee", "ccc"})); assertFalse( MemoryStoreUtils.isAuthorized( "aaa|(ccc&eee)".getBytes(), new String[] {"bbb", "dddd", "ccc"})); assertTrue( MemoryStoreUtils.isAuthorized( "aaa|(ccc&eee)".getBytes(), new String[] {"aaa", "dddd", "ccc"})); assertTrue( MemoryStoreUtils.isAuthorized("aaa".getBytes(), new String[] {"aaa", "dddd", "ccc"})); assertFalse( MemoryStoreUtils.isAuthorized("xxx".getBytes(), new String[] {"aaa", "dddd", "ccc"})); }