@Nonnull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @Nonnull Tree tree) { return base.getPattern(oakPath, tree); }
@Nonnull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @Nonnull Set<Restriction> restrictions) { return base.getPattern(oakPath, restrictions); } }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) { return base.getPattern(oakPath, tree); }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) { return base.getPattern(oakPath, tree); }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { return base.getPattern(oakPath, restrictions); } }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { return base.getPattern(oakPath, restrictions); } }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Tree tree) { return getProvider().getPattern(oakPath, tree); }
@Nonnull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @Nonnull Set<Restriction> restrictions) { return getProvider().getPattern(oakPath, restrictions); }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { return getProvider().getPattern(oakPath, restrictions); }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { List<RestrictionPattern> patterns = new ArrayList<>(); for (RestrictionProvider rp : providers) { RestrictionPattern pattern = rp.getPattern(oakPath, restrictions); if (pattern != RestrictionPattern.EMPTY) { patterns.add(pattern); } } return CompositePattern.create(patterns); }
@Nonnull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @Nonnull Tree tree) { return getProvider().getPattern(oakPath, tree); }
@NotNull @Override public RestrictionPattern getPattern(@Nullable String oakPath, @NotNull Set<Restriction> restrictions) { return getProvider().getPattern(oakPath, restrictions); }
@NotNull private PermissionEntry createPermissionEntry(@NotNull String path, @NotNull Tree entryTree) { PropertyState ps = entryTree.getProperty(REP_PRIVILEGE_BITS); PrivilegeBits bits = (isJcrAll(ps)) ? allBits : PrivilegeBits.getInstance(ps); boolean isAllow = TreeUtil.getBoolean(entryTree, REP_IS_ALLOW); return new PermissionEntry(path, isAllow, Integer.parseInt(entryTree.getName()), bits, restrictionProvider.getPattern(path, entryTree)); }
@NotNull private PermissionEntry createPermissionEntry(@NotNull String path, @NotNull Tree entryTree) { PropertyState ps = entryTree.getProperty(REP_PRIVILEGE_BITS); PrivilegeBits bits = (isJcrAll(ps)) ? allBits : PrivilegeBits.getInstance(ps); boolean isAllow = TreeUtil.getBoolean(entryTree, REP_IS_ALLOW); return new PermissionEntry(path, isAllow, Integer.parseInt(entryTree.getName()), bits, restrictionProvider.getPattern(path, entryTree)); }
@Test public void testGetPattern() { Restriction r = Mockito.mock(Restriction.class); assertSame(RestrictionPattern.EMPTY, RestrictionProvider.EMPTY.getPattern(null, ImmutableSet.of(r))); assertSame(RestrictionPattern.EMPTY, RestrictionProvider.EMPTY.getPattern("/any/path", ImmutableSet.of(r))); }
@Before public void before() { registered = Mockito.mock(RestrictionProvider.class); when(registered.getPattern(PathUtils.ROOT_PATH, tree)).thenThrow(new RestrictionException()); }
@Test public void testGetPatternFromTree() { assertSame(RestrictionPattern.EMPTY, RestrictionProvider.EMPTY.getPattern(null, Mockito.mock(Tree.class))); assertSame(RestrictionPattern.EMPTY, RestrictionProvider.EMPTY.getPattern("/any/path", Mockito.mock(Tree.class))); } }
@Test(expected = RestrictionException.class) public void testRegisteredGetPattern() { restrictionProvider.start(whiteboard); whiteboard.register(RestrictionProvider.class, registered, ImmutableMap.of()); registered.getPattern(PathUtils.ROOT_PATH, tree); } }
private RestrictionPattern buildGlobPattern(@NotNull String path, @NotNull String glob) throws Exception { RestrictionProvider rp = getConfig(AuthorizationConfiguration.class).getRestrictionProvider(); Restriction restriction = rp.createRestriction(path, AccessControlConstants.REP_GLOB, getValueFactory(root).createValue(glob)); return rp.getPattern(path, ImmutableSet.of(restriction)); }
@Test public void testGetRestrictionPattern() throws Exception { NodeUtil aceNode = new NodeUtil(root.getTree("/")).addChild("test", NT_REP_GRANT_ACE); NodeUtil rNode = aceNode.addChild(REP_RESTRICTIONS, NT_REP_RESTRICTIONS); rNode.setString(REP_GLOB, "*"); assertFalse(provider.getPattern("/test", aceNode.getTree()) instanceof CompositePattern); rNode.setBoolean("boolean", true); rNode.setValues("longs", new Value[]{vf.createValue(10), vf.createValue(290)}); assertTrue(provider.getPattern("/test", rNode.getTree()) instanceof CompositePattern); } }