@Test(expected = RuntimeException.class) public void testPrivilegeRegistrationFails() { try { NodeState ns = mock(NodeState.class); NodeBuilder nb = when(mock(NodeBuilder.class).hasChildNode(JCR_SYSTEM)).thenReturn(true).getMock(); when(nb.getChildNode(anyString())).thenReturn(nb); when(nb.child(anyString())).thenReturn(nb); when(nb.getNodeState()).thenReturn(ns); Tree t = when(mock(Tree.class).exists()).thenReturn(true).getMock(); when(t.hasChild(anyString())).thenReturn(true); Root r = when(mock(Root.class).getTree(anyString())).thenReturn(t).getMock(); RootProvider rp = when(mock(RootProvider.class).createSystemRoot(any(NodeStore.class), isNull())).thenReturn(r).getMock(); PrivilegeInitializer pi = new PrivilegeInitializer(rp); pi.initialize(nb); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof RepositoryException); throw e; } }
@Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); @Override void initialize(@NotNull NodeBuilder builder); }
PrivilegeInitializer implements RepositoryInitializer, PrivilegeConstants { @Override public void initialize(@NotNull NodeBuilder builder) { if (!builder.hasChildNode(JcrConstants.JCR_SYSTEM)) { throw new IllegalStateException("Missing " + JcrConstants.JCR_SYSTEM + " node, NodeStore not initialized."); } NodeBuilder system = builder.getChildNode(JcrConstants.JCR_SYSTEM); if (!system.hasChildNode(REP_PRIVILEGES)) { NodeBuilder privileges = system.child(REP_PRIVILEGES); privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME); NodeState base = squeeze(builder.getNodeState()); NodeStore store = new MemoryNodeStore(base); try { Root systemRoot = rootProvider.createSystemRoot(store, null); new PrivilegeDefinitionWriter(systemRoot).writeBuiltInDefinitions(); } catch (RepositoryException e) { log.error("Failed to register built-in privileges", e); throw new RuntimeException(e); } NodeState target = store.getRoot(); target.compareAgainstBaseState(base, new ApplyDiff(builder)); } } PrivilegeInitializer(@NotNull RootProvider rootProvider); @Override void initialize(@NotNull NodeBuilder builder);  }